From 8e08e1a1fd6ba8f85cc71c5fd077e60c6062a4ce Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 19 May 2022 21:08:45 +0000 Subject: tests: make it possible to simluate wget failure Make it possible to simulate wget errors by fetching an URL with 'fail' or '404' in the URL string. 'fail' results in DNS error(ish) and '404' returns a 404 error message. --- tests/bin/wget | 7 +++++++ tests/fake_wget_test | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/bin/wget b/tests/bin/wget index 72306a4..5efc612 100755 --- a/tests/bin/wget +++ b/tests/bin/wget @@ -63,6 +63,13 @@ while true; do shift done +for url; do + case "$url" in + *fail*) msg "bad address"; exit 1;; + *404*) msg "wget: server returned error: HTTP/1.1 404 Not Found"; exit 1;; + esac +done + : ${outfile:=index.html} case "$outfile" in -) msg "writing to stdout" diff --git a/tests/fake_wget_test b/tests/fake_wget_test index dac7681..c8c4152 100755 --- a/tests/fake_wget_test +++ b/tests/fake_wget_test @@ -7,7 +7,9 @@ init_tests \ fake_wget_quiet \ fake_wget \ fake_wget_outfile \ - fake_wget_stdout + fake_wget_stdout \ + fake_wget_fail \ + fake_wget_404 fake_wget_usage_body() { test_usage wget @@ -56,3 +58,18 @@ fake_wget_stdout_body() { wget -O - https://example.com ! test -f - || atf_fail "- was created" } + +fake_wget_fail_body() { + init_env + atf_check -s exit:1 \ + -e match:"bad address" \ + wget https://example.com/fail +} + +fake_wget_404_body() { + init_env + atf_check -s exit:1 \ + -e match:"404 Not Found" \ + wget https://example.com/404 +} + -- cgit v1.2.3