summaryrefslogtreecommitdiff
path: root/tests/libalpine_test
blob: 2601a1bfd1f4560d5f25ee182c86101f633988d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
63
64
65
66
67
#!/usr/bin/env atf-sh

. $(atf_get_srcdir)/test_env.sh
init_tests \
	libalpine_isin \
	libalpine_available_ifaces \
	libalpine_available_ifaces_bond \
	libalpine_available_ifaces_bridge \
	libalpine_askpass

libalpine=$(atf_get_srcdir)/../libalpine.sh

libalpine_isin_body() {
	. "$libalpine"
	isin a a b c || atf_fail "isin a a b c"
	! isin foo bar baz a a b c || atf_fail" isin foo bar baz a a b c"
	isin "with space" foo "with space" "other space" || atf_fail 'isin "with space" foo "with space" "other space'
}

libalpine_available_ifaces_body() {
	init_env
	mkdir -p sys/class/net/lo sys/class/net/eth0
	echo 1 >sys/class/net/lo/ifindex
	echo 2 >sys/class/net/eth0/ifindex
	atf_check \
		-o match:"lo eth0" \
		sh -c ". $libalpine; available_ifaces"
}

libalpine_available_ifaces_bond_body() {
	init_env
	mkdir -p sys/class/net/lo \
		sys/class/net/eth0/master/bonding \
		sys/class/net/bond0
	echo 1 >sys/class/net/lo/ifindex
	echo 2 >sys/class/net/eth0/ifindex
	echo 3 >sys/class/net/bond0/ifindex

	atf_check \
		-o match:"lo bond0" \
		sh -c ". $libalpine; available_ifaces"
}

libalpine_available_ifaces_bridge_body() {
	init_env
	mkdir -p sys/class/net/lo \
		sys/class/net/eth0/brport \
		sys/class/net/br0
	echo 1 >sys/class/net/lo/ifindex
	echo 2 >sys/class/net/eth0/ifindex
	echo 3 >sys/class/net/br0/ifindex

	atf_check \
		-o match:"lo br0" \
		sh -c ". $libalpine; available_ifaces"
}

libalpine_askpass_body() {
	init_env
	echo foo >answer
	atf_check \
		-o match:"enter password" \
		-o match:"stty -echo" \
		-o match:"stty echo" \
		-o match:"resp=foo" \
		sh -c ". $libalpine; askpass 'enter password'<answer; echo resp=\$resp"
}