Skip to content

Commit f87510d

Browse files
author
Kate Osborn
committed
Address issues with sort package and tests
1 parent 48f0c2d commit f87510d

File tree

5 files changed

+9
-14
lines changed

5 files changed

+9
-14
lines changed

internal/mode/static/sort/sort.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ func LessObjectMeta(meta1 *metav1.ObjectMeta, meta2 *metav1.ObjectMeta) bool {
1818
return meta1.CreationTimestamp.Before(&meta2.CreationTimestamp)
1919
}
2020

21-
// ClientObject compares two client.Objects and returns true if:
21+
// LessClientObject compares two client.Objects and returns true if:
2222
// - the first object was created first,
2323
// - the objects were created at the same time, or
2424
// - the first object's name appears first in alphabetical order.
25-
func ClientObject(obj1 client.Object, obj2 client.Object) bool {
25+
func LessClientObject(obj1 client.Object, obj2 client.Object) bool {
2626
create1 := obj1.GetCreationTimestamp()
2727
create2 := obj2.GetCreationTimestamp()
2828

internal/mode/static/sort/sort_test.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ func TestLessObjectMeta(t *testing.T) {
2929
meta2: &metav1.ObjectMeta{
3030
Namespace: "ns1",
3131
Name: "meta2",
32-
UID: "b",
3332
CreationTimestamp: later,
3433
},
3534
name: "first is less by timestamp",
@@ -92,7 +91,7 @@ func TestLessObjectMeta(t *testing.T) {
9291
}
9392
}
9493

95-
func TestClientObject(t *testing.T) {
94+
func TestLessClientObject(t *testing.T) {
9695
before := metav1.Now()
9796
later := metav1.NewTime(before.Add(1 * time.Second))
9897

@@ -115,7 +114,6 @@ func TestClientObject(t *testing.T) {
115114
ObjectMeta: metav1.ObjectMeta{
116115
Namespace: "ns1",
117116
Name: "obj2",
118-
UID: "b",
119117
CreationTimestamp: later,
120118
},
121119
},
@@ -133,8 +131,7 @@ func TestClientObject(t *testing.T) {
133131
obj2: &v1.Gateway{
134132
ObjectMeta: metav1.ObjectMeta{
135133
Namespace: "ns2",
136-
Name: "obj2",
137-
UID: "b",
134+
Name: "obj1",
138135
CreationTimestamp: before,
139136
},
140137
},
@@ -153,7 +150,6 @@ func TestClientObject(t *testing.T) {
153150
ObjectMeta: metav1.ObjectMeta{
154151
Namespace: "ns1",
155152
Name: "obj2",
156-
UID: "b",
157153
CreationTimestamp: before,
158154
},
159155
},
@@ -172,7 +168,6 @@ func TestClientObject(t *testing.T) {
172168
ObjectMeta: metav1.ObjectMeta{
173169
Namespace: "ns1",
174170
Name: "obj1",
175-
UID: "b",
176171
CreationTimestamp: before,
177172
},
178173
},
@@ -184,8 +179,8 @@ func TestClientObject(t *testing.T) {
184179
t.Run(test.name, func(t *testing.T) {
185180
g := NewWithT(t)
186181

187-
result := ClientObject(test.obj1, test.obj2)
188-
invertedResult := ClientObject(test.obj2, test.obj1)
182+
result := LessClientObject(test.obj1, test.obj2)
183+
invertedResult := LessClientObject(test.obj2, test.obj1)
189184

190185
g.Expect(result).To(Equal(test.expected))
191186
g.Expect(invertedResult).To(BeFalse())

internal/mode/static/state/graph/backend_refs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func findBackendTLSPolicyForService(
247247
for _, targetRef := range btp.Source.Spec.TargetRefs {
248248
if string(targetRef.Name) == refName && btpNs == refNs {
249249
if beTLSPolicy != nil {
250-
if sort.LessObjectMeta(&btp.Source.ObjectMeta, &beTLSPolicy.Source.ObjectMeta) {
250+
if sort.LessClientObject(btp.Source, beTLSPolicy.Source) {
251251
beTLSPolicy = btp
252252
}
253253
} else {

internal/mode/static/state/graph/gateway.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func processGateways(
7777
}
7878

7979
sort.Slice(referencedGws, func(i, j int) bool {
80-
return ngfsort.LessObjectMeta(&referencedGws[i].ObjectMeta, &referencedGws[j].ObjectMeta)
80+
return ngfsort.LessClientObject(referencedGws[i], referencedGws[j])
8181
})
8282

8383
ignoredGws := make(map[types.NamespacedName]*v1.Gateway)

internal/mode/static/state/graph/policies.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func markConflictedPolicies(policies map[PolicyKey]*Policy, validator validation
245245
// This will put them in priority-order.
246246
sort.Slice(
247247
policyList, func(i, j int) bool {
248-
return ngfsort.ClientObject(policyList[i].Source, policyList[j].Source)
248+
return ngfsort.LessClientObject(policyList[i].Source, policyList[j].Source)
249249
},
250250
)
251251

0 commit comments

Comments
 (0)