aboutsummaryrefslogtreecommitdiff
path: root/scripts/test/groupadd.test
diff options
context:
space:
mode:
authorDivya Kothari <divya.s.kothari@gmail.com>2014-07-04 21:20:02 -0500
committerDivya Kothari <divya.s.kothari@gmail.com>2014-07-04 21:20:02 -0500
commitef0ed68d5ba5794c1352e64273d4c5039e62476b (patch)
treece65d458c8f5e0b51eaf8f0be4caa07c07792d7d /scripts/test/groupadd.test
parent4a855d6cf62cebe40fa9fe97c7e6b9ca49f79b5b (diff)
downloadtoybox-ef0ed68d5ba5794c1352e64273d4c5039e62476b.tar.gz
I have developed few testsuites for toybox commands -
1. lsattr/chattr 2. mount 3. chmod 4. pgrep/pkill 5. groupadd 6. groupdel 7. useradd
Diffstat (limited to 'scripts/test/groupadd.test')
-rw-r--r--scripts/test/groupadd.test56
1 files changed, 56 insertions, 0 deletions
diff --git a/scripts/test/groupadd.test b/scripts/test/groupadd.test
new file mode 100644
index 00000000..0395e01a
--- /dev/null
+++ b/scripts/test/groupadd.test
@@ -0,0 +1,56 @@
+#!/bin/bash
+# Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
+# Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
+
+[ -f testing.sh ] && . testing.sh
+
+# 70 characters long string; hereafter, we will use it as per our need.
+_s70="abcdefghijklmnopqrstuvwxyz123456789abcdefghijklmnopqrstuvwxyz123456789"
+
+echo "# usage: addgroup [-g GID] [USER] GROUP
+# Add a group or add a user to a group."
+
+# Redirecting all output to /dev/null for grep and delgroup
+arg="&>/dev/null"
+
+#testing "name" "command" "result" "infile" "stdin"
+
+testing "groupadd group_name (text)" "groupadd toyTestGroup &&
+ grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg &&
+ echo 'yes'" "yes\n" "" ""
+testing "groupadd group_name (alphanumeric)" "groupadd toy1Test2Group3 &&
+ grep '^toy1Test2Group3:' /etc/group $arg && groupdel toy1Test2Group3 $arg &&
+ echo 'yes'" "yes\n" "" ""
+testing "groupadd group_name (numeric)" "groupadd 987654321 &&
+ grep '^987654321:' /etc/group $arg && groupdel 987654321 $arg &&
+ echo 'yes'" "yes\n" "" ""
+testing "groupadd group_name (with ./-)" "groupadd toy.1Test-2Group.3 &&
+ grep '^toy.1Test-2Group.3:' /etc/group $arg &&
+ groupdel toy.1Test-2Group.3 $arg && echo 'yes'" "yes\n" "" ""
+
+_s210=`echo $_s70$_s70$_s70`
+testing "groupadd group_name (long string)" "groupadd $_s210 &&
+ grep '^$_s210:' /etc/group $arg && groupdel $_s210 $arg && echo 'yes'" \
+ "yes\n" "" ""
+testing "groupadd group_name with group_id" "groupadd -g 49999 toyTestGroup &&
+ grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg &&
+ echo 'yes'" "yes\n" "" ""
+testing "groupadd group_name with group_id (system_group)" \
+ "groupadd -g 49999 -S toyTestGroup && grep '^toyTestGroup:' /etc/group $arg &&
+ groupdel toyTestGroup $arg && echo 'yes'" "yes\n" "" ""
+testing "groupadd group_name (system_group)" "groupadd -S toyTestGroup &&
+ grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg &&
+ echo 'yes'" "yes\n" "" ""
+testing "groupadd group_name (add/del user)" "groupadd toyTestGroup &&
+ grep '^toyTestGroup:' /etc/group $arg && groupadd $USER toyTestGroup &&
+ grep '^toyTestGroup:.*:.*:.*$USER.*' /etc/group $arg &&
+ groupdel $USER toyTestGroup $arg || groupdel toyTestGroup &&
+ grep '^toyTestGroup:' /etc/group $arg || echo 'yes'" "yes\n" "" ""
+
+ echo "Testing to add single group multiple times after removing it..."
+ for each in {01..20}
+ do
+ testing "groupadd group_name ($each)" "groupadd toyTestGroup &&
+ grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg &&
+ echo 'yes'" "yes\n" "" ""
+ done