Fix unit tests by unsetting VirtOperatorImageEnvName in AfterEach
@@ -151,15 +151,15 @@ type KubeVirtTestData struct {
mockEnvVarManager util.EnvVarManager
}
-var mockEnvVarManager = &util.EnvVarManagerMock{}
-
func (k *KubeVirtTestData) BeforeTest() {
- k.mockEnvVarManager = mockEnvVarManager
+ k.mockEnvVarManager = &util.EnvVarManagerMock{}
err := k.mockEnvVarManager.Setenv(util.OldOperatorImageEnvName, fmt.Sprintf("%s/virt-operator:%s", "someregistry", "v9.9.9"))
Expect(err).NotTo(HaveOccurred())
+ util.DefaultEnvVarManager = k.mockEnvVarManager
+
k.defaultConfig = k.getConfig("", "")
k.totalAdds = 0
@@ -349,6 +349,8 @@ func (k *KubeVirtTestData) BeforeTest() {
func (k *KubeVirtTestData) AfterTest() {
close(k.stop)
+ util.DefaultEnvVarManager = nil
+
// Ensure that we add checks for expected events to every test
Expect(k.recorder.Events).To(BeEmpty())
}
@@ -1670,10 +1672,6 @@ func (k *KubeVirtTestData) getConfig(registry, version string) *util.KubeVirtDep
var _ = Describe("KubeVirt Operator", func() {
- BeforeEach(func() {
- util.DefaultEnvVarManager = mockEnvVarManager
- })
-
Context("On valid KubeVirt object", func() {
It("Should not patch kubevirt namespace when labels are already defined", func() {
