Skip to content

Commit 1ea54e2

Browse files
Sophclaude
andcommitted
test: mock the OS keyring in the cli package TestMain
The cli package's TestMain never routed go-keyring to its in-memory mock, unlike the auth subpackage. The default tokenstore backend is the real OS keychain, so any cli test that reaches a credential path without UseFileBackendForTesting — or runs in the window after such a test restores the global backend — would read the developer's real keychain and trigger a macOS unlock prompt during `mise run test:ci`. Call keyring.MockInit() once in TestMain so no cli test can touch the real keychain, mirroring cmd/entire/cli/auth's TestMain. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Entire-Checkpoint: eb9e9029effe
1 parent 3eeb08c commit 1ea54e2

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

cmd/entire/cli/global_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,18 @@ import (
77

88
"github.com/go-git/go-git/v6/x/plugin"
99
"github.com/go-git/go-git/v6/x/plugin/config"
10+
"github.com/zalando/go-keyring"
1011
)
1112

1213
func TestMain(m *testing.M) {
14+
// Route the OS keyring to an in-memory mock for the whole package. The
15+
// default tokenstore backend is the real OS keychain, so any test that
16+
// reaches a credential path without UseFileBackendForTesting — or in the
17+
// window after such a test restores the backend — would otherwise read the
18+
// developer's real keychain and trigger a macOS unlock prompt. Mirrors the
19+
// auth subpackage's TestMain.
20+
keyring.MockInit()
21+
1322
// Register a default ConfigSource so tests that call ConfigScoped
1423
// (directly or indirectly via Commit/CreateTag) don't fail with
1524
// "no config loader registered".

0 commit comments

Comments
 (0)