#!/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