Documentation ¶
Index ¶
- func CountHTTPGetResponses(t *testing.T, proxyURL *url.URL, cfg CountHTTPResponsesConfig, ...) (matchedResponseCounter map[string]int)
- func DefaultHTTPClient() *http.Client
- func DistributionOfMapValues(counter map[string]int) map[string]float64
- func EventuallyExpectHTTP404WithNoRoute(t *testing.T, proxyURL *url.URL, path string, waitDuration time.Duration, ...)
- func EventuallyGETPath(t *testing.T, proxyURL *url.URL, path string, statusCode int, ...)
- func GenerateKongBuilder(_ context.Context) (*kong.Builder, []string, error)
- func GetKongDBMode(proxyAdminURL *url.URL, kongTestPassword string) (string, error)
- func GetKongRootConfig(proxyAdminURL *url.URL, kongTestPassword string) (map[string]any, error)
- func GetKongRouterFlavor(proxyAdminURL *url.URL, kongTestPassword string) (string, error)
- func GetKongVersion(proxyAdminURL *url.URL, kongTestPassword string) (kong.Version, error)
- func LabelValueForTest(t *testing.T) string
- func MustHTTPRequest(t *testing.T, method string, proxyURL *url.URL, path string, ...) *http.Request
- func MustParseURL(t *testing.T, urlStr string) *url.URL
- func Namespace(ctx context.Context, t *testing.T, env environments.Environment) *corev1.Namespace
- func RemoveCluster(ctx context.Context, cluster clusters.Cluster) error
- func RetryableHTTPClient(base *http.Client) *http.Client
- func Setup(ctx context.Context, t *testing.T, env environments.Environment) (*corev1.Namespace, *clusters.Cleaner)
- func TeardownCluster(ctx context.Context, t *testing.T, cluster clusters.Cluster)
- type CountHTTPResponsesConfig
- type ResponseMatcher
- type TCPProxy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CountHTTPGetResponses ¶
func CountHTTPGetResponses( t *testing.T, proxyURL *url.URL, cfg CountHTTPResponsesConfig, matchers ...ResponseMatcher, ) (matchedResponseCounter map[string]int)
func DefaultHTTPClient ¶
DefaultHTTPClient returns a client that should be used by default in tests. All defaults that should be propagated to tests for use should be changed in here.
func DistributionOfMapValues ¶
DistributionOfMapValues returns a map of the values in the given counter map and the relative frequency of each value.
func EventuallyExpectHTTP404WithNoRoute ¶ added in v2.10.0
func EventuallyExpectHTTP404WithNoRoute( t *testing.T, proxyURL *url.URL, path string, waitDuration time.Duration, waitTick time.Duration, headers map[string]string, )
EventuallyExpectHTTP404WithNoRoute is used to check whether a given http response is (specifically) a Kong 404.
func EventuallyGETPath ¶
func EventuallyGETPath( t *testing.T, proxyURL *url.URL, path string, statusCode int, bodyContents string, headers map[string]string, waitDuration time.Duration, waitTick time.Duration, )
EventuallyGETPath makes a GET request to the Kong proxy multiple times until either the request starts to respond with the given status code and contents present in the response body, or until timeout occurrs according to ingressWait time limits. This uses only the path of for the request and does not pay attention to hostname or other routing rules. This uses a "require" for the desired conditions so if this request doesn't eventually succeed the calling test will fail and stop.
func GenerateKongBuilder ¶
GenerateKongBuilder returns a Kong KTF addon builder, a string slice of controller arguments needed to interact with the addon and an error.
func GetKongDBMode ¶ added in v2.10.0
GetKongDBMode returns kong dbmode using the provided Admin API URL.
func GetKongRootConfig ¶ added in v2.12.0
GetKongRootConfig gets version and root configurations of Kong from / endpoint of the provided Admin API URL.
func GetKongRouterFlavor ¶ added in v2.12.0
GetKongRouterFlavor gets router flavor of Kong using the provided Admin API URL.
func GetKongVersion ¶
GetKongVersion returns kong version using the provided Admin API URL.
func LabelValueForTest ¶
LabelValueForTest returns a sanitized test name that can be used as kubernetes label value.
func MustHTTPRequest ¶
func MustHTTPRequest(t *testing.T, method string, proxyURL *url.URL, path string, headers map[string]string) *http.Request
MustHTTPRequest creates a request with provided parameters and it fails the test that it was called in when request creation fails.
func MustParseURL ¶ added in v2.10.0
MustParseURL parses a string format URL to *url.URL. If error happens, fails the test.
func Namespace ¶
func Namespace(ctx context.Context, t *testing.T, env environments.Environment) *corev1.Namespace
Namespace provides the Namespace provisioned for each test case given their t.Name as the "testCase".
func RemoveCluster ¶ added in v2.12.0
RemoveCluster removes the cluster if it was created by the test suite. Pass desired timeout through context.
func RetryableHTTPClient ¶ added in v2.10.0
RetryableHTTPClient wraps a client with retry logic. That should be used when calling external services that might temporarily fail (e.g. Konnect APIs), and we don't want them to affect the test results.
func Setup ¶
func Setup(ctx context.Context, t *testing.T, env environments.Environment) (*corev1.Namespace, *clusters.Cleaner)
Setup is a test helper function which:
- creates a cluster cleaner which will be used to to clean up test resources automatically after the test finishes and creates a new namespace for the test to use.
- creates a namespace for the provided test and adds it to the cleaner for automatic cleanup using the previously created cleaner.
TODO move this into a shared library https://github.com/Kong/kubernetes-testing-framework/issues/302
Types ¶
type ResponseMatcher ¶
ResponseMatcher is a function that returns match-name and whether the response matches the provided criteria.
func MatchRespByStatusAndContent ¶
func MatchRespByStatusAndContent( responseName string, expectedStatusCode int, expectedBodyContents string, ) ResponseMatcher
MatchRespByStatusAndContent returns a responseMatcher that matches the given status code and body contents.
type TCPProxy ¶ added in v2.12.0
type TCPProxy struct {
// contains filtered or unexported fields
}
TCPProxy is a simple server that forwards TCP connections to a given destination. It can be used to simulate network failures by stopping accepting new connections and interrupting existing ones.
func NewTCPProxy ¶ added in v2.12.0
func (*TCPProxy) Run ¶ added in v2.12.0
Run starts connections accepting loop and blocks until the context is canceled.
func (*TCPProxy) StartHandlingConnections ¶ added in v2.12.0
func (p *TCPProxy) StartHandlingConnections()
StartHandlingConnections starts handling new connections.
func (*TCPProxy) StopHandlingConnections ¶ added in v2.12.0
func (p *TCPProxy) StopHandlingConnections()
StopHandlingConnections stops handling connections by interrupting all existing connections and immediately closing new connections.