Skip to content

Commit 3d09142

Browse files
committed
add directives check
1 parent 6e267ea commit 3d09142

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

Diff for: tests/suite/upstream_settings_test.go

+33-30
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ var _ = Describe("UpstreamSettingsPolicy", Ordered, Label("functional", "uspolic
201201
},
202202
}),
203203
Entry("GRPC upstreams", []framework.ExpectedNginxField{
204+
{
205+
Directive: "upstream",
206+
Value: "uspolicy_grpc-backend_8080",
207+
File: "http.conf",
208+
},
204209
{
205210
Directive: "zone",
206211
Value: "uspolicy_grpc-backend_8080 64k",
@@ -251,8 +256,8 @@ var _ = Describe("UpstreamSettingsPolicy", Ordered, Label("functional", "uspolic
251256

252257
DescribeTable("upstreamSettingsPolicy status is set as expected",
253258
func(name string, status metav1.ConditionStatus, condReason v1alpha2.PolicyConditionReason) {
254-
nsname := types.NamespacedName{Name: name, Namespace: namespace}
255-
Expect(waitForUSPolicyStatus(nsname, gatewayName, status, condReason)).To(Succeed())
259+
uspolicyNsName := types.NamespacedName{Name: name, Namespace: namespace}
260+
Expect(waitForUSPolicyStatus(uspolicyNsName, gatewayName, status, condReason)).To(Succeed())
256261
},
257262
Entry("uspolicy merge-usp-1", "merge-usp-1", metav1.ConditionTrue, v1alpha2.PolicyReasonAccepted),
258263
Entry("uspolicy merge-usp-2", "merge-usp-2", metav1.ConditionTrue, v1alpha2.PolicyReasonAccepted),
@@ -309,6 +314,11 @@ var _ = Describe("UpstreamSettingsPolicy", Ordered, Label("functional", "uspolic
309314
}
310315
},
311316
Entry("Coffee upstream", []framework.ExpectedNginxField{
317+
{
318+
Directive: "upstream",
319+
Value: "uspolicy_coffee_80",
320+
File: "http.conf",
321+
},
312322
{
313323
Directive: "zone",
314324
Value: "uspolicy_coffee_80 512k",
@@ -347,23 +357,27 @@ var _ = Describe("UpstreamSettingsPolicy", Ordered, Label("functional", "uspolic
347357
Upstream: "uspolicy_tea_80",
348358
File: "http.conf",
349359
},
360+
{
361+
Directive: "upstream",
362+
Value: "uspolicy_tea_80",
363+
File: "http.conf",
364+
},
350365
}),
351366
)
352367
})
353368
})
354369

355-
When("UpstreamSettingsPolicy targets a Service that does not exists", func() {
370+
When("UpstreamSettingsPolicy targets a Service that does not exist", func() {
356371
Specify("upstreamSettingsPolicy sets no condition", func() {
357372
files := []string{"upstream-settings-policy/invalid-svc-usps.yaml"}
358373

359374
Expect(resourceManager.ApplyFromFiles(files, namespace)).To(Succeed())
360375

361-
nsname := types.NamespacedName{Name: "usps-target-not-found", Namespace: namespace}
376+
uspolicyNsName := types.NamespacedName{Name: "usps-target-not-found", Namespace: namespace}
377+
362378
Consistently(
363379
func() bool {
364-
return waitForUSPolicyToHaveAncestor(
365-
nsname,
366-
) != nil
380+
return usPolicyHasNoAncestors(uspolicyNsName)
367381
}).WithTimeout(timeoutConfig.GetTimeout).
368382
WithPolling(500 * time.Millisecond).
369383
Should(BeTrue())
@@ -373,18 +387,18 @@ var _ = Describe("UpstreamSettingsPolicy", Ordered, Label("functional", "uspolic
373387
})
374388

375389
When("UpstreamSettingsPolicy targets a Service that is owned by an invalid Gateway", func() {
376-
Specify("upstreamSettingsPolicy has no condition set", func() {
390+
Specify("upstreamSettingsPolicy is not Accepted with the reason TargetNotFound", func() {
377391
// delete existing gateway
378392
gatewayFileName := "upstream-settings-policy/gateway.yaml"
379393
Expect(resourceManager.DeleteFromFiles([]string{gatewayFileName}, namespace)).To(Succeed())
380394

381395
files := []string{"upstream-settings-policy/invalid-target-usps.yaml"}
382396
Expect(resourceManager.ApplyFromFiles(files, namespace)).To(Succeed())
383397

384-
nsname := types.NamespacedName{Name: "soda-svc-usp", Namespace: namespace}
398+
uspolicyNsName := types.NamespacedName{Name: "soda-svc-usp", Namespace: namespace}
385399
gatewayName = "gateway-not-valid"
386400
Expect(waitForUSPolicyStatus(
387-
nsname,
401+
uspolicyNsName,
388402
gatewayName,
389403
metav1.ConditionFalse,
390404
v1alpha2.PolicyReasonTargetNotFound,
@@ -395,30 +409,19 @@ var _ = Describe("UpstreamSettingsPolicy", Ordered, Label("functional", "uspolic
395409
})
396410
})
397411

398-
func waitForUSPolicyToHaveAncestor(usPolicyNsName types.NamespacedName) error {
412+
func usPolicyHasNoAncestors(usPolicyNsName types.NamespacedName) bool {
413+
GinkgoWriter.Printf("Checking that UpstreamSettingsPolicy %q has no ancestors in status", usPolicyNsName)
414+
399415
ctx, cancel := context.WithTimeout(context.Background(), timeoutConfig.GetStatusTimeout)
400416
defer cancel()
401417

402-
GinkgoWriter.Printf("Polling for UpstreamSettings Policy %q to not have a condition", usPolicyNsName)
403-
404-
return wait.PollUntilContextCancel(
405-
ctx,
406-
timeoutConfig.GetStatusTimeout,
407-
true, /* poll immediately */
408-
func(ctx context.Context) (bool, error) {
409-
var usPolicy ngfAPI.UpstreamSettingsPolicy
410-
var err error
411-
if err = k8sClient.Get(ctx, usPolicyNsName, &usPolicy); err != nil {
412-
return false, err
413-
}
414-
415-
if len(usPolicy.Status.Ancestors) == 0 {
416-
return false, nil
417-
}
418+
var usPolicy ngfAPI.UpstreamSettingsPolicy
419+
if err := k8sClient.Get(ctx, usPolicyNsName, &usPolicy); err != nil {
420+
GinkgoWriter.Printf("Failed to get UpstreamSettingsPolicy %q: %s", usPolicyNsName, err.Error())
421+
return false
422+
}
418423

419-
return errors.Is(err, context.DeadlineExceeded), nil
420-
},
421-
)
424+
return len(usPolicy.Status.Ancestors) == 0
422425
}
423426

424427
func waitForUSPolicyStatus(

0 commit comments

Comments
 (0)