@@ -14,6 +14,25 @@ import (
14
14
ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1"
15
15
)
16
16
17
+ const (
18
+ GatewayKind = "Gateway"
19
+ HTTPRouteKind = "HTTPRoute"
20
+ GRPCRouteKind = "GRPCRoute"
21
+ TCPRouteKind = "TCPRoute"
22
+ InvalidKind = "InvalidKind"
23
+ )
24
+
25
+ const (
26
+ GatewayGroup = "gateway.networking.k8s.io"
27
+ InvalidGroup = "invalid.networking.k8s.io"
28
+ DiscoveryGroup = "discovery.k8s.io/v1"
29
+ )
30
+
31
+ const (
32
+ ExpectedTargetRefKindError = "TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute'"
33
+ ExpectedTargetRefGroupError = "TargetRef Group must be gateway.networking.k8s.io."
34
+ )
35
+
17
36
func TestClientSettingsPoliciesTargetRefKind (t * testing.T ) {
18
37
19
38
tests := []struct {
@@ -25,46 +44,46 @@ func TestClientSettingsPoliciesTargetRefKind(t *testing.T) {
25
44
name : "Validate TargetRef of kind Gateway is allowed" ,
26
45
policySpec : ngfAPIv1alpha1.ClientSettingsPolicySpec {
27
46
TargetRef : gatewayv1alpha2.LocalPolicyTargetReference {
28
- Kind : "Gateway" ,
29
- Group : "gateway.networking.k8s.io" ,
47
+ Kind : GatewayKind ,
48
+ Group : GatewayGroup ,
30
49
},
31
50
},
32
51
},
33
52
{
34
53
name : "Validate TargetRef of kind HTTPRoute is allowed" ,
35
54
policySpec : ngfAPIv1alpha1.ClientSettingsPolicySpec {
36
55
TargetRef : gatewayv1alpha2.LocalPolicyTargetReference {
37
- Kind : "HTTPRoute" ,
38
- Group : "gateway.networking.k8s.io" ,
56
+ Kind : HTTPRouteKind ,
57
+ Group : GatewayGroup ,
39
58
},
40
59
},
41
60
},
42
61
{
43
62
name : "Validate TargetRef of kind GRPCRoute is allowed" ,
44
63
policySpec : ngfAPIv1alpha1.ClientSettingsPolicySpec {
45
64
TargetRef : gatewayv1alpha2.LocalPolicyTargetReference {
46
- Kind : "GRPCRoute" ,
47
- Group : "gateway.networking.k8s.io" ,
65
+ Kind : GRPCRouteKind ,
66
+ Group : GatewayGroup ,
48
67
},
49
68
},
50
69
},
51
70
{
52
71
name : "Validate Invalid TargetRef Kind is not allowed" ,
53
- wantErrors : []string {"TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute'" },
72
+ wantErrors : []string {ExpectedTargetRefKindError },
54
73
policySpec : ngfAPIv1alpha1.ClientSettingsPolicySpec {
55
74
TargetRef : gatewayv1alpha2.LocalPolicyTargetReference {
56
- Kind : " InvalidKind" ,
57
- Group : "gateway.networking.k8s.io" ,
75
+ Kind : InvalidKind ,
76
+ Group : GatewayGroup ,
58
77
},
59
78
},
60
79
},
61
80
{
62
81
name : "Validate TCPRoute TargetRef Kind is not allowed" ,
63
- wantErrors : []string {"TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute'" },
82
+ wantErrors : []string {ExpectedTargetRefKindError },
64
83
policySpec : ngfAPIv1alpha1.ClientSettingsPolicySpec {
65
84
TargetRef : gatewayv1alpha2.LocalPolicyTargetReference {
66
- Kind : "TCPRoute" ,
67
- Group : "gateway.networking.k8s.io" ,
85
+ Kind : TCPRouteKind ,
86
+ Group : GatewayGroup ,
68
87
},
69
88
},
70
89
},
@@ -98,28 +117,28 @@ func TestClientSettingsPoliciesTargetRefGroup(t *testing.T) {
98
117
name : "Validate gateway.networking.k8s.io TargetRef Group is allowed" ,
99
118
policySpec : ngfAPIv1alpha1.ClientSettingsPolicySpec {
100
119
TargetRef : gatewayv1alpha2.LocalPolicyTargetReference {
101
- Kind : "Gateway" ,
102
- Group : "gateway.networking.k8s.io" ,
120
+ Kind : GatewayKind ,
121
+ Group : GatewayGroup ,
103
122
},
104
123
},
105
124
},
106
125
{
107
126
name : "Validate invalid.networking.k8s.io TargetRef Group is not allowed" ,
108
- wantErrors : []string {"TargetRef Group must be gateway.networking.k8s.io." },
127
+ wantErrors : []string {ExpectedTargetRefGroupError },
109
128
policySpec : ngfAPIv1alpha1.ClientSettingsPolicySpec {
110
129
TargetRef : gatewayv1alpha2.LocalPolicyTargetReference {
111
- Kind : "Gateway" ,
112
- Group : "invalid.networking.k8s.io" ,
130
+ Kind : GatewayKind ,
131
+ Group : InvalidGroup ,
113
132
},
114
133
},
115
134
},
116
135
{
117
136
name : "Validate discovery.k8s.io/v1 TargetRef Group is not allowed" ,
118
- wantErrors : []string {"TargetRef Group must be gateway.networking.k8s.io." },
137
+ wantErrors : []string {ExpectedTargetRefGroupError },
119
138
policySpec : ngfAPIv1alpha1.ClientSettingsPolicySpec {
120
139
TargetRef : gatewayv1alpha2.LocalPolicyTargetReference {
121
- Kind : "Gateway" ,
122
- Group : "discovery.k8s.io/v1" ,
140
+ Kind : GatewayKind ,
141
+ Group : DiscoveryGroup ,
123
142
},
124
143
},
125
144
},
0 commit comments