summaryrefslogtreecommitdiff
path: root/tests/setup_interfaces_test
blob: c09968c60a2b41913d550482d171310215810598 (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
#!/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_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
}