Skip to content

Commit 8b8563a

Browse files
Merge pull request #343 from vikaschoudhary16/fix-unit-test-flake
Fix flaking unit test TestOperatorSync_NoOp
2 parents 7d5494a + 866f203 commit 8b8563a

File tree

1 file changed

+3
-31
lines changed

1 file changed

+3
-31
lines changed

pkg/operator/operator_test.go

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package operator
22

33
import (
4-
"encoding/json"
54
"fmt"
6-
"io/ioutil"
7-
"os"
8-
"path/filepath"
95
"testing"
106
"time"
117

@@ -127,25 +123,6 @@ func TestOperatorSync_NoOp(t *testing.T) {
127123
expectedNoop: true,
128124
},
129125
}
130-
131-
tempDir, err := ioutil.TempDir("", "TestOperatorSync")
132-
if err != nil {
133-
t.Fatalf("could not create the temp dir: %v", err)
134-
}
135-
defer os.RemoveAll(tempDir)
136-
137-
images := Images{
138-
MachineAPIOperator: "test-mao",
139-
}
140-
imagesAsJSON, err := json.Marshal(images)
141-
if err != nil {
142-
t.Fatalf("failed to marshal images: %v", err)
143-
}
144-
imagesFilePath := filepath.Join(tempDir, "test-images.json")
145-
if err := ioutil.WriteFile(imagesFilePath, imagesAsJSON, 0666); err != nil {
146-
t.Fatalf("could not write the images file: %v", err)
147-
}
148-
149126
for _, tc := range cases {
150127
t.Run(string(tc.platform), func(t *testing.T) {
151128
infra := &v1.Infrastructure{
@@ -158,15 +135,10 @@ func TestOperatorSync_NoOp(t *testing.T) {
158135
}
159136

160137
stopCh := make(<-chan struct{})
161-
optr := newFakeOperator(nil, []runtime.Object{infra}, stopCh)
162-
optr.imagesFile = imagesFilePath
163-
164-
err = optr.sync("test-key")
165-
if !assert.NoError(t, err, "unexpected sync failure") {
166-
t.Fatal()
167-
}
138+
optr := newFakeOperator(nil, []runtime.Object{newFeatureGate(v1.TechPreviewNoUpgrade), infra}, stopCh)
139+
go optr.Run(2, stopCh)
168140

169-
err = wait.PollImmediate(1*time.Second, 5*time.Second, func() (bool, error) {
141+
err := wait.PollImmediate(1*time.Second, 5*time.Second, func() (bool, error) {
170142
_, err := optr.deployLister.Deployments(targetNamespace).Get(deploymentName)
171143
if err != nil {
172144
t.Logf("Failed to get %q deployment: %v", deploymentName, err)

0 commit comments

Comments
 (0)