@@ -16,25 +16,6 @@ import (
1616)
1717
1818func TestClientSettingsPoliciesTargetRefKind (t * testing.T ) {
19- // Test valid and invalid TargetRef Kind
20- // Valid kinds are: Gateway, HTTPRoute, GRPCRoute
21- testValidTargetRefKind (t )
22- // Invalid kinds should return an error
23- // Example of an invalid kind: "InvalidKind", "TCPRoute"
24- testInvalidTargetRefKind (t )
25- }
26-
27- func TestClientSettingsPoliciesTargetRefGroup (t * testing.T ) {
28- // Test valid TargetRef Group
29- // Valid group is: "gateway.networking.k8s.io"
30- testValidTargetRefGroup (t )
31- // Invalid groups should return an error
32- // Examples of invalid groups: "invalid.networking.k8s.io", "discovery.k8s.io/v1"
33- testInvalidTargetRefGroup (t )
34- }
35-
36- func testValidTargetRefKind (t * testing.T ) {
37- t .Helper ()
3819
3920 tests := []struct {
4021 policySpec ngfAPIv1alpha1.ClientSettingsPolicySpec
@@ -68,33 +49,6 @@ func testValidTargetRefKind(t *testing.T) {
6849 },
6950 },
7051 },
71- }
72-
73- for _ , tt := range tests {
74- t .Run (tt .name , func (t * testing.T ) {
75- // Create a ClientSettingsPolicy with the targetRef from the test case.
76- clientSettingsPolicy := & ngfAPIv1alpha1.ClientSettingsPolicy {
77- ObjectMeta : metav1.ObjectMeta {
78- Name : "test-policy" ,
79- Namespace : "default" ,
80- },
81- Spec : ngfAPIv1alpha1.ClientSettingsPolicySpec {
82- TargetRef : tt .policySpec .TargetRef ,
83- },
84- }
85- validateClientSettingsPolicy (t , clientSettingsPolicy , tt .wantErrors )
86- })
87- }
88- }
89-
90- func testInvalidTargetRefKind (t * testing.T ) {
91- t .Helper ()
92-
93- tests := []struct {
94- policySpec ngfAPIv1alpha1.ClientSettingsPolicySpec
95- name string
96- wantErrors []string
97- }{
9852 {
9953 name : "Validate Invalid TargetRef Kind is not allowed" ,
10054 wantErrors : []string {"TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute'" },
@@ -134,51 +88,22 @@ func testInvalidTargetRefKind(t *testing.T) {
13488 }
13589}
13690
137- func testValidTargetRefGroup (t * testing.T ) {
138- t .Helper ()
91+ func TestClientSettingsPoliciesTargetRefGroup (t * testing.T ) {
13992
14093 tests := []struct {
14194 policySpec ngfAPIv1alpha1.ClientSettingsPolicySpec
14295 name string
14396 wantErrors []string
14497 }{
14598 {
146- name : "Validate gateway.networking.k8s.io TargetRef Group is allowed" ,
147- wantErrors : []string {"TargetRef Group must be gateway.networking.k8s.io." },
99+ name : "Validate gateway.networking.k8s.io TargetRef Group is allowed" ,
148100 policySpec : ngfAPIv1alpha1.ClientSettingsPolicySpec {
149101 TargetRef : gatewayv1alpha2.LocalPolicyTargetReference {
150102 Kind : "Gateway" ,
151103 Group : "gateway.networking.k8s.io" ,
152104 },
153105 },
154106 },
155- }
156-
157- for _ , tt := range tests {
158- t .Run (tt .name , func (t * testing.T ) {
159- // Create a ClientSettingsPolicy with the targetRef from the test case.
160- clientSettingsPolicy := & ngfAPIv1alpha1.ClientSettingsPolicy {
161- ObjectMeta : metav1.ObjectMeta {
162- Name : "test-policy" ,
163- Namespace : "default" ,
164- },
165- Spec : ngfAPIv1alpha1.ClientSettingsPolicySpec {
166- TargetRef : tt .policySpec .TargetRef ,
167- },
168- }
169- validateClientSettingsPolicy (t , clientSettingsPolicy , tt .wantErrors )
170- })
171- }
172- }
173-
174- func testInvalidTargetRefGroup (t * testing.T ) {
175- t .Helper ()
176-
177- tests := []struct {
178- policySpec ngfAPIv1alpha1.ClientSettingsPolicySpec
179- name string
180- wantErrors []string
181- }{
182107 {
183108 name : "Validate invalid.networking.k8s.io TargetRef Group is not allowed" ,
184109 wantErrors : []string {"TargetRef Group must be gateway.networking.k8s.io." },
0 commit comments