abuild/tests/abuild_fetch_test

91 lines
1.9 KiB
Plaintext
Raw Normal View History

2022-06-14 15:12:22 +00:00
#!/usr/bin/env atf-sh
. $(atf_get_srcdir)/test_env.sh
init_tests \
abuild_fetch_help \
2022-06-14 15:30:24 +00:00
abuild_fetch_curl_invocation \
abuild_fetch_curl_failure \
abuild_fetch_curl_insecure \
2022-06-14 15:56:16 +00:00
abuild_fetch_wget_fallback \
abuild_fetch_wget_failure
create_fake_curl() {
mkdir bin
# fake curl
cat > bin/curl <<-EOF
#!/bin/sh
echo "[\$\$] Fake curl invoked with: \$@"
if [ -n "\$FIFO" ]; then
echo "[\$\$] waiting for fifo \$FIFO"
cat "\$FIFO"
fi
exit \${CURL_EXITCODE:-0}
EOF
chmod +x bin/curl
PATH="$PWD/bin:$PATH"
}
2022-06-14 15:12:22 +00:00
create_fake_wget() {
mkdir -p bin
cat > bin/wget <<-EOF
#!/bin/sh
echo "Fake wget invoked with: \$@"
exit \${WGET_EXITCODE:-0}
EOF
chmod +x bin/wget
}
2022-06-14 15:12:22 +00:00
abuild_fetch_help_body() {
atf_check -s exit:0 \
-o not-empty \
-e empty \
abuild-fetch -h
}
abuild_fetch_curl_invocation_body() {
create_fake_curl
atf_check -s exit:0 \
-o match:"Fake curl invoked" \
-e empty \
abuild-fetch https://example.com/non-existing
}
2022-06-14 15:30:24 +00:00
abuild_fetch_curl_failure_body() {
create_fake_curl
# verify that fake curl works
CURL_EXITCODE=1 atf_check -s exit:$CURL_EXITCODE \
-o match:"Fake curl invoked" \
curl
CURL_EXITCODE=1 atf_check -s exit:$CURL_EXITCODE \
-o match:"Fake curl invoked" \
-e empty \
abuild-fetch https://example.com/non-existing
}
abuild_fetch_curl_insecure_body() {
create_fake_curl
atf_check -s exit:0 \
-o match:"--insecure" \
-e empty \
abuild-fetch http://example.com/non-existing
}
abuild_fetch_wget_fallback_body() {
create_fake_wget
PATH="$PWD/bin:$(atf_get_srcdir)/.." atf_check -s exit:0 \
-o match:"Fake wget invoked" \
-e empty \
abuild-fetch https://example.com/non-existing
}
2022-06-14 15:56:16 +00:00
abuild_fetch_wget_failure_body() {
create_fake_wget
WGET_EXITCODE=1 PATH="$PWD/bin:$(atf_get_srcdir)/.." atf_check -s exit:1 \
-o match:"Fake wget invoked" \
-e empty \
abuild-fetch https://example.com/non-existing
}