diff --git a/tests/test.sh b/tests/test.sh index 0b3d67d6048f9b70f512123c3b2dc77fb0aa049a..ea748c011f27f08456c77f62ec9a1acdca6b5e48 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -#4214!/usr/bin/env ./libs/bats/bin/bats ### # Entry point for running unittests. ## @@ -14,10 +13,15 @@ text_reset="\033[0m" text_purple="\033[0;35m" +# Get sudo password now so we don't have to later. +echo -e "To fully test some functions, script may ask for your sudo password." +sudo ls > /dev/null 2>&1 + + # Run Directory Function tests. echo "" echo -e "Running ${text_purple}Directory Function${text_reset} tests." - +./libs/bats/bin/bats ./test_directory_functions.sh echo -e "Finished ${text_purple}Directory Function${text_reset} Tests." echo "" @@ -25,7 +29,8 @@ echo "" # Run User Function tests. echo "" echo -e "Running ${text_purple}User Function${text_reset} tests." - +./libs/bats/bin/bats ./test_user_functions.sh +sudo ./libs/bats/bin/bats ./test_user_functions_sudo.sh echo -e "Finished ${text_purple}User Function${text_reset} tests." echo "" @@ -33,7 +38,7 @@ echo "" # Run Text Function tests. echo "" echo -e "Running ${text_purple}Text Function${text_reset} tests." - +./libs/bats/bin/bats ./test_text_functions.sh echo -e "Finished ${text_purple}Text Function${text_reset} tests." echo "" @@ -41,6 +46,6 @@ echo "" # Run Display Function tests. echo "" echo -e "Running ${text_purple}Display Function${text_reset} tests." - +./libs/bats/bin/bats ./test_display_functions.sh echo -e "Finished ${text_purple}Display Function${text_reset} tests." echo "" diff --git a/tests/test_text_functions.sh b/tests/test_text_functions.sh new file mode 100755 index 0000000000000000000000000000000000000000..ab633fe2bac8d25bf0a01d35f0539ae1eaa07040 --- /dev/null +++ b/tests/test_text_functions.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +### + # Tests for the "Text Manipulation Functions" section of the utils script. + ## + + +# Load UnitTesting libraries. +load 'libs/bats-assert/load' +load 'libs/bats-support/load' + + +setup() { + mixed_case_var="ThisIsMixedCase" +} + + +@test "Text Function - to_upper" { + # Import utils script. + source ../utils.sh + + to_upper ${mixed_case_var} + [[ "${return_value}" == "THISISMIXEDCASE" ]] +} + + +@test "Text Function - to_lower" { + # Import utils script. + source ../utils.sh + + to_lower ${mixed_case_var} + [[ "${return_value}" == "thisismixedcase" ]] +} diff --git a/tests/test_user_functions.sh b/tests/test_user_functions.sh new file mode 100755 index 0000000000000000000000000000000000000000..5900bfbbc646f72e6bf80aa344ad0bec8ce96542 --- /dev/null +++ b/tests/test_user_functions.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash +### + # Tests for the "User Check Functions" section of the utils script. + ## + + +# Load UnitTesting libraries. +load 'libs/bats-assert/load' +load 'libs/bats-support/load' + + + +@test "User Function - check_is_user - Success - Current User" { + # Import utils script. + source ../utils.sh + + run $(check_is_user ${USER}) + assert_success +} + + +@test "User Function - check_is_user - Failure - Current User" { + # Import utils script. + source ../utils.sh + + run $(check_is_user "some_test_user") + assert_failure +} + + +@test "User Function - check_is_user - Failure - Sudo" { + # Import utils script. + source ../utils.sh + + run $(check_is_user "sudo") + assert_failure +} + + +@test "User Function - check_is_user - Failure - Root" { + # Import utils script. + source ../utils.sh + + run $(check_is_user "root") + assert_failure +} + + +@test "User Function - check_is_not_user - Success - Current User" { + # Import utils script. + source ../utils.sh + + run $(check_is_not_user "some_test_user") + assert_success +} + + +@test "User Function - check_is_not_user - Success - Sudo" { + # Import utils script. + source ../utils.sh + + run $(check_is_not_user "sudo") + assert_success +} + + +@test "User Function - check_is_not_user - Success - Root" { + # Import utils script. + source ../utils.sh + + run $(check_is_not_user "root") + assert_success +} + + +@test "User Function - check_is_not_user - Failure - Current User" { + # Import utils script. + source ../utils.sh + + run $(check_is_not_user ${USER}) + assert_failure +} diff --git a/tests/test_user_functions_sudo.sh b/tests/test_user_functions_sudo.sh new file mode 100644 index 0000000000000000000000000000000000000000..e94de55da9d8e06392ddd3084678bfede4198463 --- /dev/null +++ b/tests/test_user_functions_sudo.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +### + # Tests for the "User Check Functions" section of the utils script. + ## + + +# Load UnitTesting libraries. +load 'libs/bats-assert/load' +load 'libs/bats-support/load' + + +@test "User Function - check_is_user - Success - Sudo" { + # Import utils script. + source ../utils.sh + + run $(check_is_user "sudo") + assert_success +} + + +@test "User Function - check_is_user - Success - Root" { + # Import utils script. + source ../utils.sh + + run $(check_is_user "root") + assert_success +} + + +@test "User Function - check_is_not_user - Failure - Sudo" { + # Import utils script. + source ../utils.sh + + run $(check_is_not_user "sudo") + assert_failure +} + + +@test "User Function - check_is_not_user - Failure - Root" { + # Import utils script. + source ../utils.sh + + run $(check_is_not_user "root") + assert_failure +}