From 3bfd15f786da882ece66256d5f5e26f81fe8205b Mon Sep 17 00:00:00 2001 From: Christopher Horrell Date: Sat, 2 Jun 2018 11:03:45 -0400 Subject: [PATCH 1/4] Use BATS for testing Switches testing to the BATS testing framework: https://github.com/bats-core/bats-core --- test-build.sh | 4 +++- test-image.bats | 17 +++++++++++++++++ test-image.sh | 18 ------------------ 3 files changed, 20 insertions(+), 19 deletions(-) create mode 100755 test-image.bats delete mode 100755 test-image.sh diff --git a/test-build.sh b/test-build.sh index 61861e9e..e4a137a0 100755 --- a/test-build.sh +++ b/test-build.sh @@ -46,7 +46,9 @@ function build() { info "Build of ${full_tag} succeeded." info "Testing ${full_tag}" - docker run --rm -v "$PWD/test-image.sh:/usr/local/bin/test.sh" node:"${full_tag}" test.sh "${full_version}" + export full_tag=${full_tag} + export full_version=${full_version} + bats test-image.bats } cd "$(cd "${0%/*}" && pwd -P)" || exit diff --git a/test-image.bats b/test-image.bats new file mode 100755 index 00000000..0ed16486 --- /dev/null +++ b/test-image.bats @@ -0,0 +1,17 @@ +#!/usr/bin/env bats + +@test "Test for node and version" { + run docker run --rm -it node:"$full_tag" node -e "process.stdout.write(process.versions.node)" + [ "$status" -eq 0 ] + [ "$output" == "${full_version}" ] +} + +@test "Test for npm" { + run docker run --rm -it node:"$full_tag" npm --version + [ "$status" -eq 0 ] +} + +@test "Test for yarn" { + run docker run --rm -it node:"$full_tag" yarn --version + [ "$status" -eq 0 ] +} diff --git a/test-image.sh b/test-image.sh deleted file mode 100755 index e409e3bc..00000000 --- a/test-image.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh -if [ "$(node -e "process.stdout.write(process.versions.node)")" != "${1}" ]; then - echo "Test for node failed!" - exit 1 -fi -echo "Test for node succeeded." - -if ! npm --version >/dev/null; then - echo "Test for npm failed!" - exit 1 -fi -echo "Test for npm succeeded." - -if ! yarn --version >/dev/null; then - echo "Test of yarn failed!" - exit 1 -fi -echo "Test for yarn succeeded." From 04dbeb2ee0f3f86c87af96a92a0ad05e07a445da Mon Sep 17 00:00:00 2001 From: Christopher Horrell Date: Sat, 30 Jun 2018 10:30:13 -0400 Subject: [PATCH 2/4] Add test_image function --- test-build.sh | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/test-build.sh b/test-build.sh index e4a137a0..45af46cc 100755 --- a/test-build.sh +++ b/test-build.sh @@ -44,10 +44,31 @@ function build() { fatal "Build of ${full_tag} failed!" fi info "Build of ${full_tag} succeeded." +} + +function test_image() { + local full_version + local variant + local tag + local full_tag + version="$1" + shift + variant="$1" + shift + tag="$1" + shift + + if [ -z "${variant}" ]; then + full_tag="${tag}" + elif [ "${variant}" = "default" ]; then + full_tag="${tag}" + else + full_tag="${tag}-${variant}" + fi info "Testing ${full_tag}" - export full_tag=${full_tag} export full_version=${full_version} + export full_tag=${full_tag} bats test-image.bats } @@ -68,6 +89,7 @@ for version in "${versions[@]}"; do # Required for chakracore if [ -f "${version}/Dockerfile" ]; then build "${version}" "default" "${tag}" + test_image "${full_version}" "default" "${tag}" fi # Get supported variants according to the target architecture. @@ -80,9 +102,11 @@ for version in "${versions[@]}"; do if [ "${variant}" = "onbuild" ]; then build "${version}" "${default_variant}" "$tag" + test_image "${full_version}" "${default_variant}" "$tag" fi build "${version}" "${variant}" "${tag}" + test_image "${full_version}" "${variant}" "${tag}" done done From 9677d6aa5ad5b7b62453ea088d9756ab829ed063 Mon Sep 17 00:00:00 2001 From: Christopher Horrell Date: Sat, 30 Jun 2018 18:58:30 -0400 Subject: [PATCH 3/4] Add get_full_tag and get_path functions --- functions.sh | 37 +++++++++++++++++++++++++++++++++++++ test-build.sh | 22 ++++------------------ 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/functions.sh b/functions.sh index 24d17aa3..437110b3 100755 --- a/functions.sh +++ b/functions.sh @@ -180,6 +180,24 @@ function get_fork_name() { fi } +function get_full_tag() { + local variant + local tag + local full_tag + variant="$1" + shift + tag="$1" + shift + if [ -z "${variant}" ]; then + full_tag="${tag}" + elif [ "${variant}" = "default" ]; then + full_tag="${tag}" + else + full_tag="${tag}-${variant}" + fi + echo "${full_tag}" +} + function get_full_version() { local version version=$1 @@ -206,6 +224,25 @@ function get_major_minor_version() { echo "$(echo "${fullversion}" | cut -d'.' -f1).$(echo "${fullversion}" | cut -d'.' -f2)" } +function get_path() { + local version + local variant + local path + version="$1" + shift + variant="$1" + shift + + if [ -z "${variant}" ]; then + path="${version}/${variant}" + elif [ "${variant}" = "default" ]; then + path="${version}" + else + path="${version}/${variant}" + fi + echo "${path}" +} + function get_tag() { local version version=$1 diff --git a/test-build.sh b/test-build.sh index 45af46cc..76bb3f73 100755 --- a/test-build.sh +++ b/test-build.sh @@ -27,16 +27,8 @@ function build() { tag="$1" shift - if [ -z "${variant}" ]; then - full_tag="${tag}" - path="${version}/${variant}" - elif [ "${variant}" = "default" ]; then - full_tag="${tag}" - path="${version}" - else - full_tag="${tag}-${variant}" - path="${version}/${variant}" - fi + full_tag=$(get_full_tag "${variant}" "${tag}") + path=$(get_path "${version}" "${variant}") info "Building ${full_tag}..." @@ -51,20 +43,14 @@ function test_image() { local variant local tag local full_tag - version="$1" + full_version="$1" shift variant="$1" shift tag="$1" shift - if [ -z "${variant}" ]; then - full_tag="${tag}" - elif [ "${variant}" = "default" ]; then - full_tag="${tag}" - else - full_tag="${tag}-${variant}" - fi + full_tag=$(get_full_tag "${variant}" "${tag}") info "Testing ${full_tag}" export full_version=${full_version} From df219f13773074d52271210be928093256db06c2 Mon Sep 17 00:00:00 2001 From: Christopher Horrell Date: Tue, 3 Jul 2018 09:48:13 -0400 Subject: [PATCH 4/4] Wrap exports and test execution in a subshell --- test-build.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test-build.sh b/test-build.sh index 76bb3f73..26621a1e 100755 --- a/test-build.sh +++ b/test-build.sh @@ -53,9 +53,11 @@ function test_image() { full_tag=$(get_full_tag "${variant}" "${tag}") info "Testing ${full_tag}" - export full_version=${full_version} - export full_tag=${full_tag} - bats test-image.bats + ( + export full_version=${full_version} + export full_tag=${full_tag} + bats test-image.bats + ) } cd "$(cd "${0%/*}" && pwd -P)" || exit