Skip to content

Commit 1e37138

Browse files
committed
Initial work adding back BATS
1 parent be42a31 commit 1e37138

File tree

4 files changed

+46
-19
lines changed

4 files changed

+46
-19
lines changed

.github/workflows/build-test.yml

+8-19
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ jobs:
5555
strategy:
5656
fail-fast: false
5757
matrix: ${{ fromJson(needs.gen-matrix.outputs.matrix) }}
58+
env:
59+
NODE_VERSION: ${{ matrix.version }}
60+
IMAGE_TAG: node:${{ matrix.version }}-${{ matrix.variant }}
5861

5962
steps:
6063
- name: Get short node version
@@ -66,6 +69,8 @@ jobs:
6669

6770
- name: Checkout
6871
uses: actions/checkout@v2
72+
with:
73+
submodules: true
6974

7075
- name: Build image
7176
uses: docker/build-push-action@v2
@@ -74,23 +79,7 @@ jobs:
7479
load: true
7580
context: .
7681
file: ./${{ steps.short-version.outputs.result }}/${{ matrix.variant }}/Dockerfile
77-
tags: node:${{ matrix.version }}-${{ matrix.variant }}
78-
79-
- name: Test for node version
80-
run: |
81-
image_node_version=$(docker run --rm node:${{ matrix.version }}-${{ matrix.variant }} node --print "process.versions.node")
82-
echo "Expected: \"${{ matrix.version }}\", Got: \"${image_node_version}\""
83-
[ "${image_node_version}" == "${{ matrix.version }}" ]
84-
85-
- name: Verify entrypoint runs regular, non-executable files with node
86-
run: |
87-
tmp_file=$(mktemp)
88-
echo 'console.log("success")' > "${tmp_file}"
89-
output=$(docker run --rm -v "${tmp_file}:/app/index.js" node:${{ matrix.version }}-${{ matrix.variant }} app/index.js)
90-
[ "${output}" = 'success' ]
91-
92-
- name: Test for npm
93-
run: docker run --rm node:${{ matrix.version }}-${{ matrix.variant }} npm --version
82+
tags: ${{ env.IMAGE_TAG }}
9483

95-
- name: Test for yarn
96-
run: docker run --rm node:${{ matrix.version }}-${{ matrix.variant }} yarn --version
84+
- name: Run tests with BATS
85+
run: test/bats/bin/bats --verbose-run test/docker-image.bats

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "test/bats"]
2+
path = test/bats
3+
url = https://github.com/bats-core/bats-core.git

test/bats

Submodule bats added at 01636e4

test/docker-image.bats

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
setup() {
2+
tmp_file=$(mktemp)
3+
echo 'console.log("success")' > "${tmp_file}"
4+
}
5+
6+
@test "Test for node version" {
7+
run docker run --rm "${IMAGE_TAG}" node --print "process.versions.node"
8+
[ "$output" = "${NODE_VERSION}" ]
9+
}
10+
11+
@test "Test for node version, without directly invoking node" {
12+
run docker run --rm "${IMAGE_TAG}" --print "process.versions.node"
13+
[ "$output" = "${NODE_VERSION}" ]
14+
}
15+
16+
@test "Test for npm" {
17+
run docker run --rm "${IMAGE_TAG}" npm --version
18+
[ -n "$output" ]
19+
}
20+
21+
@test "Test for yarn" {
22+
run docker run --rm "${IMAGE_TAG}" yarn --version
23+
[ -n "$output" ]
24+
}
25+
26+
@test "Verify entrypoint runs regular, non-executable file with node" {
27+
run docker run --rm -v "${tmp_file}:/index.js" "${IMAGE_TAG}" index.js
28+
[ "$output" = 'success' ]
29+
}
30+
31+
@test "Verify entrypoint runs regular, non-executable file inside subdirectory with node" {
32+
run docker run --rm -v "${tmp_file}:/app/index.js" "${IMAGE_TAG}" app/index.js
33+
[ "$output" = 'success' ]
34+
}

0 commit comments

Comments
 (0)