Skip to content

Commit 89610de

Browse files
committed
Add smoke test for built image
tests/smoke.sh checks a built image under timeouts: non-interactive login shells exit, help50 deps are installed, wrappers print with stdin redirected. Run via make smoke, and in CI before pushing to Docker Hub.
1 parent 11563e1 commit 89610de

3 files changed

Lines changed: 46 additions & 1 deletion

File tree

‎.github/workflows/main.yml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ jobs:
3030
cs50/cli:amd64
3131
cs50/cli:canary-amd64
3232
33+
- name: Check out tests
34+
uses: actions/checkout@v7
35+
36+
- name: Smoke-test linux/amd64 build
37+
run: |
38+
bash tests/smoke.sh cs50/cli:canary-amd64
39+
3340
- name: Push linux/amd64 build to Docker Hub
3441
if: ${{ github.ref == 'refs/heads/main' }}
3542
run: |
@@ -68,6 +75,13 @@ jobs:
6875
cs50/cli:arm64
6976
cs50/cli:canary-arm64
7077
78+
- name: Check out tests
79+
uses: actions/checkout@v7
80+
81+
- name: Smoke-test linux/arm64 build
82+
run: |
83+
bash tests/smoke.sh cs50/cli:canary-arm64
84+
7185
- name: Push linux/arm64 build to Docker Hub
7286
if: ${{ github.ref == 'refs/heads/main' }}
7387
run: |

‎Makefile‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ rebuild:
1313
docker build --build-arg VCS_REF=$(shell git rev-parse HEAD) --no-cache --tag $(IMAGE) .
1414

1515
run:
16-
docker run --env LANG=$(LANG) --env LOCAL_WORKSPACE_FOLDER="$(PWD)" --env WORKDIR=/mnt --interactive --publish-all --rm --security-opt seccomp=unconfined --tty --volume "$(PWD)":/mnt --volume /var/run/docker.sock:/var/run/docker-host.sock --workdir /mnt cs50/cli bash --login || true
16+
docker run --env LANG=$(LANG) --env LOCAL_WORKSPACE_FOLDER="$(PWD)" --env WORKDIR=/mnt --interactive --publish-all --rm --security-opt seccomp=unconfined --tty --volume "$(PWD)":/mnt --volume /var/run/docker.sock:/var/run/docker-host.sock --workdir /mnt $(IMAGE) bash --login || true
17+
18+
smoke:
19+
bash tests/smoke.sh $(IMAGE)
1720

1821
squash: depends
1922
docker-squash --tag $(IMAGE) $(IMAGE)

‎tests/smoke.sh‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
# Smoke-tests a built cs50/cli image. Usage: tests/smoke.sh [IMAGE]
3+
# Each check has a timeout so that a regression that hangs the shell fails loudly.
4+
5+
set -o errexit -o nounset -o pipefail
6+
7+
IMAGE="${1:-cs50/cli}"
8+
run() { timeout 60 docker run --rm "$@"; }
9+
10+
echo "Checking $IMAGE"
11+
12+
echo "- non-interactive login shell exits (help50 must not start without a terminal)"
13+
run "$IMAGE" bash --login -c 'echo ok' | grep -qx ok
14+
echo true | run --interactive "$IMAGE" bash --login
15+
16+
echo "- runtime dependencies of help50 are installed"
17+
run "$IMAGE" bash --login -c 'for c in ansi2txt col file script fold; do command -v "$c" > /dev/null || { echo "missing $c" >&2; exit 1; }; done'
18+
19+
echo "- help50 controller is the Bash version, on PATH, and enabled by default"
20+
run "$IMAGE" bash --login -c 'test "$(type -P help50)" = /opt/cs50/bin/help50 && help50 is-enabled && test "$(help50 status)" = stopped' > /dev/null
21+
22+
echo "- wrappers print their message even when stdin is redirected"
23+
run "$IMAGE" bash --login -c 'valgrind python x.py < /dev/null; test $? -eq 1' 2>&1 | grep -q 'does not support Python'
24+
25+
echo "- _fold wraps without a terminal"
26+
run "$IMAGE" bash --login -c '. /opt/cs50/lib/cli; TERM= _fold "$(printf "a %.0s" {1..100})"' | head -n 1 | grep -qE '^.{1,80}$'
27+
28+
echo "OK"

0 commit comments

Comments
 (0)