MCPcopy
hub / github.com/docker/compose / unsetEnv

Function unsetEnv

cmd/compose/hooks_test.go:306–320  ·  view source on GitHub ↗

unsetEnv removes an env var for the lifetime of the test, restoring its prior state on cleanup. t.Setenv("", "") is not equivalent to unset: compose-go's WithConfigFileEnv treats empty as a meaningful override.

(t *testing.T, key string)

Source from the content-addressed store, hash-verified

304// prior state on cleanup. t.Setenv("", "") is not equivalent to unset:
305// compose-go's WithConfigFileEnv treats empty as a meaningful override.
306func unsetEnv(t *testing.T, key string) {
307 t.Helper()
308 prev, had := os.LookupEnv(key)
309 if err := os.Unsetenv(key); err != nil {
310 t.Fatalf("unsetenv %s: %v", key, err)
311 }
312 t.Cleanup(func() {
313 if !had {
314 return
315 }
316 if err := os.Setenv(key, prev); err != nil {
317 t.Errorf("restore env %s: %v", key, err)
318 }
319 })
320}
321
322func mustWrite(t *testing.T, dir, name, content string) {
323 t.Helper()

Calls

no outgoing calls

Tested by

no test coverage detected