From d345655a2e6570bb88889f6d469de8d19d45e870 Mon Sep 17 00:00:00 2001 From: yubiuser Date: Wed, 18 Sep 2024 21:49:31 +0200 Subject: [PATCH] Add bast-assert Signed-off-by: yubiuser --- .github/Dockerfile | 3 ++- test/run.sh | 2 +- test/test_suite.bats | 11 ++++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/Dockerfile b/.github/Dockerfile index ec0e9c3ff8..d5910c915a 100644 --- a/.github/Dockerfile +++ b/.github/Dockerfile @@ -17,8 +17,9 @@ ENV BUILD_OPTS=${BUILD_OPTS} RUN apk add --no-cache ncurses ENV TERM=xterm -# Add bats-support for testing +# Add bats-support and bats-assert for testing RUN git clone --depth=1 --quiet https://github.com/bats-core/bats-support test/libs/bats-support > /dev/null +RUN git clone --depth=1 --quiet https://github.com/bats-core/bats-assert test/libs/bats-assert > /dev/null # Build FTL # Remove possible old build files diff --git a/test/run.sh b/test/run.sh index 626a5dc705..5d490a8228 100755 --- a/test/run.sh +++ b/test/run.sh @@ -106,7 +106,7 @@ echo -n "Contained dnsmasq version (DNS): " dig TXT CHAOS version.bind @127.0.0.1 +short # Run tests -$BATS -p "test/test_suite.bats" +$BATS "test/test_suite.bats" RET=$? curl_to_tricorder() { diff --git a/test/test_suite.bats b/test/test_suite.bats index 445958931d..76f642b797 100644 --- a/test/test_suite.bats +++ b/test/test_suite.bats @@ -2,6 +2,11 @@ # load bats-support load 'libs/bats-support/load' +load 'libs/bats-assert/load' + +@test 'fail()' { + fail 'this test always fails' +} @test "Compare template and test TOML config files" { # We skip the first 5 lines of the files as they contain the version and @@ -14,14 +19,14 @@ load 'libs/bats-support/load' @test "Running a second instance is detected and prevented" { run bash -c 'su pihole -s /bin/sh -c "./pihole-FTL -f"' printf "%s\n" "${lines[@]}" - [[ "${lines[@]}" == *"CRIT: pihole-FTL is already running"* ]] + assert_output --partial 'CRIT: pihole-FTL is already running' } @test "dnsmasq options as expected" { run bash -c './pihole-FTL -vv | grep "cryptohash"' printf "%s\n" "${lines[@]}" - [[ ${lines[0]} == "Features: IPv6 GNU-getopt no-DBus no-UBus no-i18n IDN2 DHCP DHCPv6 Lua TFTP no-conntrack ipset no-nftset auth cryptohash DNSSEC loop-detect inotify dumpfile" ]] - [[ ${lines[1]} == "" ]] + assert_line --index 0 "Features: IPv6 GNU-getopt no-DBus no-UBus no-i18n IDN2 DHCP DHCPv6 Lua TFTP no-conntrack ipset no-nftset auth cryptohash DNSSEC loop-detect inotify dumpfile" + assert_line --index 1 '' } @test "Initial blocking status is enabled" {