@@ -20,6 +20,7 @@ import (
2020 "strings"
2121 "testing"
2222
23+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324 v1 "sigs.k8s.io/gateway-api/apis/v1"
2425)
2526
@@ -245,3 +246,75 @@ func TestIsDNS1123Domain(t *testing.T) {
245246 })
246247 }
247248}
249+
250+ func TestGwRouteIsAccepted (t * testing.T ) {
251+ tests := []struct {
252+ desc string
253+ conditions []metav1.Condition
254+ currentGeneration int64
255+ want bool
256+ }{
257+ {
258+ desc : "accepted condition with matching generation" ,
259+ conditions : []metav1.Condition {
260+ {
261+ Type : string (v1 .RouteConditionAccepted ),
262+ Status : metav1 .ConditionTrue ,
263+ ObservedGeneration : 1 ,
264+ },
265+ },
266+ currentGeneration : 1 ,
267+ want : true ,
268+ },
269+ {
270+ desc : "accepted condition with different generation" ,
271+ conditions : []metav1.Condition {
272+ {
273+ Type : string (v1 .RouteConditionAccepted ),
274+ Status : metav1 .ConditionTrue ,
275+ ObservedGeneration : 1 ,
276+ },
277+ },
278+ currentGeneration : 2 ,
279+ want : false ,
280+ },
281+ {
282+ desc : "accepted condition with false status" ,
283+ conditions : []metav1.Condition {
284+ {
285+ Type : string (v1 .RouteConditionAccepted ),
286+ Status : metav1 .ConditionFalse ,
287+ ObservedGeneration : 1 ,
288+ },
289+ },
290+ currentGeneration : 1 ,
291+ want : false ,
292+ },
293+ {
294+ desc : "no accepted condition" ,
295+ conditions : []metav1.Condition {
296+ {
297+ Type : "OtherCondition" ,
298+ Status : metav1 .ConditionTrue ,
299+ ObservedGeneration : 1 ,
300+ },
301+ },
302+ currentGeneration : 1 ,
303+ want : false ,
304+ },
305+ {
306+ desc : "empty conditions" ,
307+ conditions : []metav1.Condition {},
308+ currentGeneration : 1 ,
309+ want : false ,
310+ },
311+ }
312+
313+ for _ , tt := range tests {
314+ t .Run (tt .desc , func (t * testing.T ) {
315+ if got := gwRouteIsAccepted (tt .conditions , tt .currentGeneration ); got != tt .want {
316+ t .Errorf ("gwRouteIsAccepted() = %v, want %v" , got , tt .want )
317+ }
318+ })
319+ }
320+ }
0 commit comments