Skip to content

Commit b23dcbf

Browse files
committed
pkg/config: fix verify getDefaultEnv test flake
Do not use Default() in unit tests, that caches the config in a global var so it conflicts with other tests also calling it. Now only the Reload test should test that. The Default() call got broken by commit ee04b4f because now the test only unsets the env after the last Reload() call which should already use the actual default. Fixes: ee04b4f ("*_test.go: use t.TempDir, t.Setenv") Signed-off-by: Paul Holzinger <pholzing@redhat.com>
1 parent e6e162a commit b23dcbf

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

pkg/config/config_local_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ var _ = Describe("Config Local", func() {
390390
t.Setenv(containersConfEnv, "/dev/null")
391391

392392
// When
393-
config, err := Default()
393+
config, err := New(nil)
394394

395395
// Then
396396
gomega.Expect(err).ToNot(gomega.HaveOccurred())

pkg/config/config_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,15 @@ image_copy_tmp_dir="storage"`
748748
t := GinkgoT()
749749
// Default configuration
750750
defaultTestFile := "testdata/containers_default.conf"
751+
// Note this must be defined before the Setenv as cleanup happens LIFO
752+
// and Reload() must be called without the custom env to reset the default config
753+
DeferCleanup(func() {
754+
// Reload change back to default global configuration
755+
_, err := Reload()
756+
gomega.Expect(err).ToNot(gomega.HaveOccurred())
757+
})
751758
t.Setenv(containersConfEnv, defaultTestFile)
759+
752760
cfg, err := Default()
753761
gomega.Expect(err).ToNot(gomega.HaveOccurred())
754762

@@ -768,9 +776,6 @@ env=["foo=bar"]`
768776
expectNewEnv := []string{"foo=bar"}
769777
gomega.Expect(cfg.Containers.Env.Get()).To(gomega.Equal(expectOldEnv))
770778
gomega.Expect(newCfg.Containers.Env.Get()).To(gomega.Equal(expectNewEnv))
771-
// Reload change back to default global configuration
772-
_, err = Reload()
773-
gomega.Expect(err).ToNot(gomega.HaveOccurred())
774779
})
775780
})
776781

0 commit comments

Comments
 (0)