Skip to content

Commit 5da5315

Browse files
Fix testing on Alpine (#1213)
1 parent 64e5b65 commit 5da5315

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

tests/_test_base.bash

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,10 @@ function stop_gpg_agent {
125125
'/gpg-agent/ { if ( $0 !~ "awk" ) { system("kill "$1) } }' >> "$TEST_OUTPUT_FILE" 2>&1
126126
else
127127
local ps_is_busybox
128-
ps_is_busybox=_exe_is_busybox 'ps'
128+
ps_is_busybox=$(_exe_is_busybox 'ps')
129129
if [[ $ps_is_busybox -eq '1' ]]; then
130-
echo '# git-secret: tests: not stopping gpg-agent on busybox' >&3
130+
# On Alpine/busybox, ps doesn't show command arguments, so use gpgconf instead
131+
gpgconf --homedir "$TEST_GPG_HOMEDIR" --kill gpg-agent >> "$TEST_OUTPUT_FILE" 2>&1 || true
131132
else
132133
ps -wx -U "$username" | gawk \
133134
'/gpg-agent --homedir/ { if ( $0 !~ "awk" ) { system("kill "$1) } }' >> "$TEST_OUTPUT_FILE" 2>&1
@@ -246,6 +247,12 @@ function remove_git_repository {
246247
function set_state_initial {
247248
cd "$BATS_TMPDIR" || exit 1
248249
rm -rf "${BATS_TMPDIR:?}/*"
250+
# Safety net: remove hidden dirs that may persist from a prior failed teardown.
251+
# The rm above is a no-op (glob inside double quotes is literal), so we must
252+
# explicitly clean up dot-dirs to prevent 'already initialized' errors.
253+
rm -rf "${BATS_TMPDIR:?}/${_SECRETS_DIR}"
254+
rm -rf "${BATS_TMPDIR:?}/.git"
255+
rm -rf "${BATS_TMPDIR:?}/.gitignore"
249256
}
250257

251258

tests/test_reveal.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function setup {
2222

2323

2424
function teardown {
25-
rm "$FILE_TO_HIDE"
25+
rm -f "$FILE_TO_HIDE"
2626

2727
uninstall_fixture_full_key "$TEST_DEFAULT_USER" "$FINGERPRINT"
2828
unset_current_state

tests/test_reveal_filename.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function setup {
2626

2727

2828
function teardown {
29-
rm "$FILE_TO_HIDE"
29+
rm -f "$FILE_TO_HIDE"
3030

3131
uninstall_fixture_full_key "$TEST_DEFAULT_USER" "$FINGERPRINT"
3232
unset_current_state

0 commit comments

Comments
 (0)