testing

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2025 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultJWKS

func DefaultJWKS() []byte

DefaultJWKS generates the JSON web key set used for tests.

func LocalhostCertificate

func LocalhostCertificate() tls.Certificate

LocalhostCertificate returns a self signed TLS certificate valid for the name `localhost` DNS name, for the `127.0.0.1` IPv4 address and for the `::1` IPv6 address.

A similar certificate can be generated with the following command:

openssl req \
-x509 \
-newkey rsa:4096 \
-nodes \
-keyout tls.key \
-out tls.crt \
-subj '/CN=localhost' \
-addext 'subjectAltName=DNS:localhost,IP:127.0.0.1,IP:::1' \
-days 1

func MakeClaims

func MakeClaims() jwt.MapClaims

MakeClaims generates a default set of claims to be used to issue a token.

func MakeTCPServer

func MakeTCPServer() *ghttp.Server

MakeTCPServer creates a test server that listens in a TCP socket and configured so that it sends log messages to the Ginkgo writer.

func MakeTCPTLSServer

func MakeTCPTLSServer() (server *ghttp.Server, ca string)

MakeTCPTLSServer creates a test server configured so that it sends log messages to the Ginkgo writer. It returns the created server and the name of a temporary file that contains the CA certificate that the client should trust in order to connect to the server. It is the responsibility of the caller to delete this temporary file when it is no longer needed.

func MakeTokenObject

func MakeTokenObject(claims jwt.MapClaims) *jwt.Token

MakeTokenObject generates a token with the claims resulting from merging the default claims and the claims explicitly given.

func MakeTokenString

func MakeTokenString(typ string, life time.Duration) string

MakeTokenString generates a token issued by the default OpenID server and with the given type and with the given life. If the life is zero the token will never expire. If the life is positive the token will be valid, and expire after that time. If the life is negative the token will be already expired that time ago.

func RespondWithContent

func RespondWithContent(status int, contentType, body string) http.HandlerFunc

RespondeWithContent responds with the given status code, content type and body.

func RespondWithJSON

func RespondWithJSON(status int, body string) http.HandlerFunc

RespondWithJSON responds with the given status code and JSON body.

func RespondWithObject

func RespondWithObject(object any) http.HandlerFunc

RespondWithObject returns an HTTP handler that responds with a single object.

Types

type Command added in v0.0.7

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

Command helps manage execute a command line tool. Don't create instances of this type directly, use the NewCommand function instead.

func (*Command) Evaluate added in v0.0.7

func (c *Command) Evaluate(ctx context.Context) (stdoutBytes, stderrBytes []byte, err error)

Evaluate evalutes the command and returns the standard output and error as byte slices. It returns an error if the command fails.

func (*Command) Execute added in v0.0.7

func (c *Command) Execute(ctx context.Context) error

Execute executes the commands. It returns an error if the command fails.

type CommandBuilder added in v0.0.7

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

CommandBuilder contains the data and logic needed to create an object that helps execute a command line tool. Don't create instances of this type directly, use the NewCommand function instead.

func NewCommand added in v0.0.7

func NewCommand() *CommandBuilder

NewCommand creates a builder that can then be used to configure and create a new command.

func (*CommandBuilder) AddArgs added in v0.0.7

func (b *CommandBuilder) AddArgs(args ...string) *CommandBuilder

AddArgs adds the arguments for the command. Note that this appends to any previously set arguments with the SetArgs method. Arguments are optional, if not set no arguments will be used.

func (*CommandBuilder) Build added in v0.0.7

func (b *CommandBuilder) Build() (result *Command, err error)

Build creates the command object.

func (*CommandBuilder) SetArgs added in v0.0.7

func (b *CommandBuilder) SetArgs(args ...string) *CommandBuilder

SetArgs sets the arguments for the command. Note that this replaces any previously arguments added with the AddArgs /method. Arguments are optional, if not set no arguments will be used.

func (*CommandBuilder) SetDir added in v0.0.7

func (b *CommandBuilder) SetDir(value string) *CommandBuilder

SetDir sets the directory where the command will be executed. This is optional, if not set the current working directory will be used.

func (*CommandBuilder) SetLogger added in v0.0.7

func (b *CommandBuilder) SetLogger(value *slog.Logger) *CommandBuilder

SetLogger sets the logger. This is mandatory.

func (*CommandBuilder) SetName added in v0.0.7

func (b *CommandBuilder) SetName(name string) *CommandBuilder

SetName sets the name of the command. This is mandatory.

type Database

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

Database is a PostgreSQL database.

func (*Database) Close

func (d *Database) Close()

Close deletes the database.

func (*Database) MakeHandle

func (d *Database) MakeHandle() *sql.DB

MakeHandle creates a new database handle for this database.

func (*Database) MakeURL

func (d *Database) MakeURL() string

MakeURL calculates the URL for this database.

type DatabaseServer

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

DatabaseServer knows how to start a PostgreSQL database server inside a container, and how to create databases to be used for tests.

func MakeDatabaseServer

func MakeDatabaseServer() *DatabaseServer

MakeDatabaseServer creates a new database server.

func (*DatabaseServer) Close

func (s *DatabaseServer) Close()

Close stops the database server.

func (*DatabaseServer) MakeDatabase

func (s *DatabaseServer) MakeDatabase() *Database

MakeDatabase creates a new database.

type Kind added in v0.0.7

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

Kind helps manage a Kind cluster used for integration tests. Don't create instances of this type directly, use the NewKind function instead.

func (*Kind) Client added in v0.0.7

func (k *Kind) Client() crclient.WithWatch

Client returns the controller runtime client for the cluster.

func (*Kind) ClientSet added in v0.0.7

func (k *Kind) ClientSet() *kubernetes.Clientset

ClientSet returns the Kubernetes set client for the cluster.

func (*Kind) Kubeconfig added in v0.0.7

func (k *Kind) Kubeconfig() []byte

Kubeconfig returns the kubeconfig bytes.

func (*Kind) LoadArchive added in v0.0.7

func (k *Kind) LoadArchive(ctx context.Context, archive string) error

LoadArchive loads the specified image archive into the Kind cluster.

func (*Kind) LoadImage added in v0.0.7

func (k *Kind) LoadImage(ctx context.Context, image string) error

LoadImage loads the specified image into the Kind cluster.

Note that this will take the image from the local Docker daemon, regardless of what provider was used to create the cluster. For example, if the cluster was created with the Podman provider this wills still load the image from Docker.

func (*Kind) Start added in v0.0.7

func (k *Kind) Start(ctx context.Context) error

Start makes sure that the cluster is created and ready to use. It will remove the cluster if it already exists and will create a new one if it doesn't exist.

func (*Kind) Stop added in v0.0.7

func (k *Kind) Stop(ctx context.Context) error

Stop removes the Kind cluster.

type KindBuilder added in v0.0.7

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

KindBuilder contains the data and logic needed to create an object that helps manage a Kind cluster used for integration tests. Don't create instances of this type directly, use the NewKind function instead.

func NewKind added in v0.0.7

func NewKind() *KindBuilder

NewKind creates a builder that can then be used to configure and create a new Kind cluster used for integration tests.

func (*KindBuilder) AddCrdFile added in v0.0.7

func (b *KindBuilder) AddCrdFile(file string) *KindBuilder

AddCrdFile adds a file containing custom resource definition to be installed in the cluster.

func (*KindBuilder) Build added in v0.0.7

func (b *KindBuilder) Build() (result *Kind, err error)

Build uses the configuration stored in the builder to create a new Kind cluster

func (*KindBuilder) SetLogger added in v0.0.7

func (b *KindBuilder) SetLogger(value *slog.Logger) *KindBuilder

SetLogger sets the logger. This is mandatory.

func (*KindBuilder) SetName added in v0.0.7

func (b *KindBuilder) SetName(name string) *KindBuilder

SetName sets the name of the Kind cluster. This is mandatory.

Jump to

Keyboard shortcuts

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