MCPcopy Create free account
hub / github.com/coder/agentapi / isolateViper

Function isolateViper

cmd/server/server_test.go:184–219  ·  view source on GitHub ↗

Test helper to isolate viper config between tests

(t *testing.T)

Source from the content-addressed store, hash-verified

182
183// Test helper to isolate viper config between tests
184func isolateViper(t *testing.T) {
185 // Save current state
186 oldConfig := viper.AllSettings()
187
188 // Reset viper
189 viper.Reset()
190
191 // Clear AGENTAPI_ env vars
192 var agentapiEnvs []string
193 for _, env := range os.Environ() {
194 if strings.HasPrefix(env, "AGENTAPI_") {
195 parts := strings.SplitN(env, "=", 2)
196 agentapiEnvs = append(agentapiEnvs, parts[0])
197 if err := os.Unsetenv(parts[0]); err != nil {
198 t.Fatalf("Failed to unset env var %s: %v", parts[0], err)
199 }
200 }
201 }
202
203 t.Cleanup(func() {
204 // Restore state
205 viper.Reset()
206 for key, value := range oldConfig {
207 viper.Set(key, value)
208 }
209
210 // Restore env vars
211 for _, key := range agentapiEnvs {
212 if val := os.Getenv(key); val != "" {
213 if err := os.Setenv(key, val); err != nil {
214 t.Fatalf("Failed to set env var %s: %v", key, err)
215 }
216 }
217 }
218 })
219}
220
221// Test configuration values via ServerCmd execution
222func TestServerCmd_AllArgs_Defaults(t *testing.T) {

Calls

no outgoing calls

Tested by

no test coverage detected