fake_wget_test 1.56 KB
Newer Older
Natanael Copa's avatar
Natanael Copa committed
1
2
3
4
5
6
7
8
9
#!/usr/bin/env atf-sh

. $(atf_get_srcdir)/test_env.sh
init_tests \
	fake_wget_usage \
	fake_wget_spider \
	fake_wget_quiet \
	fake_wget \
	fake_wget_outfile \
10
11
	fake_wget_stdout \
	fake_wget_fail \
12
13
14
	fake_wget_404 \
	fake_wget_missing_url \
	fake_wget_empty_url
Natanael Copa's avatar
Natanael Copa committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

fake_wget_usage_body() {
	test_usage wget
}

fake_wget_spider_body() {
	init_env
	atf_check -s exit:0 \
		-o empty \
		-e empty \
		wget --spider https://example.com
}

fake_wget_quiet_body() {
	init_env
	atf_check -s exit:0 \
		-o empty \
		-e empty \
		wget -q https://example.com
}

fake_wget_body() {
	init_env
	atf_check -s exit:0 \
		-o empty \
		-e match:"saving to 'index.html'" \
		wget https://example.com
		test -f index.html || atf_fail "index.html not created"
}

fake_wget_outfile_body() {
	init_env
	atf_check -s exit:0 \
		-o empty \
		-e match:"saving to 'foo'" \
		wget -O foo https://example.com
		test -f foo || atf_fail "foo not created"
}

fake_wget_stdout_body() {
	init_env
	export WGETCONTENT="hello world"
	atf_check -s exit:0 \
		-o match:"hello world" \
		-e match:"writing to stdout" \
		wget -O - https://example.com
		! test -f - || atf_fail "- was created"
}
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

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
}

78
79
80
81
82
83
84
85
86
87
88
89
90
91
fake_wget_missing_url_body() {
	init_env
	atf_check -s exit:1 \
		-e match:"usage:" \
		wget -q -O -
}

fake_wget_empty_url_body() {
	init_env
	atf_check -s exit:1 \
		-e match:"bad address" \
		wget ""
}