ratelimit

package
v0.0.0-...-e6a14be Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertNRateLimitedResponses

func AssertNRateLimitedResponses(t *testing.T, n int, method, url string, headers map[string]string)

AssertNRateLimitedResponses sends n requests in total and asserts that each response is 429 TooManyRequests. In dualstack mode, requests are distributed per family.

func AssertNSuccessfulResponses

func AssertNSuccessfulResponses(t *testing.T, n int, method, url string, headers map[string]string)

AssertNSuccessfulResponses sends n requests in total and asserts that each response is 200 OK. In dualstack mode, requests are distributed per family.

func AssertNSuccessfulResponsesWithRetries

func AssertNSuccessfulResponsesWithRetries(t *testing.T, n, maxRetries int, method, url string, headers map[string]string)

AssertNSuccessfulResponsesWithRetries sends up to maxRetries requests and asserts that at least n 200 OK responses are received. 429 responses are ignored. The function logs the total requests sent and how many were successful.

Use this instead of AssertNSuccessfulResponses when there are multiple pods: each pod has an independent token bucket, so requests must be distributed across all pods to drain their combined capacity. maxRetries provides a budget to account for uneven LB distribution.

func AssertRateLimitResponseHeaders

func AssertRateLimitResponseHeaders(t *testing.T, method, url string, headers map[string]string, expectedLimit, expectedRemaining int)

AssertRateLimitResponseHeaders asserts that the response contains the x-ratelimit-limit and x-ratelimit-remaining headers with the expected values, which are set by Envoy when enableResponseHeaders is true.

func MatchingPodCount

func MatchingPodCount(t *testing.T, rateLimitName, namespace string) int

MatchingPodCount returns the number of running pods in namespace whose labels match the selectorLabels of the named RateLimit. Returns 1 if none are found.

func SetupAPIRule

func SetupAPIRule(t *testing.T, apiRuleYAML string, templateValues map[string]any, namespace string)

SetupAPIRule creates an APIRule from the given template and waits until it is ready.

func SetupRateLimit

func SetupRateLimit(t *testing.T, rateLimitYAML string, templateValues map[string]any, namespace string)

SetupRateLimit creates a RateLimit resource from the given template and waits until it is ready. It also registers a cleanup that waits for the resource to be fully deleted, so that sequential tests sharing the same ingressgateway do not observe stale Envoy state.

func WaitUntilDeleted

func WaitUntilDeleted(t *testing.T, name, namespace string)

func WaitUntilReady

func WaitUntilReady(t *testing.T, name, namespace string)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL