github.com/cilium/cilium@v1.16.2/operator/pkg/gateway-api/gatewayclass_status_test.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package gateway_api 5 6 import ( 7 "testing" 8 9 "github.com/google/go-cmp/cmp" 10 "github.com/google/go-cmp/cmp/cmpopts" 11 "github.com/stretchr/testify/assert" 12 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 13 gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" 14 ) 15 16 func Test_gatewayClassAcceptedCondition(t *testing.T) { 17 type args struct { 18 gwc *gatewayv1.GatewayClass 19 accepted bool 20 } 21 tests := []struct { 22 name string 23 args args 24 want metav1.Condition 25 }{ 26 { 27 name: "accepted gateway class", 28 args: args{ 29 gwc: &gatewayv1.GatewayClass{ 30 ObjectMeta: metav1.ObjectMeta{ 31 Generation: 100, 32 }, 33 }, 34 accepted: true, 35 }, 36 want: metav1.Condition{ 37 Type: "Accepted", 38 Status: "True", 39 ObservedGeneration: 100, 40 Reason: "Accepted", 41 Message: "Valid GatewayClass", 42 }, 43 }, 44 { 45 name: "non-accepted gateway class", 46 args: args{ 47 gwc: &gatewayv1.GatewayClass{ 48 ObjectMeta: metav1.ObjectMeta{ 49 Generation: 100, 50 }, 51 }, 52 accepted: false, 53 }, 54 want: metav1.Condition{ 55 Type: "Accepted", 56 Status: "False", 57 ObservedGeneration: 100, 58 Reason: "InvalidParameters", 59 Message: "Invalid GatewayClass", 60 }, 61 }, 62 } 63 for _, tt := range tests { 64 t.Run(tt.name, func(t *testing.T) { 65 got := gatewayClassAcceptedCondition(tt.args.gwc, tt.args.accepted) 66 assert.True(t, cmp.Equal(got, tt.want, cmpopts.IgnoreFields(metav1.Condition{}, "LastTransitionTime")), "httpRouteAcceptedCondition() = %v, want %v", got, tt.want) 67 }) 68 } 69 }