|
1 | 1 | package cel |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "context" |
5 | 4 | "testing" |
6 | 5 |
|
7 | 6 | . "github.com/onsi/gomega" |
8 | 7 | controllerruntime "sigs.k8s.io/controller-runtime" |
9 | | - "sigs.k8s.io/controller-runtime/pkg/client" |
10 | 8 | gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" |
11 | 9 |
|
12 | 10 | ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/v2/apis/v1alpha1" |
13 | 11 | "github.com/nginx/nginx-gateway-fabric/v2/internal/framework/helpers" |
14 | | - "github.com/nginx/nginx-gateway-fabric/v2/tests/framework" |
15 | 12 | ) |
16 | 13 |
|
17 | 14 | func TestClientSettingsPoliciesTargetRefKind(t *testing.T) { |
@@ -78,7 +75,16 @@ func TestClientSettingsPoliciesTargetRefKind(t *testing.T) { |
78 | 75 | for _, tt := range tests { |
79 | 76 | t.Run(tt.name, func(t *testing.T) { |
80 | 77 | t.Parallel() |
81 | | - validateClientSettingsPolicy(t, tt, g, k8sClient) |
| 78 | + policySpec := tt.policySpec |
| 79 | + policySpec.TargetRef.Name = gatewayv1alpha2.ObjectName(uniqueResourceName(testTargetRefName)) |
| 80 | + clientSettingsPolicy := &ngfAPIv1alpha1.ClientSettingsPolicy{ |
| 81 | + ObjectMeta: controllerruntime.ObjectMeta{ |
| 82 | + Name: uniqueResourceName(testPolicyName), |
| 83 | + Namespace: defaultNamespace, |
| 84 | + }, |
| 85 | + Spec: policySpec, |
| 86 | + } |
| 87 | + validateCrd(t, tt.wantErrors, g, clientSettingsPolicy, k8sClient) |
82 | 88 | }) |
83 | 89 | } |
84 | 90 | } |
@@ -129,7 +135,16 @@ func TestClientSettingsPoliciesTargetRefGroup(t *testing.T) { |
129 | 135 | for _, tt := range tests { |
130 | 136 | t.Run(tt.name, func(t *testing.T) { |
131 | 137 | t.Parallel() |
132 | | - validateClientSettingsPolicy(t, tt, g, k8sClient) |
| 138 | + policySpec := tt.policySpec |
| 139 | + policySpec.TargetRef.Name = gatewayv1alpha2.ObjectName(uniqueResourceName(testTargetRefName)) |
| 140 | + clientSettingsPolicy := &ngfAPIv1alpha1.ClientSettingsPolicy{ |
| 141 | + ObjectMeta: controllerruntime.ObjectMeta{ |
| 142 | + Name: uniqueResourceName(testPolicyName), |
| 143 | + Namespace: defaultNamespace, |
| 144 | + }, |
| 145 | + Spec: policySpec, |
| 146 | + } |
| 147 | + validateCrd(t, tt.wantErrors, g, clientSettingsPolicy, k8sClient) |
133 | 148 | }) |
134 | 149 | } |
135 | 150 | } |
@@ -191,46 +206,16 @@ func TestClientSettingsPoliciesKeepAliveTimeout(t *testing.T) { |
191 | 206 | for _, tt := range tests { |
192 | 207 | t.Run(tt.name, func(t *testing.T) { |
193 | 208 | t.Parallel() |
194 | | - validateClientSettingsPolicy(t, tt, g, k8sClient) |
| 209 | + policySpec := tt.policySpec |
| 210 | + policySpec.TargetRef.Name = gatewayv1alpha2.ObjectName(uniqueResourceName(testTargetRefName)) |
| 211 | + clientSettingsPolicy := &ngfAPIv1alpha1.ClientSettingsPolicy{ |
| 212 | + ObjectMeta: controllerruntime.ObjectMeta{ |
| 213 | + Name: uniqueResourceName(testPolicyName), |
| 214 | + Namespace: defaultNamespace, |
| 215 | + }, |
| 216 | + Spec: policySpec, |
| 217 | + } |
| 218 | + validateCrd(t, tt.wantErrors, g, clientSettingsPolicy, k8sClient) |
195 | 219 | }) |
196 | 220 | } |
197 | 221 | } |
198 | | - |
199 | | -func validateClientSettingsPolicy(t *testing.T, tt struct { |
200 | | - policySpec ngfAPIv1alpha1.ClientSettingsPolicySpec |
201 | | - name string |
202 | | - wantErrors []string |
203 | | -}, g *WithT, k8sClient client.Client, |
204 | | -) { |
205 | | - t.Helper() |
206 | | - |
207 | | - policySpec := tt.policySpec |
208 | | - policySpec.TargetRef.Name = gatewayv1alpha2.ObjectName(uniqueResourceName(testTargetRefName)) |
209 | | - policyName := uniqueResourceName(testPolicyName) |
210 | | - |
211 | | - clientSettingsPolicy := &ngfAPIv1alpha1.ClientSettingsPolicy{ |
212 | | - ObjectMeta: controllerruntime.ObjectMeta{ |
213 | | - Name: policyName, |
214 | | - Namespace: defaultNamespace, |
215 | | - }, |
216 | | - Spec: policySpec, |
217 | | - } |
218 | | - timeoutConfig := framework.DefaultTimeoutConfig() |
219 | | - ctx, cancel := context.WithTimeout(context.Background(), timeoutConfig.KubernetesClientTimeout) |
220 | | - err := k8sClient.Create(ctx, clientSettingsPolicy) |
221 | | - defer cancel() |
222 | | - |
223 | | - // Clean up after test |
224 | | - defer func() { |
225 | | - _ = k8sClient.Delete(context.Background(), clientSettingsPolicy) |
226 | | - }() |
227 | | - |
228 | | - if len(tt.wantErrors) == 0 { |
229 | | - g.Expect(err).ToNot(HaveOccurred()) |
230 | | - } else { |
231 | | - g.Expect(err).To(HaveOccurred()) |
232 | | - for _, wantError := range tt.wantErrors { |
233 | | - g.Expect(err.Error()).To(ContainSubstring(wantError), "Expected error '%s' not found in: %s", wantError, err.Error()) |
234 | | - } |
235 | | - } |
236 | | -} |
0 commit comments