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