tests for remove

pull/10/head
sobolevn 8 years ago
parent bdc3dbda18
commit cd97ba1cc2

@ -16,7 +16,7 @@ This project is still under development. Current objectives:
- hooks: `pre-commit` to encrypt secret files
- static site for `gh-pages` build from manuals with `Jekyll` and `Ronn`
- plugin for `zsh`
- extra tests, tests for `git-secret-remove`
- extra tests
- precompiled distributions for `brew` and other package managers
- styleguide for bash (?)
- сygwin support (?)

@ -26,7 +26,7 @@ function _optional_clean {
_show_help_hide
;;
*)
v)
opt_string="$opt_string -$opt"
;;
esac

@ -1,7 +1,35 @@
#!/usr/bin/env bash
function _show_help_remove {
echo "usage: git secret remove [files..]"
echo "removes files from git-secret's index."
echo
echo " -c deletes existing real files."
exit 0
}
function remove {
OPTIND=1
local clean=0
while getopts "ch" opt; do
case "$opt" in
c)
clean=1
;;
h)
_show_help_remove
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
# validate if user exist:
_user_required
for item in $@; do
@ -10,9 +38,16 @@ function remove {
fi
_delete_line "$item" "$SECRETS_DIR_PATHS_MAPPING"
if [[ "$clean" == 1 ]]; then
local encrypted_filename=`_get_encrypted_filename "$item"`
rm -f "$encrypted_filename"
fi
done
local all=${@}
echo "removed from index."
echo "ensure that files: [$all] are now not ignored."
}

@ -0,0 +1 @@
print('fine!')

@ -0,0 +1,58 @@
#!/usr/bin/env bats
load _test_base
FIRST_FILE="file_to_hide1"
SECOND_FILE="file_to_hide2"
function setup {
install_fixture_full_key "$TEST_DEFAULT_USER"
set_state_git
set_state_secret_init
set_state_secret_tell "$TEST_DEFAULT_USER"
set_state_secret_add "$FIRST_FILE" "$FIRST_FILE"
set_state_secret_add "$SECOND_FILE" "$SECOND_FILE"
}
function teardown {
uninstall_fixture_full_key "$TEST_DEFAULT_USER"
unset_current_state
rm -f "$FIRST_FILE" "$SECOND_FILE"
}
@test "run 'remove' normally" {
git secret hide
run git secret remove "$SECOND_FILE"
[ "$status" -eq 0 ]
local mapping_contains=$(grep "$SECOND_FILE" "$SECRETS_DIR_PATHS_MAPPING"; echo $?)
[ "$mapping_contains" -eq 1 ]
local first_enctypted_file=`_get_encrypted_filename $FIRST_FILE`
local second_enctypted_file=`_get_encrypted_filename $SECOND_FILE`
[ -f "$first_enctypted_file" ]
[ -f "$second_enctypted_file" ]
}
@test "run 'remove -c'" {
git secret hide
run git secret remove -c "$SECOND_FILE"
[ "$status" -eq 0 ]
local mapping_contains=$(grep "$SECOND_FILE" "$SECRETS_DIR_PATHS_MAPPING"; echo $?)
[ "$mapping_contains" -eq 1 ]
local first_enctypted_file=`_get_encrypted_filename $FIRST_FILE`
local second_enctypted_file=`_get_encrypted_filename $SECOND_FILE`
[ -f "$first_enctypted_file" ]
[ ! -f "$second_enctypted_file" ]
}
Loading…
Cancel
Save