Skip to content

Use BATS for image testing #802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
36 changes: 25 additions & 11 deletions test-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,37 @@ 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}..."

if ! docker build --cpuset-cpus="0,1" -t node:"${full_tag}" "${path}"; then
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
Expand All @@ -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.
Expand All @@ -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
Expand Down
17 changes: 17 additions & 0 deletions test-image.bats
Original file line number Diff line number Diff line change
@@ -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 ]
}
18 changes: 0 additions & 18 deletions test-image.sh

This file was deleted.