tests

package
v0.0.0-...-efa9021 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClusterTrustBundleFeature features.FeatureName = "ClusterTrustBundle"

	ConformanceInfraNamespace = "gateway-conformance-infra"

	AllNamespacesGateway = "all-namespaces"
)

Variables

View Source
var (
	IPFamily      = os.Getenv("IP_FAMILY")
	DeployProfile = os.Getenv("KUBE_DEPLOY_PROFILE")

	SameNamespaceGateway    = types.NamespacedName{Name: "same-namespace", Namespace: ConformanceInfraNamespace}
	SameNamespaceGatewayRef = k8sutils.NewGatewayRef(SameNamespaceGateway)

	PodReady = corev1.PodCondition{Type: corev1.PodReady, Status: corev1.ConditionTrue}
)

Functions

func AlmostEquals

func AlmostEquals(actual, expect, offset int) bool

AlmostEquals We use a solution similar to istio: Given an offset, calculate whether the actual value is within the offset of the expected value

func BackendMustBeAccepted

func BackendMustBeAccepted(t *testing.T, client client.Client, backendName types.NamespacedName)

BackendMustBeAccepted waits for the specified Backend to be accepted.

func BackendTrafficPolicyMustBeAccepted

func BackendTrafficPolicyMustBeAccepted(t *testing.T, client client.Client, policyName types.NamespacedName, controllerName string, ancestorRef gwapiv1.ParentReference)

BackendTrafficPolicyMustBeAccepted waits for the specified BackendTrafficPolicy to be accepted.

func BackendTrafficPolicyMustFail

func BackendTrafficPolicyMustFail(
	t *testing.T, client client.Client, policyName types.NamespacedName,
	controllerName string, ancestorRef gwapiv1.ParentReference, message string,
)

BackendTrafficPolicyMustFail waits for an BackendTrafficPolicy to fail with the specified reason.

func ClientTrafficPolicyMustBeAccepted

func ClientTrafficPolicyMustBeAccepted(t *testing.T, client client.Client, policyName types.NamespacedName, controllerName string, ancestorRef gwapiv1.ParentReference)

ClientTrafficPolicyMustBeAccepted waits for the specified ClientTrafficPolicy to be accepted.

func CollectAndDump

func CollectAndDump(t *testing.T, rest *rest.Config)

CollectAndDump collects and dumps the cluster data for troubleshooting and log. This function should be call within t.Cleanup.

func ContentEncoding

func ContentEncoding(compressorType egv1a1.CompressorType) string

func CreateBackend

func CreateBackend(c client.Client, nn types.NamespacedName, clusterIP string, port int32) error

func DeleteBackend

func DeleteBackend(c client.Client, nn types.NamespacedName) error

func EnabledClusterTrustBundle

func EnabledClusterTrustBundle() bool

TODO: remove this when the min version EG supported is v1.33

func EnvoyExtensionPolicyMustBeAccepted

func EnvoyExtensionPolicyMustBeAccepted(t *testing.T, client client.Client, policyName types.NamespacedName, controllerName string, ancestorRef gwapiv1.ParentReference)

EnvoyExtensionPolicyMustBeAccepted waits for the specified EnvoyExtensionPolicy to be accepted.

func EnvoyExtensionPolicyMustFail

func EnvoyExtensionPolicyMustFail(
	t *testing.T, client client.Client, policyName types.NamespacedName,
	controllerName string, ancestorRef gwapiv1.ParentReference, message string,
)

EnvoyExtensionPolicyMustFail waits for an EnvoyExtensionPolicy to fail with the specified reason.

func ExpectEnvoyProxyDeploymentCount

func ExpectEnvoyProxyDeploymentCount(t *testing.T, suite *suite.ConformanceTestSuite, gwNN types.NamespacedName, expectedNs string, expectedCount int)

func ExpectEnvoyProxyHPACount

func ExpectEnvoyProxyHPACount(t *testing.T, suite *suite.ConformanceTestSuite, gwNN types.NamespacedName, expectedNs string, expectedCount int)

func ExpectRequestTimeout

func ExpectRequestTimeout(t *testing.T, suite *suite.ConformanceTestSuite, gwAddr, path, query string, exceptedStatusCode int)

func GetGatewayResourceNamespace

func GetGatewayResourceNamespace() string

func GetService

func GetService(c client.Client, nn types.NamespacedName) (*corev1.Service, error)

func IsGatewayNamespaceMode

func IsGatewayNamespaceMode() bool

func OverLimitCount

func OverLimitCount(suite *suite.ConformanceTestSuite) (int, error)

func QueryLogCountFromLoki

func QueryLogCountFromLoki(t *testing.T, c client.Client, keyValues map[string]string, match string) (int, error)

QueryLogCountFromLoki queries log count from loki

func RetrieveMetric

func RetrieveMetric(url, name string, timeout time.Duration) (*dto.MetricFamily, error)

func RetrieveMetrics

func RetrieveMetrics(url string, timeout time.Duration) (map[string]*dto.MetricFamily, error)

func RetrieveURL

func RetrieveURL(c client.Client, nn types.NamespacedName, port int32, path string) (string, error)

func ScrapeMetrics

func ScrapeMetrics(t *testing.T, c client.Client, nn types.NamespacedName, port int32, path string) error

ScrapeMetrics TODO: use QueryPrometheus from test/e2e/tests/promql.go instead

func SecurityPolicyMustBeAccepted

func SecurityPolicyMustBeAccepted(t *testing.T, client client.Client, policyName types.NamespacedName, controllerName string, ancestorRef gwapiv1.ParentReference)

SecurityPolicyMustBeAccepted waits for the specified SecurityPolicy to be accepted.

func SecurityPolicyMustBeMerged

func SecurityPolicyMustBeMerged(t *testing.T, client client.Client, policyName types.NamespacedName, controllerName string, ancestorRef gwapiv1.ParentReference)

SecurityPolicyMustBeMerged waits for the specified SecurityPolicy to have Merged condition.

func SecurityPolicyMustFail

func SecurityPolicyMustFail(
	t *testing.T, client client.Client, policyName types.NamespacedName,
	controllerName string, ancestorRef gwapiv1.ParentReference, message string,
)

SecurityPolicyMustFail waits for an SecurityPolicy to fail with the specified reason.

func SecurityPolicyMustNotExist

func SecurityPolicyMustNotExist(t *testing.T, client client.Client, policyName types.NamespacedName)

SecurityPolicyMustNotExist waits for the specified SecurityPolicy to be deleted.

func ServiceHost

func ServiceHost(c client.Client, nn types.NamespacedName, port int32) (string, error)

func TimeoutConfig

func TimeoutConfig() config.TimeoutConfig

TimeoutConfig returns the default TimeoutConfig for E2E tests. We need this to reduce the logs in CI because of https://github.com/kubernetes-sigs/gateway-api/pull/4630

func UseStandardChannel

func UseStandardChannel() bool

func WaitForLoadBalancerAddress

func WaitForLoadBalancerAddress(t *testing.T, client client.Client, timeout time.Duration, nn types.NamespacedName) (string, error)

func WaitForPods

func WaitForPods(t *testing.T, cl client.Client, namespace string, selectors map[string]string, phase corev1.PodPhase, condition *corev1.PodCondition)

WaitForPods waits for the pods in the given namespace and with the given selector to be in the given phase and condition.

func XDSNameSchemeV2

func XDSNameSchemeV2() bool

TODO(zhaohuabing) remove this after the feature flag is removed.

Types

type AddressMappings

type AddressMappings struct {
	// contains filtered or unexported fields
}

AddressMappings is a custom dialer that resolves specific host:port to specific target addresses.

func (*AddressMappings) DialContext

func (a *AddressMappings) DialContext(ctx context.Context, network, addr string) (net.Conn, error)

DialContext is a custom dialer that resolves specific host:port to specific target addresses.

type CookieTracker

type CookieTracker struct {
	Delegate http.RoundTripper
	Cookies  map[string]*http.Cookie
}

CookieTracker is a http.RoundTripper that tracks cookies received from the server.

func (*CookieTracker) RoundTrip

func (c *CookieTracker) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip tracks the cookies received from the server.

type LoggingRoundTripper

type LoggingRoundTripper struct {
	LogFunc  func(...any)
	LogBody  bool
	Delegate http.RoundTripper
}

LoggingRoundTripper is a http.RoundTripper that logs requests and responses.

func (LoggingRoundTripper) RoundTrip

func (l LoggingRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip logs all the requests and responses using the configured settings.

type LokiQueryResponse

type LokiQueryResponse struct {
	Status string `json:"status"`
	Data   struct {
		ResultType string `json:"resultType"`
		Result     []struct {
			Metric interface{}
			Values []interface{} `json:"values"`
		}
	}
}

type OIDCTestClient

type OIDCTestClient struct {
	// contains filtered or unexported fields
}

OIDCTestClient encapsulates a http.Client and keeps track of the state of the OIDC login process.

func NewOIDCTestClient

func NewOIDCTestClient(opts ...Option) (*OIDCTestClient, error)

NewOIDCTestClient creates a new OIDCTestClient.

func (*OIDCTestClient) Get

func (o *OIDCTestClient) Get(url string, followDirection bool) (*http.Response, error)

Get sends a GET request to the specified URL.

func (*OIDCTestClient) Login

func (o *OIDCTestClient) Login(formData map[string]string) (*http.Response, error)

Login logs in to the IdP using the provided credentials.

func (*OIDCTestClient) ParseLoginForm

func (o *OIDCTestClient) ParseLoginForm(responseBody io.ReadCloser, formID string) error

ParseLoginForm parses the HTML response body to get the URL where the login page would post the user-entered credentials.

func (*OIDCTestClient) Send

func (o *OIDCTestClient) Send(req *http.Request, followRedirect bool) (*http.Response, error)

Send sends the specified request.

type Option

type Option func(*OIDCTestClient) error

Option is a functional option for configuring the OIDCTestClient.

func WithCustomAddressMappings

func WithCustomAddressMappings(mappings map[string]string) Option

WithCustomAddressMappings configures the OIDCTestClient to resolve specific host:port to specific target addresses.

func WithLoggingOptions

func WithLoggingOptions(logFunc func(...any), logBody bool) Option

WithLoggingOptions configures the OIDCTestClient to log requests and responses.

Jump to

Keyboard shortcuts

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