Skip to content

Commit

Permalink
Merge pull request #1186 from spidernet-io/fix-unit-test
Browse files Browse the repository at this point in the history
Fix gomonkey patch in `for range`
  • Loading branch information
weizhoublue authored Jan 30, 2024
2 parents 4d60470 + 91e8c72 commit fc39ed5
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions pkg/controller/egress_cluster_info/egress_cluster_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,15 @@ func Test_eciReconciler_Reconcile(t *testing.T) {
getReqFunc: mock_request_calico,
setReconciler: mock_eciReconciler_info_AutoDetect_PodCidrMode_calico,
patchFunc: mock_Reconciler_Reconcile_failed_Update,
expErr: false,
expRequeue: true,
},
}

builder := fake.NewClientBuilder()
builder.WithScheme(schema.GetScheme())

// objs = append(objs, egci)
// builder.WithObjects(objs...)
// builder.WithStatusSubresource(objs...)

r := &eciReconciler{
// mgr: mgr,
eci: new(egressv1.EgressClusterInfo),
log: logr.Logger{},
k8sPodCidr: make(map[string]egressv1.IPListPair),
Expand All @@ -93,13 +89,9 @@ func Test_eciReconciler_Reconcile(t *testing.T) {
tc.setReconciler(r)
}

patches := make([]gomonkey.Patches, 0)
if tc.patchFunc != nil {
patches := tc.patchFunc(r)
defer func() {
for _, p := range patches {
p.Reset()
}
}()
patches = tc.patchFunc(r)
}

req := tc.getReqFunc()
Expand All @@ -114,9 +106,12 @@ func Test_eciReconciler_Reconcile(t *testing.T) {
if tc.expRequeue {
assert.True(t, res.Requeue)
}

for _, p := range patches {
p.Reset()
}
})
}

}

func Test_eciReconciler_reconcileEgressClusterInfo(t *testing.T) {
Expand Down

0 comments on commit fc39ed5

Please sign in to comment.