summaryrefslogtreecommitdiff
path: root/secrets/test/ensure.sh
blob: 720d3288deed7c5f4c1224f8a0f7d8b554331e0b (plain)
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
#!/bin/bash
# Tests for ensure command

this_dir="$(cd "$(dirname "$0")" && pwd)"
source "${this_dir}/common.sh"

test_ensure_succeeds_when_key_exists() {
    # Key already exists from setup, should succeed silently
    assert_success szecret ensure
    pass "ensure succeeds when key exists"
}

test_ensure_fails_noninteractive_without_key() {
    local saved_key="${SZECRET_PRIVATE_KEY}"
    export SZECRET_PRIVATE_KEY="${TEST_DIR}/nonexistent-key"

    # Force non-interactive mode by redirecting stdin from /dev/null
    assert_failure szecret ensure < /dev/null

    export SZECRET_PRIVATE_KEY="${saved_key}"
    pass "ensure fails non-interactive without key"
}

run_tests() {
    test_ensure_succeeds_when_key_exists
    test_ensure_fails_noninteractive_without_key
}

[[ "${BASH_SOURCE[0]}" == "${0}" ]] && run_tests