@@ -14,6 +14,25 @@ import (
1414 ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1"
1515)
1616
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+
1736func TestClientSettingsPoliciesTargetRefKind (t * testing.T ) {
1837
1938 tests := []struct {
@@ -25,46 +44,46 @@ func TestClientSettingsPoliciesTargetRefKind(t *testing.T) {
2544 name : "Validate TargetRef of kind Gateway is allowed" ,
2645 policySpec : ngfAPIv1alpha1.ClientSettingsPolicySpec {
2746 TargetRef : gatewayv1alpha2.LocalPolicyTargetReference {
28- Kind : "Gateway" ,
29- Group : "gateway.networking.k8s.io" ,
47+ Kind : GatewayKind ,
48+ Group : GatewayGroup ,
3049 },
3150 },
3251 },
3352 {
3453 name : "Validate TargetRef of kind HTTPRoute is allowed" ,
3554 policySpec : ngfAPIv1alpha1.ClientSettingsPolicySpec {
3655 TargetRef : gatewayv1alpha2.LocalPolicyTargetReference {
37- Kind : "HTTPRoute" ,
38- Group : "gateway.networking.k8s.io" ,
56+ Kind : HTTPRouteKind ,
57+ Group : GatewayGroup ,
3958 },
4059 },
4160 },
4261 {
4362 name : "Validate TargetRef of kind GRPCRoute is allowed" ,
4463 policySpec : ngfAPIv1alpha1.ClientSettingsPolicySpec {
4564 TargetRef : gatewayv1alpha2.LocalPolicyTargetReference {
46- Kind : "GRPCRoute" ,
47- Group : "gateway.networking.k8s.io" ,
65+ Kind : GRPCRouteKind ,
66+ Group : GatewayGroup ,
4867 },
4968 },
5069 },
5170 {
5271 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 },
5473 policySpec : ngfAPIv1alpha1.ClientSettingsPolicySpec {
5574 TargetRef : gatewayv1alpha2.LocalPolicyTargetReference {
56- Kind : " InvalidKind" ,
57- Group : "gateway.networking.k8s.io" ,
75+ Kind : InvalidKind ,
76+ Group : GatewayGroup ,
5877 },
5978 },
6079 },
6180 {
6281 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 },
6483 policySpec : ngfAPIv1alpha1.ClientSettingsPolicySpec {
6584 TargetRef : gatewayv1alpha2.LocalPolicyTargetReference {
66- Kind : "TCPRoute" ,
67- Group : "gateway.networking.k8s.io" ,
85+ Kind : TCPRouteKind ,
86+ Group : GatewayGroup ,
6887 },
6988 },
7089 },
@@ -98,28 +117,28 @@ func TestClientSettingsPoliciesTargetRefGroup(t *testing.T) {
98117 name : "Validate gateway.networking.k8s.io TargetRef Group is allowed" ,
99118 policySpec : ngfAPIv1alpha1.ClientSettingsPolicySpec {
100119 TargetRef : gatewayv1alpha2.LocalPolicyTargetReference {
101- Kind : "Gateway" ,
102- Group : "gateway.networking.k8s.io" ,
120+ Kind : GatewayKind ,
121+ Group : GatewayGroup ,
103122 },
104123 },
105124 },
106125 {
107126 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 },
109128 policySpec : ngfAPIv1alpha1.ClientSettingsPolicySpec {
110129 TargetRef : gatewayv1alpha2.LocalPolicyTargetReference {
111- Kind : "Gateway" ,
112- Group : "invalid.networking.k8s.io" ,
130+ Kind : GatewayKind ,
131+ Group : InvalidGroup ,
113132 },
114133 },
115134 },
116135 {
117136 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 },
119138 policySpec : ngfAPIv1alpha1.ClientSettingsPolicySpec {
120139 TargetRef : gatewayv1alpha2.LocalPolicyTargetReference {
121- Kind : "Gateway" ,
122- Group : "discovery.k8s.io/v1" ,
140+ Kind : GatewayKind ,
141+ Group : DiscoveryGroup ,
123142 },
124143 },
125144 },
0 commit comments