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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
#!/usr/bin/env bats
load _test_base
FIRST_FILE="$TEST_DEFAULT_FILENAME"
SECOND_FILE="$TEST_SECOND_FILENAME"
function setup {
install_fixture_key "$TEST_DEFAULT_USER"
set_state_initial
set_state_git
set_state_secret_init
set_state_secret_tell "$TEST_DEFAULT_USER"
set_state_secret_add "$FIRST_FILE" "somecontent"
set_state_secret_add "$SECOND_FILE" "somecontent2"
set_state_secret_hide
}
function teardown {
# This also needs to be cleaned:
rm "$FIRST_FILE" "$SECOND_FILE"
uninstall_fixture_key "$TEST_DEFAULT_USER"
unset_current_state
}
function _secret_files_exists {
echo "$(find . -type f -name "*.$SECRETS_EXTENSION" \
-print0 2>/dev/null | grep -q .; echo "$?")"
}
@test "run 'clean' normally" {
run git secret clean
[ "$status" -eq 0 ]
# There must be no .secret files:
[ "$(_secret_files_exists)" -ne 0 ]
}
@test "run 'clean' with extra filename" {
run git secret clean extra_filename
[ "$status" -ne 0 ]
}
@test "run 'clean' with bad arg" {
run git secret clean -Z
[ "$status" -ne 0 ]
}
@test "run 'clean' with '-v'" {
run git secret clean -v
[ "$status" -eq 0 ]
# There must be no .secret files:
[ "$(_secret_files_exists)" -ne 0 ]
local first_filename
local second_filename
first_filename=$(_get_encrypted_filename "$FIRST_FILE")
second_filename=$(_get_encrypted_filename "$SECOND_FILE")
# Output must be verbose:
[[ "$output" == *"deleted"* ]]
[[ "$output" == *"$first_filename"* ]]
[[ "$output" == *"$second_filename"* ]]
}
# this test is like above, but uses SECRETS_VERBOSE env var
@test "run 'clean' with 'SECRETS_VERBOSE=1'" {
SECRETS_VERBOSE=1 run git secret clean
[ "$status" -eq 0 ]
# Output must be verbose:
[[ "$output" == *"deleted:"* ]]
}
# this test is like above, but sets SECRETS_VERBOSE env var to 0
# and expected non-verbose output
@test "run 'clean' with 'SECRETS_VERBOSE=0'" {
SECRETS_VERBOSE=0 run git secret clean
[ "$status" -eq 0 ]
# Output must not be verbose:
[[ "$output" != *"cleaning"* ]]
}
|