Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions internal/controller/state/graph/backend_refs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1664,9 +1664,6 @@ func TestFindBackendTLSPolicyForService(t *testing.T) {
},
}
}
oldestBtp := getBtp("oldest", oldCreationTimestamp)
newestBtp := getBtp("newest", newCreationTimestamp)
alphaFirstBtp := getBtp("alphabeticallyfirst", oldCreationTimestamp)

ref := gatewayv1.HTTPBackendRef{
BackendRef: gatewayv1.BackendRef{
Expand All @@ -1678,26 +1675,39 @@ func TestFindBackendTLSPolicyForService(t *testing.T) {
},
}

getBTPMap := func(nameAndTimestamp map[string]metav1.Time) map[types.NamespacedName]*BackendTLSPolicy {
m := make(map[types.NamespacedName]*BackendTLSPolicy, len(nameAndTimestamp))
for n, ts := range nameAndTimestamp {
btp := getBtp(n, ts)
m[client.ObjectKeyFromObject(btp.Source)] = btp
}
return m
}

tests := []struct {
name string
backendTLSPolicies map[types.NamespacedName]*BackendTLSPolicy
expectedBtpName string
}{
{
name: "oldest wins",
backendTLSPolicies: map[types.NamespacedName]*BackendTLSPolicy{
client.ObjectKeyFromObject(newestBtp.Source): newestBtp,
client.ObjectKeyFromObject(oldestBtp.Source): oldestBtp,
},
backendTLSPolicies: getBTPMap(
map[string]metav1.Time{
"newest": newCreationTimestamp,
"oldest": oldCreationTimestamp,
},
),
expectedBtpName: "oldest",
},
{
name: "alphabetically first wins",
backendTLSPolicies: map[types.NamespacedName]*BackendTLSPolicy{
client.ObjectKeyFromObject(oldestBtp.Source): oldestBtp,
client.ObjectKeyFromObject(alphaFirstBtp.Source): alphaFirstBtp,
client.ObjectKeyFromObject(newestBtp.Source): newestBtp,
},
backendTLSPolicies: getBTPMap(
map[string]metav1.Time{
"alphabeticallyfirst": oldCreationTimestamp,
"newest": newCreationTimestamp,
"oldest": oldCreationTimestamp,
},
),
expectedBtpName: "alphabeticallyfirst",
},
}
Expand Down
Loading