summaryrefslogtreecommitdiff
path: root/tests/setup_user_test
blob: e2f358ce6ff8f517a97a489f1da5022d7c577975 (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
#!/usr/bin/env atf-sh

. $(atf_get_srcdir)/test_env.sh
init_tests \
	setup_user_usage \
	setup_user_fullname \
	setup_user_interactive \
	setup_user_interactive_fullname \
	setup_user_interactive_singlename \
	setup_user_groups_commas \
	setup_user_groups_spaces

setup_user_usage_body() {
	test_usage setup-user
}

setup_user_body() {
	init_env
	atf_check -s exit:0 \
		-o match:"adduser -D testuser" \
		-e empty \
		setup-user testuser
}

setup_user_fullname_body() {
	init_env
	atf_check -s exit:0 \
		-o match:"adduser.* -D .*testuser" \
		-o match:"adduser.* -g Joe User .*testuser" \
		-e empty \
		setup-user -f "Joe User" testuser
}

setup_user_interactive_body() {
	init_env
	(
		echo "Joe User"
		echo "testuser"
		echo "none"
	) | atf_check -s exit:0 \
		-o match:"Enter full name" \
		-o match:"Enter username" \
		-o not-match:"adduser.* -D .*testuser" \
		-o match:"adduser.* -g Joe User .*testuser" \
		-e empty \
		setup-user
}

setup_user_interactive_fullname_body() {
	init_env
	(
		echo ""
	) | atf_check -s exit:0 \
		-o not-match:"Enter full name" \
		-o match:"Enter username.*[juser]" \
		-o not-match:"adduser.* -D .*" \
		-o match:"adduser.* -g Joe User .*juser" \
		-e empty \
		setup-user -f "Joe User" -k none
}

setup_user_interactive_singlename_body() {
	init_env
	(
		echo ""
	) | atf_check -s exit:0 \
		-o not-match:"Enter full name" \
		-o match:"Enter username.*[joe]" \
		-o not-match:"adduser.* -D .*" \
		-o match:"adduser.* -g Joe .*joe" \
		-e empty \
		setup-user -f "Joe" -k none
}

setup_user_groups_commas_body() {
	init_env
	atf_check -s exit:0 \
		-o match:"addgroup testuser wheel" \
		-o match:"addgroup testuser audio" \
		-o match:"addgroup testuser video" \
		-e empty \
		setup-user -g wheel,audio,video testuser
}

setup_user_groups_spaces_body() {
	init_env
	atf_check -s exit:0 \
		-o match:"addgroup testuser wheel" \
		-o match:"addgroup testuser audio" \
		-o match:"addgroup testuser video" \
		-e empty \
		setup-user -g "wheel audio video" testuser
}