Skip to content

Commit 6c3b237

Browse files
authored
Prevent config tests from modifying real config (#1374)
1 parent e6e29dc commit 6c3b237

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

pkg/client/config_test.go

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"path/filepath"
1010
"testing"
1111

12+
"github.com/adrg/xdg"
1213
"github.com/stretchr/testify/assert"
1314
"github.com/stretchr/testify/require"
1415

@@ -83,6 +84,7 @@ func MockConfig(t *testing.T, cfg *config.Config) func() {
8384
// Save original XDG_CONFIG_HOME
8485
originalXDGConfigHome := os.Getenv("XDG_CONFIG_HOME")
8586
t.Setenv("XDG_CONFIG_HOME", tempDir)
87+
xdg.Reload()
8688

8789
// Create the config directory structure
8890
configDir := filepath.Join(tempDir, "toolhive")
@@ -97,6 +99,7 @@ func MockConfig(t *testing.T, cfg *config.Config) func() {
9799

98100
return func() {
99101
t.Setenv("XDG_CONFIG_HOME", originalXDGConfigHome)
102+
xdg.Reload()
100103
}
101104
}
102105

@@ -226,31 +229,32 @@ func TestSuccessfulClientConfigOperations(t *testing.T) {
226229
// Create test config files
227230
createTestConfigFiles(t, tempHome)
228231

229-
t.Run("FindAllConfiguredClients", func(t *testing.T) { //nolint:paralleltest // Uses environment variables
230-
testConfig := &config.Config{
231-
Secrets: config.Secrets{
232-
ProviderType: "encrypted",
233-
},
234-
Clients: config.Clients{
235-
RegisteredClients: []string{
236-
string(VSCode),
237-
string(VSCodeInsider),
238-
string(Cursor),
239-
string(RooCode),
240-
string(ClaudeCode),
241-
string(Cline),
242-
string(AmpCli),
243-
string(AmpVSCode),
244-
string(AmpCursor),
245-
string(AmpVSCodeInsider),
246-
string(AmpWindsurf),
247-
},
232+
// Set up config for all sub-tests
233+
testConfig := &config.Config{
234+
Secrets: config.Secrets{
235+
ProviderType: "encrypted",
236+
},
237+
Clients: config.Clients{
238+
RegisteredClients: []string{
239+
string(VSCode),
240+
string(VSCodeInsider),
241+
string(Cursor),
242+
string(RooCode),
243+
string(ClaudeCode),
244+
string(Cline),
245+
string(AmpCli),
246+
string(AmpVSCode),
247+
string(AmpCursor),
248+
string(AmpVSCodeInsider),
249+
string(AmpWindsurf),
248250
},
249-
}
251+
},
252+
}
250253

251-
cleanup := MockConfig(t, testConfig)
252-
defer cleanup()
254+
cleanup := MockConfig(t, testConfig)
255+
defer cleanup()
253256

257+
t.Run("FindAllConfiguredClients", func(t *testing.T) { //nolint:paralleltest // Uses environment variables
254258
configs, err := FindRegisteredClientConfigs()
255259
require.NoError(t, err)
256260
assert.Len(t, configs, len(supportedClientIntegrations), "Should find all mock client configs")

0 commit comments

Comments
 (0)