summaryrefslogtreecommitdiff
path: root/tests/setup_interfaces_test
blob: a2e03d61c94e166b48ed5b91b85506460c126a4a (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env atf-sh

. $(atf_get_srcdir)/test_env.sh
init_tests \
	setup_interfaces_usage \
	setup_interfaces_interactive_dhcp \
	setup_interfaces_interactive_vlan \
	setup_interfaces_interactive_vlan_ng \
	setup_interfaces_interactive_vlan0_ng

setup_interfaces_usage_body() {
	test_usage setup-interfaces
}

create_fake_ifaces() {
	local n=1
	for i; do
		mkdir -p sys/class/net/$i
		echo $n > sys/class/net/$i/ifindex
		echo down >sys/class/net/$i/operstate
		n=$((n+1))
	done
}

setup_interfaces_interactive_dhcp_body() {
	init_env
	create_fake_ifaces lo eth0
	(
		# Which one do you want to initialize? (or '?' or 'done') [eth0]
		echo eth0
		# Ip address for eth0? (or 'dhcp', 'none', '?') [dhcp]
		echo dhcp
		# Do you want to do any manual network configuration? (y/n) [n]
		echo n
	)>answers
	atf_check -s exit:0 \
		-o match:"Available interfaces are: eth0" \
		setup-interfaces <answers
}

setup_interfaces_interactive_vlan_body() {
	init_env
	create_fake_ifaces lo eth0
	(
		# Which one do you want to initialize? (or '?' or 'done') [eth0]
		echo eth0.5
		# Ip address for eth0.5? (or 'dhcp', 'none', '?') [dhcp]
		echo dhcp
		# Which one do you want to initialize? (or '?' or 'done') [eth0]
		echo done
		# Do you want to do any manual network configuration? (y/n) [n]
		echo n
	)>answers
	atf_check -s exit:0 \
		-o match:"apk add.*vlan" \
		setup-interfaces <answers
}

setup_interfaces_interactive_vlan_ng_body() {
	init_env
	create_fake_ifaces lo eth0

	mkdir -p usr/libexec/ifupdown-ng
	touch usr/libexec/ifupdown-ng/link

	(
		# Which one do you want to initialize? (or '?' or 'done') [eth0]
		echo eth0.5
		# Ip address for eth0.5? (or 'dhcp', 'none', '?') [dhcp]
		echo dhcp
		# Which one do you want to initialize? (or '?' or 'done') [eth0]
		echo done
		# Do you want to do any manual network configuration? (y/n) [n]
		echo n
	)>answers
	atf_check -s exit:0 \
		-o not-match:"apk add.*vlan" \
		setup-interfaces <answers
}

setup_interfaces_interactive_vlan0_ng_body() {
	init_env
	create_fake_ifaces lo eth0

	mkdir -p usr/libexec/ifupdown-ng
	touch usr/libexec/ifupdown-ng/link

	(
		# Which one do you want to initialize? (or '?' or 'done') [eth0]
		echo vlan0
		# Which one do you want use for vlan0? (or 'done') [eth0]
		echo eth0
		# Ip address for vlan0? (or 'dhcp', 'none', '?') [dhcp]
		echo dhcp
		# Which one do you want to initialize? (or '?' or 'done') [eth0]
		echo done
		# Do you want to do any manual network configuration? (y/n) [n]
		echo n
	)>answers
	atf_check -s exit:0 \
		-o match:"Available raw devices are: eth0" \
		-o not-match:"apk add.*vlan" \
		setup-interfaces <answers
}