Skip to content

Commit 5b857c3

Browse files
committed
fix unit tests
1 parent 19c972d commit 5b857c3

File tree

3 files changed

+14
-54
lines changed

3 files changed

+14
-54
lines changed

internal/mode/static/state/change_processor.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,22 @@ func NewChangeProcessorImpl(cfg ChangeProcessorConfig) *ChangeProcessorImpl {
126126
{
127127
gvk: extractGVK(&v1.GatewayClass{}),
128128
store: newObjectStoreMapAdapter(clusterStore.GatewayClasses),
129-
predicate: nil,
129+
predicate: generationChangedPredicate{},
130130
},
131131
{
132132
gvk: extractGVK(&v1.Gateway{}),
133133
store: newObjectStoreMapAdapter(clusterStore.Gateways),
134-
predicate: nil,
134+
predicate: generationChangedPredicate{},
135135
},
136136
{
137137
gvk: extractGVK(&v1.HTTPRoute{}),
138138
store: newObjectStoreMapAdapter(clusterStore.HTTPRoutes),
139-
predicate: nil,
139+
predicate: generationChangedPredicate{},
140140
},
141141
{
142142
gvk: extractGVK(&v1beta1.ReferenceGrant{}),
143143
store: newObjectStoreMapAdapter(clusterStore.ReferenceGrants),
144-
predicate: nil,
144+
predicate: generationChangedPredicate{},
145145
},
146146
{
147147
gvk: extractGVK(&apiv1.Namespace{}),

internal/mode/static/state/change_processor_test.go

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -703,17 +703,6 @@ var _ = Describe("ChangeProcessor", func() {
703703
Expect(helpers.Diff(expGraph, graphCfg)).To(BeEmpty())
704704
})
705705
})
706-
When("the first HTTPRoute without a generation changed is processed", func() {
707-
It("returns nil graph", func() {
708-
hr1UpdatedSameGen := hr1.DeepCopy()
709-
// hr1UpdatedSameGen.Generation has not been changed
710-
processor.CaptureUpsertChange(hr1UpdatedSameGen)
711-
712-
changed, graphCfg := processor.Process()
713-
Expect(changed).To(BeFalse())
714-
Expect(graphCfg).To(BeNil())
715-
})
716-
})
717706
When("the first HTTPRoute update with a generation changed is processed", func() {
718707
It("returns populated graph", func() {
719708
processor.CaptureUpsertChange(hr1Updated)
@@ -733,17 +722,6 @@ var _ = Describe("ChangeProcessor", func() {
733722
},
734723
)
735724
})
736-
When("the first Gateway update without generation changed is processed", func() {
737-
It("returns nil graph", func() {
738-
gwUpdatedSameGen := gw1.DeepCopy()
739-
// gwUpdatedSameGen.Generation has not been changed
740-
processor.CaptureUpsertChange(gwUpdatedSameGen)
741-
742-
changed, graphCfg := processor.Process()
743-
Expect(changed).To(BeFalse())
744-
Expect(graphCfg).To(BeNil())
745-
})
746-
})
747725
When("the first Gateway update with a generation changed is processed", func() {
748726
It("returns populated graph", func() {
749727
processor.CaptureUpsertChange(gw1Updated)
@@ -758,17 +736,6 @@ var _ = Describe("ChangeProcessor", func() {
758736
Expect(helpers.Diff(expGraph, graphCfg)).To(BeEmpty())
759737
})
760738
})
761-
When("the GatewayClass update without generation change is processed", func() {
762-
It("returns nil graph", func() {
763-
gcUpdatedSameGen := gc.DeepCopy()
764-
// gcUpdatedSameGen.Generation has not been changed
765-
processor.CaptureUpsertChange(gcUpdatedSameGen)
766-
767-
changed, graphCfg := processor.Process()
768-
Expect(changed).To(BeFalse())
769-
Expect(graphCfg).To(BeNil())
770-
})
771-
})
772739
When("the GatewayClass update with generation change is processed", func() {
773740
It("returns populated graph", func() {
774741
processor.CaptureUpsertChange(gcUpdated)
@@ -1590,15 +1557,6 @@ var _ = Describe("ChangeProcessor", func() {
15901557
changed, _ := processor.Process()
15911558
Expect(changed).To(BeTrue())
15921559
})
1593-
It("should report not changed after multiple Upserts of the resource with same generation", func() {
1594-
processor.CaptureUpsertChange(gc)
1595-
processor.CaptureUpsertChange(gw1)
1596-
processor.CaptureUpsertChange(hr1)
1597-
processor.CaptureUpsertChange(rg1)
1598-
1599-
changed, _ := processor.Process()
1600-
Expect(changed).To(BeFalse())
1601-
})
16021560
When("a upsert of updated resources is followed by an upsert of the same generation", func() {
16031561
It("should report changed", func() {
16041562
// these are changing changes
@@ -1737,14 +1695,7 @@ var _ = Describe("ChangeProcessor", func() {
17371695
Expect(changed).To(BeTrue())
17381696
})
17391697

1740-
It("should report not changed after multiple Upserts of unrelated and unchanged resources", func() {
1741-
// unchanged Gateway API resources
1742-
fakeRelationshipCapturer.ExistsReturns(false)
1743-
processor.CaptureUpsertChange(gc)
1744-
processor.CaptureUpsertChange(gw1)
1745-
processor.CaptureUpsertChange(hr1)
1746-
processor.CaptureUpsertChange(rg1)
1747-
1698+
It("should report not changed after multiple Upserts of unrelated resources", func() {
17481699
// unrelated Kubernetes API resources
17491700
fakeRelationshipCapturer.ExistsReturns(false)
17501701
processor.CaptureUpsertChange(svc)

internal/mode/static/state/changed_predicate.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ func (f funcPredicate) delete(object client.Object) bool {
2424
return f.stateChanged(object)
2525
}
2626

27+
// generationChangedPredicate implements stateChangedPredicate based on the generation of the object.
28+
// This predicate will return true on upsert if the object's generation has changed.
29+
// It always returns true on delete.
30+
type generationChangedPredicate struct{}
31+
32+
func (generationChangedPredicate) delete(_ client.Object) bool { return true }
33+
34+
func (generationChangedPredicate) upsert(_, _ client.Object) bool { return true }
35+
2736
// annotationChangedPredicate implements stateChangedPredicate based on the value of the annotation provided.
2837
// This predicate will return true on upsert if the annotation's value has changed.
2938
// It always returns true on delete.

0 commit comments

Comments
 (0)