...
1
16
17 package validation_test
18
19 import (
20 "testing"
21
22 gatewayv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1"
23 validationtutils "sigs.k8s.io/gateway-api/apis/v1beta1/util/validation"
24 )
25
26 func TestIsControllerNameValid(t *testing.T) {
27 testCases := []struct {
28 name string
29 controllerName gatewayv1b1.GatewayController
30 isvalid bool
31 }{
32 {
33 name: "empty controller name",
34 controllerName: "",
35 isvalid: false,
36 },
37 {
38 name: "invalid controller name 1",
39 controllerName: "example.com",
40 isvalid: false,
41 },
42 {
43 name: "invalid controller name 2",
44 controllerName: "example*com/bar",
45 isvalid: false,
46 },
47 {
48 name: "invalid controller name 3",
49 controllerName: "example/@bar",
50 isvalid: false,
51 },
52 {
53 name: "valid controller name",
54 controllerName: "example.com/bar",
55 isvalid: true,
56 },
57 }
58
59 for _, tc := range testCases {
60 tc := tc
61 t.Run(tc.name, func(t *testing.T) {
62 isValid := validationtutils.IsControllerNameValid(tc.controllerName)
63 if isValid != tc.isvalid {
64 t.Errorf("Expected validity %t, got %t", tc.isvalid, isValid)
65 }
66 })
67 }
68 }
69
View as plain text