From: Kyle Bowman Date: Sun, 30 Mar 2025 15:49:45 +0000 (-0400) Subject: feat: check for container before running tests X-Git-Url: https://git.rocketbowman.com/?a=commitdiff_plain;h=fd12b9737ee1fd124956e82c50d45ad77a7c2313;p=belfry.git feat: check for container before running tests --- diff --git a/Dockerfile b/Dockerfile index 315f6d2..df3d76d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ FROM debian:bookworm-20250317-slim +ENV IN_CONTAINER=true RUN apt update \ && apt install -y bats \ No newline at end of file diff --git a/tests/test_example.bats b/tests/test_example.bats index 3d7bcd9..2a61dda 100644 --- a/tests/test_example.bats +++ b/tests/test_example.bats @@ -1,18 +1,33 @@ #!/usr/bin/env bats -setup() { - # Run before each test case - # Example: start container, prepare environment +#################### +# Setup & Teardown # +#################### +# setup_file is run once for this whole file +setup_file() { + + # Ensure sandboxed if the script has side effects. + if [ -z "$IN_CONTAINER" ]; then + echo "This script has side effects and must be run in a container." > /dev/stderr + exit 1 + fi +} + +# setup is run once per test case +setup () { + # Source library LIB_DIR="$(dirname $(dirname "$BATS_TEST_FILENAME"))/lib" . "$LIB_DIR"/example.sh } +# teardown is run after each test case teardown() { - # Run after each test case - # Example: stop/remove container, clean up resources echo "Teardown running" } +######### +# Tests # +######### @test "ensure echo_hello runs" { echo_hello }