diff --git a/tests/common/ratelimitpolicy/ratelimitpolicy_controller_test.go b/tests/common/ratelimitpolicy/ratelimitpolicy_controller_test.go index 338a4a955..867e52397 100644 --- a/tests/common/ratelimitpolicy/ratelimitpolicy_controller_test.go +++ b/tests/common/ratelimitpolicy/ratelimitpolicy_controller_test.go @@ -963,6 +963,85 @@ var _ = Describe("RateLimitPolicy CEL Validations", func() { }, testTimeOut) }) + Context("Limits missing from configuration", func() { + It("Missing limits object", func(ctx SpecContext) { + policy := policyFactory(func(policy *kuadrantv1.RateLimitPolicy) { + policy.Spec.Limits = nil + }) + err := k8sClient.Create(ctx, policy) + Expect(err).To(Not(BeNil())) + Expect(strings.Contains(err.Error(), "At least one spec.limits most be defined")).To(BeTrue()) + }, testTimeOut) + + It("Empty limits object created", func(ctx SpecContext) { + policy := policyFactory(func(policy *kuadrantv1.RateLimitPolicy) { + policy.Spec.Limits = map[string]kuadrantv1.Limit{} + + }) + err := k8sClient.Create(ctx, policy) + Expect(err).To(Not(BeNil())) + Expect(strings.Contains(err.Error(), "At least one spec.limits most be defined")).To(BeTrue()) + }, testTimeOut) + + It("Missing defaults.limits object", func(ctx SpecContext) { + policy := policyFactory(func(policy *kuadrantv1.RateLimitPolicy) { + policy.Spec.Limits = nil + policy.Spec.Defaults = &kuadrantv1.MergeableRateLimitPolicySpec{ + RateLimitPolicySpecProper: kuadrantv1.RateLimitPolicySpecProper{ + Limits: nil, + }, + } + }) + err := k8sClient.Create(ctx, policy) + Expect(err).To(Not(BeNil())) + Expect(strings.Contains(err.Error(), "At least one spec.defaults.limits most be defined")).To(BeTrue()) + }, testTimeOut) + + It("Empty defaults.limits object created", func(ctx SpecContext) { + policy := policyFactory(func(policy *kuadrantv1.RateLimitPolicy) { + policy.Spec.Limits = nil + policy.Spec.Defaults = &kuadrantv1.MergeableRateLimitPolicySpec{ + RateLimitPolicySpecProper: kuadrantv1.RateLimitPolicySpecProper{ + Limits: map[string]kuadrantv1.Limit{}, + }, + } + + }) + err := k8sClient.Create(ctx, policy) + Expect(err).To(Not(BeNil())) + Expect(strings.Contains(err.Error(), "At least one spec.defaults.limits most be defined")).To(BeTrue()) + }, testTimeOut) + + It("Missing overrides.limits object", func(ctx SpecContext) { + policy := policyFactory(func(policy *kuadrantv1.RateLimitPolicy) { + policy.Spec.Limits = nil + policy.Spec.Overrides = &kuadrantv1.MergeableRateLimitPolicySpec{ + RateLimitPolicySpecProper: kuadrantv1.RateLimitPolicySpecProper{ + Limits: nil, + }, + } + }) + err := k8sClient.Create(ctx, policy) + Expect(err).To(Not(BeNil())) + Expect(strings.Contains(err.Error(), "At least one spec.overrides.limits most be defined")).To(BeTrue()) + }, testTimeOut) + + It("Empty overrides.limits object created", func(ctx SpecContext) { + policy := policyFactory(func(policy *kuadrantv1.RateLimitPolicy) { + policy.Spec.Limits = nil + policy.Spec.Overrides = &kuadrantv1.MergeableRateLimitPolicySpec{ + RateLimitPolicySpecProper: kuadrantv1.RateLimitPolicySpecProper{ + Limits: map[string]kuadrantv1.Limit{}, + }, + } + + }) + err := k8sClient.Create(ctx, policy) + Expect(err).To(Not(BeNil())) + Expect(strings.Contains(err.Error(), "At least one spec.overrides.limits most be defined")).To(BeTrue()) + }, testTimeOut) + }) + Context("Defaults / Override validation", func() { It("Valid - only implicit defaults defined", func(ctx SpecContext) { policy := policyFactory(func(policy *kuadrantv1.RateLimitPolicy) {