diff --git a/functions.sh b/functions.sh index 24d17aa368..437110b3e3 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 61861e9e0d..26621a1e12 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}..." @@ -44,9 +36,28 @@ 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 + full_version="$1" + shift + variant="$1" + shift + tag="$1" + shift + + full_tag=$(get_full_tag "${variant}" "${tag}") 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_version=${full_version} + export full_tag=${full_tag} + bats test-image.bats + ) } cd "$(cd "${0%/*}" && pwd -P)" || exit @@ -66,6 +77,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. @@ -78,9 +90,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 diff --git a/test-image.bats b/test-image.bats new file mode 100755 index 0000000000..0ed164867c --- /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 e409e3bc3e..0000000000 --- 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."