Skip to content

Commit 661b47d

Browse files
committed
Reset fakeAPI to avoid polluting it
1 parent 826015c commit 661b47d

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

cloud/linode/fake_linode_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ func newFake(t *testing.T) *fakeAPI {
4242
}
4343
}
4444

45+
func (f *fakeAPI) Reset() {
46+
*f = *newFake(f.t)
47+
}
48+
4549
func (f *fakeAPI) recordRequest(r *http.Request) {
4650
bodyBytes, _ := ioutil.ReadAll(r.Body)
4751
r.Body.Close()

cloud/linode/loadbalancers_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func TestCCMLoadBalancers(t *testing.T) {
167167
f: testMakeLoadBalancerStatus,
168168
},
169169
{
170-
name: "Cleanup does not all the API unless Service annotated",
170+
name: "Cleanup does not call the API unless Service annotated",
171171
f: testCleanupDoesntCall,
172172
},
173173
}
@@ -1467,6 +1467,7 @@ func testCleanupDoesntCall(t *testing.T, client *linodego.Client, fakeAPI *fakeA
14671467
svcAnn.Status.LoadBalancer = *makeLoadBalancerStatus(svc, nb)
14681468
lb := &loadbalancers{client, "us-west", nil}
14691469

1470+
fakeAPI.Reset()
14701471
t.Run("non-annotated service shouldn't call the API during cleanup", func(t *testing.T) {
14711472
if err := lb.cleanupOldNodeBalancer(context.TODO(), svc); err != nil {
14721473
t.Fatal(err)
@@ -1476,7 +1477,7 @@ func testCleanupDoesntCall(t *testing.T, client *linodego.Client, fakeAPI *fakeA
14761477
}
14771478
})
14781479

1479-
// TODO(okokes): note that we're polluting fakeAPI between these subtests (not an issue per-se here, but not ideal)
1480+
fakeAPI.Reset()
14801481
t.Run("annotated service calls the API to load said NB", func(t *testing.T) {
14811482
if err := lb.cleanupOldNodeBalancer(context.TODO(), svcAnn); err != nil {
14821483
t.Fatal(err)

0 commit comments

Comments
 (0)