summaryrefslogtreecommitdiffstats
path: root/pw/tests/pw_usernext_test.sh
blob: 89f938ec8c336c96a9e0b436c6753a8baef5d11b (plain) (blame)
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
# $FreeBSD$

# Import helper functions
. $(atf_get_srcdir)/helper_functions.shin

# Test usernext after adding a random number of new users.
atf_test_case usernext
usernext_body() {
	populate_etc_skel

	CURRENT=`${PW} usernext | sed -e 's/:.*//'`
	RANDOM=`jot -r 1 1 150`
	MAX=`expr ${CURRENT} + ${RANDOM}`
	while [ "${CURRENT}" -lt "${MAX}" ]
	do
		atf_check -s exit:0 ${PW} useradd test${CURRENT}
		CURRENT=`expr ${CURRENT} + 1`
	done
	atf_check -s exit:0 -o match:"${CURRENT}:${CURRENT}" \
		${PW} usernext
}

# Test usernext when multiple users are added to the same group so 
# that group id doesn't increment at the same pace as new users.
atf_test_case usernext_assigned_group
usernext_assigned_group_body() {
	populate_etc_skel

	CURRENT=`${PW} usernext | sed -e 's/:.*//'`
	CURRENTGID=`${PW} groupnext`
	RANDOM=`jot -r 1 1 150`
	MAX=`expr ${CURRENT} + ${RANDOM}`
	while [ "${CURRENT}" -lt "${MAX}" ]
	do
		atf_check -s exit:0 ${PW} useradd -n test${CURRENT} -g 0
		CURRENT=`expr ${CURRENT} + 1`
	done
	atf_check -s exit:0 -o match:"${CURRENT}:${CURRENTGID}" \
		${PW} usernext
}

atf_init_test_cases() {
	atf_add_test_case usernext
	atf_add_test_case usernext_assigned_group
}