Skip to content

Commit a64aa65

Browse files
Wei WengWei Weng
authored andcommitted
consolidate test time constants
Signed-off-by: Wei Weng <[email protected]>
1 parent d9d053a commit a64aa65

File tree

4 files changed

+27
-58
lines changed

4 files changed

+27
-58
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
## Repository upload token - get it from codecov.io. Required only for private repositories
5656
token: ${{ secrets.CODECOV_TOKEN }}
5757
## Comma-separated list of files to upload
58-
files: ./it-coverage.xml;./ut-coverage.xml
58+
files: ./ut-coverage.xml
5959

6060
e2e-tests:
6161
strategy:

test/e2e/fleet_guard_rail_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
placementv1beta1 "github.com/kubefleet-dev/kubefleet/apis/placement/v1beta1"
3838
"github.com/kubefleet-dev/kubefleet/pkg/utils"
3939
"github.com/kubefleet-dev/kubefleet/pkg/webhook/validation"
40-
testutils "github.com/kubefleet-dev/kubefleet/test/utils"
4140

4241
fleetnetworkingv1alpha1 "go.goms.io/fleet-networking/api/v1alpha1"
4342
)
@@ -720,7 +719,7 @@ var _ = Describe("fleet guard rail for UPDATE work operations, in fleet prefixed
720719
return err
721720
}
722721
return checkIfStatusErrorWithMessage(err, fmt.Sprintf(validation.ResourceDeniedFormat, testUser, utils.GenerateGroupString(testGroups), admissionv1.Update, &workGVK, "status", types.NamespacedName{Name: w.Name, Namespace: w.Namespace}))
723-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
722+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
724723
})
725724

726725
It("should deny DELETE work operation for user not in MC identity", func() {

test/e2e/webhook_test.go

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
clusterv1beta1 "github.com/kubefleet-dev/kubefleet/apis/cluster/v1beta1"
3535
placementv1beta1 "github.com/kubefleet-dev/kubefleet/apis/placement/v1beta1"
3636
"github.com/kubefleet-dev/kubefleet/pkg/utils/defaulter"
37-
testutils "github.com/kubefleet-dev/kubefleet/test/utils"
3837
)
3938

4039
var _ = Describe("webhook tests for CRP CREATE operations", func() {
@@ -80,7 +79,7 @@ var _ = Describe("webhook tests for CRP CREATE operations", func() {
8079
g.Expect(statusErr.ErrStatus.Message).Should(MatchRegexp("cluster names cannot be empty for policy type"))
8180
g.Expect(statusErr.ErrStatus.Message).Should(MatchRegexp("number of clusters must be nil for policy type PickFixed"))
8281
return nil
83-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
82+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
8483
})
8584

8685
It("should deny create on CRP with invalid placement policy for PickN", func() {
@@ -127,7 +126,7 @@ var _ = Describe("webhook tests for CRP CREATE operations", func() {
127126
g.Expect(statusErr.ErrStatus.Message).Should(MatchRegexp("unknown unsatisfiable type random-type"))
128127
g.Expect(statusErr.ErrStatus.Message).Should(MatchRegexp("number of cluster cannot be nil for policy type PickN"))
129128
return nil
130-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
129+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
131130
})
132131

133132
It("should deny create CRP with invalid GVK", func() {
@@ -157,7 +156,7 @@ var _ = Describe("webhook tests for CRP CREATE operations", func() {
157156
g.Expect(errors.As(err, &statusErr)).To(BeTrue(), fmt.Sprintf("Create CRP call produced error %s. Error type wanted is %s.", reflect.TypeOf(err), reflect.TypeOf(&k8sErrors.StatusError{})))
158157
g.Expect(statusErr.ErrStatus.Message).Should(MatchRegexp(regexp.QuoteMeta("failed to get GVR of the selector")))
159158
return nil
160-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
159+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
161160
})
162161

163162
It("should deny create CRP with namespaced resource selected", func() {
@@ -187,7 +186,7 @@ var _ = Describe("webhook tests for CRP CREATE operations", func() {
187186
g.Expect(errors.As(err, &statusErr)).To(BeTrue(), fmt.Sprintf("Create CRP call produced error %s. Error type wanted is %s.", reflect.TypeOf(err), reflect.TypeOf(&k8sErrors.StatusError{})))
188187
g.Expect(statusErr.ErrStatus.Message).Should(MatchRegexp(regexp.QuoteMeta("the resource is not found in schema (please retry) or it is not a cluster scoped resource")))
189188
return nil
190-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
189+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
191190
})
192191
})
193192

@@ -228,7 +227,7 @@ var _ = Describe("webhook tests for CRP CREATE operations", func() {
228227
g.Expect(hubClient.Get(ctx, types.NamespacedName{Name: crpName}, &createdCRP)).Should(Succeed(), "Failed to get CRP %s", crpName)
229228
g.Expect(createdCRP.Spec.Policy).To(Equal(&placementv1beta1.PlacementPolicy{PlacementType: placementv1beta1.PickAllPlacementType}), "CRP should have default policy type PickAll")
230229
return nil
231-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
230+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
232231
})
233232

234233
It("should allow create CRP with TopologySpreadConstraints & Tolerations fields and update fields with default values", func() {
@@ -289,7 +288,7 @@ var _ = Describe("webhook tests for CRP CREATE operations", func() {
289288
},
290289
}), "CRP should have default tolerations fields")
291290
return nil
292-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
291+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
293292
})
294293

295294
It("should allow create CRP with nil strategy and update fields with default values", func() {
@@ -325,7 +324,7 @@ var _ = Describe("webhook tests for CRP CREATE operations", func() {
325324
},
326325
}), "CRP should have default strategy type RollingUpdate with default values")
327326
return nil
328-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
327+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
329328
})
330329

331330
It("should allow create CRP with nil revision history limit and update fields with default values", func() {
@@ -358,7 +357,7 @@ var _ = Describe("webhook tests for CRP CREATE operations", func() {
358357
g.Expect(hubClient.Get(ctx, types.NamespacedName{Name: crpName}, &createdCRP)).Should(Succeed(), "Failed to get CRP %s", crpName)
359358
g.Expect(*createdCRP.Spec.RevisionHistoryLimit).To(Equal(int32(defaulter.DefaultRevisionHistoryLimitValue)), "CRP should have default revision history limit value")
360359
return nil
361-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
360+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
362361
})
363362

364363
It("should allow create CRP with nil serverside apply config and update fields with default values", func() {
@@ -396,7 +395,7 @@ var _ = Describe("webhook tests for CRP CREATE operations", func() {
396395
ForceConflicts: false,
397396
}), "CRP should have default serverside apply config")
398397
return nil
399-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
398+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
400399
})
401400
})
402401
})
@@ -441,7 +440,7 @@ var _ = Describe("webhook tests for CRP UPDATE operations", Ordered, func() {
441440
g.Expect(errors.As(err, &statusErr)).To(BeTrue(), fmt.Sprintf("Update CRP call produced error %s. Error type wanted is %s.", reflect.TypeOf(err), reflect.TypeOf(&k8sErrors.StatusError{})))
442441
g.Expect(statusErr.ErrStatus.Message).Should(MatchRegexp("the labelSelector and name fields are mutually exclusive"))
443442
return nil
444-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
443+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
445444
})
446445

447446
It("should deny update on CRP with invalid placement policy for PickAll", func() {
@@ -483,7 +482,7 @@ var _ = Describe("webhook tests for CRP UPDATE operations", Ordered, func() {
483482
g.Expect(statusErr.ErrStatus.Message).Should(MatchRegexp(regexp.QuoteMeta(fmt.Sprintf("the labelSelector in cluster selector %+v is invalid:", crp.Spec.Policy.Affinity.ClusterAffinity.RequiredDuringSchedulingIgnoredDuringExecution.ClusterSelectorTerms[0].LabelSelector))))
484483
g.Expect(statusErr.ErrStatus.Message).Should(MatchRegexp("topology spread constraints needs to be empty for policy type PickAll"))
485484
return nil
486-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
485+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
487486
})
488487

489488
It("should deny update on CRP with placement policy type update", func() {
@@ -503,7 +502,7 @@ var _ = Describe("webhook tests for CRP UPDATE operations", Ordered, func() {
503502
g.Expect(errors.As(err, &statusErr)).To(BeTrue(), fmt.Sprintf("Update CRP call produced error %s. Error type wanted is %s.", reflect.TypeOf(err), reflect.TypeOf(&k8sErrors.StatusError{})))
504503
g.Expect(statusErr.ErrStatus.Message).Should(MatchRegexp("placement type is immutable"))
505504
return nil
506-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
505+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
507506
})
508507
})
509508

@@ -541,7 +540,7 @@ var _ = Describe("webhook tests for CRP UPDATE operations", Ordered, func() {
541540
g.Expect(hubClient.Get(ctx, types.NamespacedName{Name: crpName}, &updatedCRP)).Should(Succeed(), "Failed to get CRP %s", crpName)
542541
g.Expect(updatedCRP.Spec.Policy).To(Equal(&placementv1beta1.PlacementPolicy{PlacementType: placementv1beta1.PickAllPlacementType}), "CRP should have default policy type PickAll")
543542
return nil
544-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
543+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
545544
})
546545

547546
It("should allow update CRP with empty strategy and update fields with default values", func() {
@@ -568,7 +567,7 @@ var _ = Describe("webhook tests for CRP UPDATE operations", Ordered, func() {
568567
},
569568
}), "CRP should have default strategy type RollingUpdate with default values")
570569
return nil
571-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
570+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
572571
})
573572

574573
It("should allow update CRP with nil revision history limit and update fields with default values", func() {
@@ -582,7 +581,7 @@ var _ = Describe("webhook tests for CRP UPDATE operations", Ordered, func() {
582581
g.Expect(hubClient.Get(ctx, types.NamespacedName{Name: crpName}, &updatedCRP)).Should(Succeed(), "Failed to get CRP %s", crpName)
583582
g.Expect(*createdCRP.Spec.RevisionHistoryLimit).To(Equal(int32(defaulter.DefaultRevisionHistoryLimitValue)), "CRP should have default revision history limit value")
584583
return nil
585-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
584+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
586585
})
587586

588587
It("should allow update CRP with nil serverside apply config and update fields with default values", func() {
@@ -602,7 +601,7 @@ var _ = Describe("webhook tests for CRP UPDATE operations", Ordered, func() {
602601
ForceConflicts: false,
603602
}), "CRP should have default serverside apply config")
604603
return nil
605-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
604+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
606605
})
607606
})
608607

@@ -668,7 +667,7 @@ var _ = Describe("webhook tests for CRP UPDATE operations", Ordered, func() {
668667
},
669668
}), "CRP should have default tolerations fields")
670669
return nil
671-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
670+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
672671
})
673672
})
674673
})
@@ -731,7 +730,7 @@ var _ = Describe("webhook tests for CRP tolerations", Ordered, func() {
731730
g.Expect(errors.As(err, &statusErr)).To(BeTrue(), fmt.Sprintf("Update CRP call produced error %s. Error type wanted is %s.", reflect.TypeOf(err), reflect.TypeOf(&k8sErrors.StatusError{})))
732731
g.Expect(statusErr.ErrStatus.Message).Should(MatchRegexp(fmt.Sprintf("invalid toleration %+v: %s", invalidToleration, "toleration key cannot be empty, when operator is Equal")))
733732
return nil
734-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
733+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
735734
})
736735

737736
It("should deny update on CRP with update to existing toleration", func() {
@@ -760,7 +759,7 @@ var _ = Describe("webhook tests for CRP tolerations", Ordered, func() {
760759
g.Expect(errors.As(err, &statusErr)).To(BeTrue(), fmt.Sprintf("Update CRP call produced error %s. Error type wanted is %s.", reflect.TypeOf(err), reflect.TypeOf(&k8sErrors.StatusError{})))
761760
g.Expect(statusErr.ErrStatus.Message).Should(MatchRegexp("tolerations have been updated/deleted, only additions to tolerations are allowed"))
762761
return nil
763-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
762+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
764763
})
765764

766765
It("should allow update on CRP with adding a new toleration", func() {
@@ -775,7 +774,7 @@ var _ = Describe("webhook tests for CRP tolerations", Ordered, func() {
775774
}
776775
crp.Spec.Policy.Tolerations = append(crp.Spec.Policy.Tolerations, newToleration)
777776
return hubClient.Update(ctx, &crp)
778-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
777+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
779778
})
780779
})
781780

@@ -808,7 +807,7 @@ var _ = Describe("webhook tests for MC taints", Ordered, func() {
808807
g.Expect(errors.As(err, &statusErr)).To(BeTrue(), fmt.Sprintf("Update MC call produced error %s. Error type wanted is %s.", reflect.TypeOf(err), reflect.TypeOf(&k8sErrors.StatusError{})))
809808
g.Expect(statusErr.ErrStatus.Message).Should(MatchRegexp("name part must consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character"))
810809
return nil
811-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
810+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
812811
})
813812
})
814813

@@ -1169,7 +1168,7 @@ var _ = Describe("webhook tests for CRO UPDATE operations", Ordered, func() {
11691168
Expect(statusErr.Status().Message).Should(MatchRegexp(fmt.Sprintf("resource selector %+v already exists, and must be unique", cro.Spec.ClusterResourceSelectors[0])))
11701169
Expect(statusErr.Status().Message).Should(MatchRegexp(regexp.QuoteMeta(fmt.Sprintf("resource name is required for resource selection %+v", invalidSelector1))))
11711170
return nil
1172-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
1171+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
11731172
})
11741173

11751174
It("should deny update CRO for invalid cluster resource override", func() {
@@ -1248,7 +1247,7 @@ var _ = Describe("webhook tests for CRO UPDATE operations", Ordered, func() {
12481247
Expect(statusErr.Status().Message).Should(MatchRegexp("cannot override typeMeta fields"))
12491248
Expect(statusErr.Status().Message).Should(MatchRegexp("path cannot be empty"))
12501249
return nil
1251-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
1250+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
12521251
})
12531252
})
12541253

@@ -1591,7 +1590,7 @@ var _ = Describe("webhook tests for ResourceOverride UPDATE operations", Ordered
15911590
Expect(errors.As(err, &statusErr)).To(BeTrue(), fmt.Sprintf("Update RO call produced error %s. Error type wanted is %s.", reflect.TypeOf(err), reflect.TypeOf(&k8sErrors.StatusError{})))
15921591
Expect(statusErr.Status().Message).Should(MatchRegexp(fmt.Sprintf("resource selector %+v already exists, and must be unique", selector)))
15931592
return nil
1594-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
1593+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
15951594
})
15961595

15971596
It("should deny update RO with invalid resource override", func() {
@@ -1675,6 +1674,6 @@ var _ = Describe("webhook tests for ResourceOverride UPDATE operations", Ordered
16751674
Expect(statusErr.Status().Message).Should(MatchRegexp("path cannot contain empty string"))
16761675
Expect(statusErr.Status().Message).Should(MatchRegexp("cannot override metadata fields except annotations and labels"))
16771676
return nil
1678-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
1677+
}, eventuallyDuration, eventuallyInterval).Should(Succeed())
16791678
})
16801679
})

test/utils/helper.go

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)