Skip to content

Commit

Permalink
Integration tests.
Browse files Browse the repository at this point in the history
Add integration tests for the six states that the user can try add invaild limit blocks.
This does not check if the limits are valid only that they are there.

Signed-off-by: Jim Fitzpatrick <jfitzpat@redhat.com>
  • Loading branch information
Boomatang committed Nov 15, 2024
1 parent c11c535 commit dea4490
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions tests/common/ratelimitpolicy/ratelimitpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit dea4490

Please sign in to comment.