summaryrefslogtreecommitdiff
path: root/secrets/test/main.sh
diff options
context:
space:
mode:
Diffstat (limited to 'secrets/test/main.sh')
-rwxr-xr-xsecrets/test/main.sh57
1 files changed, 57 insertions, 0 deletions
diff --git a/secrets/test/main.sh b/secrets/test/main.sh
new file mode 100755
index 0000000..23c8dd2
--- /dev/null
+++ b/secrets/test/main.sh
@@ -0,0 +1,57 @@
+#!/bin/bash
+# Tests for main entrypoint
+
+this_dir="$(cd "$(dirname "$0")" && pwd)"
+source "${this_dir}/common.sh"
+
+test_main_help() {
+ local output
+ output="$(szecret --help)"
+ assert_contains "${output}" "szecret" "help output"
+ assert_contains "${output}" "Usage" "help output"
+ pass "main --help shows usage"
+}
+
+test_main_help_short() {
+ local output
+ output="$(szecret -h)"
+ assert_contains "${output}" "szecret" "help output"
+ pass "main -h shows usage"
+}
+
+test_main_unknown_command() {
+ assert_failure szecret nonexistent-command
+ pass "main fails on unknown command"
+}
+
+test_main_no_command() {
+ assert_failure szecret
+ pass "main fails without command"
+}
+
+test_main_dispatches_to_command() {
+ echo "dispatch-test-value" | szecret put "dispatch-test"
+ local retrieved
+ retrieved="$(szecret get "dispatch-test")"
+ assert_equals "dispatch-test-value" "${retrieved}" "dispatched command"
+ pass "main dispatches to commands"
+}
+
+test_command_help() {
+ local output
+ output="$(szecret get --help)"
+ assert_contains "${output}" "get" "command help"
+ assert_contains "${output}" "Usage" "command help"
+ pass "command --help shows command usage"
+}
+
+run_tests() {
+ test_main_help
+ test_main_help_short
+ test_main_unknown_command
+ test_main_no_command
+ test_main_dispatches_to_command
+ test_command_help
+}
+
+[[ "${BASH_SOURCE[0]}" == "${0}" ]] && run_tests