Skip to content

Commit 8ead034

Browse files
committed
test_helper: make test setup more hermetic
When running tests locally outside of a container (e.g. git clone git-secrets; make test), if a user is already using git-secrets by default in their system config and default gitdir template, tests which expect not to have git-secrets installed will fail. Instead, let's remove all hooks when we create a directory without the testbench's template and ignore the system config which may contain patterns that conflict with the testbench.
1 parent 5e28df3 commit 8ead034

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Diff for: test/test_helper.bash

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/bin/bash
2+
# Disallow any system-level git-secret pattern configs
3+
export GIT_CONFIG_NOSYSTEM="true"
24
export TEST_REPO="$BATS_TMPDIR/test-repo"
35
export TEMP_HOME="$BATS_TMPDIR/home"
46
export TEMPLATE_DIR="${BATS_TMPDIR}/template"
@@ -31,6 +33,9 @@ setup_repo() {
3133
mkdir -p $TEST_REPO
3234
cd $TEST_REPO
3335
git init
36+
# Uninstall any hooks present in the system template which could interfere
37+
# with git-secrets
38+
rm -fr .git/hooks/*
3439
git config --local --add secrets.patterns '@todo'
3540
git config --local --add secrets.patterns 'forbidden|me'
3641
git config --local --add secrets.patterns '#hash'

0 commit comments

Comments
 (0)