e2e

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: Apache-2.0 Imports: 32 Imported by: 0

README

e2e tests

Each directory is an end-to-end test suite that is self-contained and can be run independently. Refer to the Developer Guide for more information on how to run these tests.

Documentation

Index

Constants

View Source
const (
	// KubeConfig is the path where the e2e test setup generates the kubeconfig file
	KubeConfig = "cluster/kubeconfig"
)

Variables

View Source
var (
	PodReady       = corev1.PodCondition{Type: corev1.PodReady, Status: corev1.ConditionTrue}
	PodInitialized = corev1.PodCondition{Type: corev1.PodInitialized, Status: corev1.ConditionTrue}
)

Functions

func NoopLogFunc

func NoopLogFunc(...any)

NoopLogFunc is a log function that does nothing

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.

func (*AddressMappings) DialTLSContext

func (a *AddressMappings) DialTLSContext(tlsConfig *tls.Config) func(context.Context, string, string) (net.Conn, error)

DialTLSContext 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 DockerCompose

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

DockerCompose is a helper to interact with docker compose command

func NewDockerCompose

func NewDockerCompose(opts ...DockerComposeOption) DockerCompose

NewDockerCompose creates a new DockerCompose with the given options

func (DockerCompose) StartDockerService

func (d DockerCompose) StartDockerService(name string) error

StartDockerService starts a docker service or returns an error

func (DockerCompose) StopDockerService

func (d DockerCompose) StopDockerService(name string) error

StopDockerService stops a docker service or returns an error

func (DockerCompose) WaitForDockerService

func (d DockerCompose) WaitForDockerService(name string, status DockerServiceStatus, timeout, tick time.Duration) error

WaitForDockerService waits for a docker service to match a status in the given timeout or returns an error

type DockerComposeOption

type DockerComposeOption func(compose *DockerCompose)

DockerComposeOption is a functional option for DockerCompose initialization

func WithDockerComposeLogFunc

func WithDockerComposeLogFunc(logFunc func(...any)) DockerComposeOption

WithDockerComposeLogFunc sets the log function for the DockerCompose. The default is NoopLogFunc

type DockerServiceStatus

type DockerServiceStatus interface {
	// Match returns true if the status matches the given docker service status
	Match(string) bool
	// String returns a string representation of the status
	String() string
}

DockerServiceStatus is an interface that matches the status of a docker service

var (
	// DockerServiceExited is a DockerServiceStatus that matches the state "Exited"
	DockerServiceExited DockerServiceStatus = containsMatcher{"Exited"}
	// DockerServiceContainerUp is a DockerServiceStatus that matches the state "Up"
	DockerServiceContainerUp DockerServiceStatus = containsMatcher{"Up"}
	// DockerServiceContainerUpAndHealthy is a DockerServiceStatus that matches the state "Up (healthy)"
	DockerServiceContainerUpAndHealthy DockerServiceStatus = containsMatcher{"(healthy)"}
)

type K8sSuite

type K8sSuite struct {
	suite.Suite

	Kubeconfig *rest.Config
	// contains filtered or unexported fields
}

K8sSuite is a suite that provides a Kubernetes client and a set of helper methods to interact with the Kubernetes API. Kubernetes tests can crete specific suite types that embeds this one to get access to the Kubernetes client and the helper methods.

func (*K8sSuite) Apply

func (k *K8sSuite) Apply(ctx context.Context, file string) error

Apply the given file to the Kubernetes cluster.

func (*K8sSuite) Delete

func (k *K8sSuite) Delete(ctx context.Context, file string) error

Delete the resources defined in the given file from the Kubernetes cluster.

func (*K8sSuite) MustApply

func (k *K8sSuite) MustApply(ctx context.Context, file string)

MustApply applies the given file to the Kubernetes cluster and fails the test if an error occurs.

func (*K8sSuite) MustDelete

func (k *K8sSuite) MustDelete(ctx context.Context, file string)

MustDelete deletes the resources defined in the given file from the Kubernetes cluster and fails the test if an error occurs.

func (*K8sSuite) ReadObjects

func (k *K8sSuite) ReadObjects(file string) []*unstructured.Unstructured

ReadObjects reads the given file and returns the list of Kubernetes objects defined in it.

func (*K8sSuite) SetupSuite

func (k *K8sSuite) SetupSuite()

SetupSuite initializes the Kubernetes clients.

func (*K8sSuite) WaitForPods

func (k *K8sSuite) WaitForPods(client kubernetes.Interface, namespace, selector 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.

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 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) (*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) Logout

func (o *OIDCTestClient) Logout() (*http.Response, error)

Logout logs out from the IdP.

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) ParseLogoutForm

func (o *OIDCTestClient) ParseLogoutForm(responseBody io.ReadCloser) error

ParseLogoutForm parses the HTML response body to get the URL where the logout page would post the session logout.

func (*OIDCTestClient) Send

func (o *OIDCTestClient) Send(req *http.Request) (*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 WithBaseURL

func WithBaseURL(idpBaseURL string) Option

WithBaseURL configures the OIDCTestClient to use the specified IdP base url. Required when the form action URL is relative. For example the logout one.

func WithCustomAddressMappings

func WithCustomAddressMappings(mappings map[string]string) Option

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

func WithCustomCA

func WithCustomCA(caCert string) Option

WithCustomCA configures the OIDCTestClient to use a custom CA bundle to verify certificates.

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