github.com/cilium/cilium@v1.16.2/operator/pkg/gateway-api/gatewayclass_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/stretchr/testify/require" 10 "sigs.k8s.io/controller-runtime/pkg/client" 11 gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" 12 13 corev1 "github.com/cilium/cilium/pkg/k8s/slim/k8s/api/core/v1" 14 ) 15 16 func Test_matchesControllerName(t *testing.T) { 17 testCases := []struct { 18 name string 19 object client.Object 20 expected bool 21 }{ 22 { 23 name: "matches", 24 object: &gatewayv1.GatewayClass{ 25 Spec: gatewayv1.GatewayClassSpec{ 26 ControllerName: "foo", 27 }, 28 }, 29 expected: true, 30 }, 31 { 32 name: "does not match", 33 object: &gatewayv1.GatewayClass{ 34 Spec: gatewayv1.GatewayClassSpec{ 35 ControllerName: "bar", 36 }, 37 }, 38 expected: false, 39 }, 40 { 41 name: "not a GatewayClass", 42 object: &corev1.Service{}, 43 expected: false, 44 }, 45 } 46 47 for _, tc := range testCases { 48 t.Run(tc.name, func(t *testing.T) { 49 require.Equal(t, tc.expected, matchesControllerName("foo")(tc.object)) 50 }) 51 } 52 }