secrets/test/main.sh (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 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
|