xref: /freebsd/usr.sbin/pw/tests/pw_usernext_test.sh (revision 734e82fe33aa764367791a7d603b383996c6b40b)
1
2# Import helper functions
3. $(atf_get_srcdir)/helper_functions.shin
4
5# Test usernext after adding a random number of new users.
6atf_test_case usernext
7usernext_body() {
8	populate_etc_skel
9
10	CURRENT=`${PW} usernext | sed -e 's/:.*//'`
11	RANDOM=`jot -r 1 1 150`
12	MAX=`expr ${CURRENT} + ${RANDOM}`
13	while [ "${CURRENT}" -lt "${MAX}" ]
14	do
15		atf_check -s exit:0 ${PW} useradd test${CURRENT}
16		CURRENT=`expr ${CURRENT} + 1`
17	done
18	atf_check -s exit:0 -o match:"${CURRENT}:${CURRENT}" \
19		${PW} usernext
20}
21
22# Test usernext when multiple users are added to the same group so
23# that group id doesn't increment at the same pace as new users.
24atf_test_case usernext_assigned_group
25usernext_assigned_group_body() {
26	populate_etc_skel
27
28	CURRENT=`${PW} usernext | sed -e 's/:.*//'`
29	CURRENTGID=`${PW} groupnext`
30	RANDOM=`jot -r 1 1 150`
31	MAX=`expr ${CURRENT} + ${RANDOM}`
32	while [ "${CURRENT}" -lt "${MAX}" ]
33	do
34		atf_check -s exit:0 ${PW} useradd -n test${CURRENT} -g 0
35		CURRENT=`expr ${CURRENT} + 1`
36	done
37	atf_check -s exit:0 -o match:"${CURRENT}:${CURRENTGID}" \
38		${PW} usernext
39}
40
41atf_init_test_cases() {
42	atf_add_test_case usernext
43	atf_add_test_case usernext_assigned_group
44}
45