From d708a813a34ed757ca50a9d004e1df273841897d Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Tue, 20 Apr 2021 11:13:16 +0200 Subject: [PATCH] tests: add tests for abuild-fetch --- tests/abuild-fetch.bats | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/abuild-fetch.bats diff --git a/tests/abuild-fetch.bats b/tests/abuild-fetch.bats new file mode 100644 index 0000000..fea3ac6 --- /dev/null +++ b/tests/abuild-fetch.bats @@ -0,0 +1,36 @@ +setup() { + export ABUILD_FETCH="$PWD/../abuild-fetch" + + tmpdir="$BATS_TMPDIR"/abuild-fetch + bindir="$tmpdir"/bin + mkdir -p "$bindir" + export PATH="$bindir:$PATH" + + # fake curl + cat >> "$bindir"/curl <<-EOF + #!/bin/sh + + touch "$tmpdir"/curl-invoked + echo "Fake curl invoked with: \$@" + exit \${CURL_EXITCODE:-0} + EOF + chmod +x "$bindir"/curl +} + +teardown() { + rm -rf "$tmpdir" +} + +@test "abuild-fetch: help text" { + $ABUILD_FETCH -h +} + +@test "abuild-fetch: test curl invocation" { + $ABUILD_FETCH -d "$tmpdir" https://example.com/non-existing + [ -f "$tmpdir"/curl-invoked ] +} + +@test "abuild-fetch: test curl failure" { + run CURL_EXITCODE=1 $ABUILD_FETCH -d "$tmpdir" https://example.com/non-existing + [ $status -ne 0 ] +}