summaryrefslogtreecommitdiff
path: root/secrets/test/list.sh
diff options
context:
space:
mode:
Diffstat (limited to 'secrets/test/list.sh')
-rwxr-xr-xsecrets/test/list.sh55
1 files changed, 55 insertions, 0 deletions
diff --git a/secrets/test/list.sh b/secrets/test/list.sh
new file mode 100755
index 0000000..08671c8
--- /dev/null
+++ b/secrets/test/list.sh
@@ -0,0 +1,55 @@
+#!/bin/bash
+# Tests for list command
+
+this_dir="$(cd "$(dirname "$0")" && pwd)"
+source "${this_dir}/common.sh"
+
+test_list_shows_secrets() {
+ echo "value1" | szecret put "secret-a"
+ echo "value2" | szecret put "secret-b"
+ echo "value3" | szecret put "secret-c"
+
+ local list_output
+ list_output="$(szecret list)"
+
+ assert_contains "${list_output}" "secret-a" "list output"
+ assert_contains "${list_output}" "secret-b" "list output"
+ assert_contains "${list_output}" "secret-c" "list output"
+ pass "list shows all secrets"
+}
+
+test_list_empty_store() {
+ local list_output
+ list_output="$(szecret list)"
+ assert_equals "" "${list_output}" "empty list"
+ pass "list handles empty store"
+}
+
+test_list_sorted() {
+ echo "v" | szecret put "zebra"
+ echo "v" | szecret put "apple"
+ echo "v" | szecret put "mango"
+
+ local list_output
+ list_output="$(szecret list)"
+
+ # Check that apple comes before mango comes before zebra
+ local apple_pos mango_pos zebra_pos
+ apple_pos=$(echo "${list_output}" | grep -n "apple" | cut -d: -f1)
+ mango_pos=$(echo "${list_output}" | grep -n "mango" | cut -d: -f1)
+ zebra_pos=$(echo "${list_output}" | grep -n "zebra" | cut -d: -f1)
+
+ if [[ "${apple_pos}" -lt "${mango_pos}" && "${mango_pos}" -lt "${zebra_pos}" ]]; then
+ pass "list is sorted"
+ else
+ fail "list is not sorted: apple=${apple_pos}, mango=${mango_pos}, zebra=${zebra_pos}"
+ fi
+}
+
+run_tests() {
+ test_list_empty_store
+ test_list_shows_secrets
+ test_list_sorted
+}
+
+[[ "${BASH_SOURCE[0]}" == "${0}" ]] && run_tests