Skip to content

Commit b3fe000

Browse files
Merge pull request #802 from nodejs/bats
Use BATS for image testing
2 parents b22fb6c + df219f1 commit b3fe000

File tree

4 files changed

+79
-29
lines changed

4 files changed

+79
-29
lines changed

functions.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,24 @@ function get_fork_name() {
180180
fi
181181
}
182182

183+
function get_full_tag() {
184+
local variant
185+
local tag
186+
local full_tag
187+
variant="$1"
188+
shift
189+
tag="$1"
190+
shift
191+
if [ -z "${variant}" ]; then
192+
full_tag="${tag}"
193+
elif [ "${variant}" = "default" ]; then
194+
full_tag="${tag}"
195+
else
196+
full_tag="${tag}-${variant}"
197+
fi
198+
echo "${full_tag}"
199+
}
200+
183201
function get_full_version() {
184202
local version
185203
version=$1
@@ -206,6 +224,25 @@ function get_major_minor_version() {
206224
echo "$(echo "${fullversion}" | cut -d'.' -f1).$(echo "${fullversion}" | cut -d'.' -f2)"
207225
}
208226

227+
function get_path() {
228+
local version
229+
local variant
230+
local path
231+
version="$1"
232+
shift
233+
variant="$1"
234+
shift
235+
236+
if [ -z "${variant}" ]; then
237+
path="${version}/${variant}"
238+
elif [ "${variant}" = "default" ]; then
239+
path="${version}"
240+
else
241+
path="${version}/${variant}"
242+
fi
243+
echo "${path}"
244+
}
245+
209246
function get_tag() {
210247
local version
211248
version=$1

test-build.sh

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,37 @@ function build() {
2727
tag="$1"
2828
shift
2929

30-
if [ -z "${variant}" ]; then
31-
full_tag="${tag}"
32-
path="${version}/${variant}"
33-
elif [ "${variant}" = "default" ]; then
34-
full_tag="${tag}"
35-
path="${version}"
36-
else
37-
full_tag="${tag}-${variant}"
38-
path="${version}/${variant}"
39-
fi
30+
full_tag=$(get_full_tag "${variant}" "${tag}")
31+
path=$(get_path "${version}" "${variant}")
4032

4133
info "Building ${full_tag}..."
4234

4335
if ! docker build --cpuset-cpus="0,1" -t node:"${full_tag}" "${path}"; then
4436
fatal "Build of ${full_tag} failed!"
4537
fi
4638
info "Build of ${full_tag} succeeded."
39+
}
40+
41+
function test_image() {
42+
local full_version
43+
local variant
44+
local tag
45+
local full_tag
46+
full_version="$1"
47+
shift
48+
variant="$1"
49+
shift
50+
tag="$1"
51+
shift
52+
53+
full_tag=$(get_full_tag "${variant}" "${tag}")
4754

4855
info "Testing ${full_tag}"
49-
docker run --rm -v "$PWD/test-image.sh:/usr/local/bin/test.sh" node:"${full_tag}" test.sh "${full_version}"
56+
(
57+
export full_version=${full_version}
58+
export full_tag=${full_tag}
59+
bats test-image.bats
60+
)
5061
}
5162

5263
cd "$(cd "${0%/*}" && pwd -P)" || exit
@@ -66,6 +77,7 @@ for version in "${versions[@]}"; do
6677
# Required for chakracore
6778
if [ -f "${version}/Dockerfile" ]; then
6879
build "${version}" "default" "${tag}"
80+
test_image "${full_version}" "default" "${tag}"
6981
fi
7082

7183
# Get supported variants according to the target architecture.
@@ -78,9 +90,11 @@ for version in "${versions[@]}"; do
7890

7991
if [ "${variant}" = "onbuild" ]; then
8092
build "${version}" "${default_variant}" "$tag"
93+
test_image "${full_version}" "${default_variant}" "$tag"
8194
fi
8295

8396
build "${version}" "${variant}" "${tag}"
97+
test_image "${full_version}" "${variant}" "${tag}"
8498
done
8599

86100
done

test-image.bats

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bats
2+
3+
@test "Test for node and version" {
4+
run docker run --rm -it node:"$full_tag" node -e "process.stdout.write(process.versions.node)"
5+
[ "$status" -eq 0 ]
6+
[ "$output" == "${full_version}" ]
7+
}
8+
9+
@test "Test for npm" {
10+
run docker run --rm -it node:"$full_tag" npm --version
11+
[ "$status" -eq 0 ]
12+
}
13+
14+
@test "Test for yarn" {
15+
run docker run --rm -it node:"$full_tag" yarn --version
16+
[ "$status" -eq 0 ]
17+
}

test-image.sh

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)