Documentation
¶
Index ¶
- func DefaultJWKS() []byte
- func LocalhostCertificate() tls.Certificate
- func LocalhostCertificateFiles() (certFile, keyFile, caFile string)
- func MakeClaims() jwt.MapClaims
- func MakeTCPServer() *ghttp.Server
- func MakeTCPTLSServer() (server *ghttp.Server, ca string)
- func MakeTokenObject(claims jwt.MapClaims) *jwt.Token
- func MakeTokenString(typ string, life time.Duration) string
- func MatchLine(regexp string, args ...any) OmegaMatcher
- func RespondWithContent(status int, contentType, body string) http.HandlerFunc
- func RespondWithJSON(status int, body string) http.HandlerFunc
- func RespondWithObject(object any) http.HandlerFunc
- func TmpFS(args ...any) (dir string, fsys fs.FS)
- type Command
- type CommandBuilder
- func (b *CommandBuilder) AddArgs(args ...string) *CommandBuilder
- func (b *CommandBuilder) Build() (result *Command, err error)
- func (b *CommandBuilder) SetArgs(args ...string) *CommandBuilder
- func (b *CommandBuilder) SetDir(value string) *CommandBuilder
- func (b *CommandBuilder) SetHome(value string) *CommandBuilder
- func (b *CommandBuilder) SetLogger(value *slog.Logger) *CommandBuilder
- func (b *CommandBuilder) SetName(name string) *CommandBuilder
- func (b *CommandBuilder) SetQuiet(value bool) *CommandBuilder
- type Database
- type DatabaseServer
- type Kind
- func (k *Kind) Client() crclient.WithWatch
- func (k *Kind) ClientSet() *kubernetes.Clientset
- func (k *Kind) Dump(ctx context.Context, dir string) error
- func (k *Kind) Exists(ctx context.Context) (result bool, err error)
- func (k *Kind) Kubeconfig() []byte
- func (k *Kind) LoadArchive(ctx context.Context, archive string) error
- func (k *Kind) LoadImage(ctx context.Context, image string) error
- func (k *Kind) Start(ctx context.Context) error
- func (k *Kind) Stop(ctx context.Context) error
- type KindBuilder
- func (b *KindBuilder) AddCrdFile(file string) *KindBuilder
- func (b *KindBuilder) Build() (result *Kind, err error)
- func (b *KindBuilder) SetHome(value string) *KindBuilder
- func (b *KindBuilder) SetLogger(value *slog.Logger) *KindBuilder
- func (b *KindBuilder) SetName(name string) *KindBuilder
- func (b *KindBuilder) SetQuiet(value bool) *KindBuilder
- type MetricsServer
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 LocalhostCertificateFiles ¶
func LocalhostCertificateFiles() (certFile, keyFile, caFile string)
LocalhostCertificateFiles returns the paths to three temporary files containing the certificate, private key and CA certificate returned by LocalhostCertificate. All files are PEM encoded. Since the certificate is self-signed, the CA file contains the same certificate. It is the responsibility of the caller to delete these files when they are no longer needed.
func MakeClaims ¶
MakeClaims generates a default set of claims to be used to issue a token.
func MakeTCPServer ¶
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 ¶
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 ¶
MakeTokenObject generates a token with the claims resulting from merging the default claims and the claims explicitly given.
func MakeTokenString ¶
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 MatchLine ¶
MatchLine succeeds if actual is a slice of strings that contains at least one item that matches the passed regular expression.
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.
func TmpFS ¶
TmpFS creates a temporary directory containing the given files, and then creates a fs.FS object that can be used to access it.
The files are specified as pairs of full path names and content. For example, to create a file named `mydir/myfile.yaml` containig some YAML text and a file `yourdir/yourfile.json` containing some JSON text:
dir, fsys = TmpFS(
"mydir/myfile.yaml",
`
name: Joe
age: 52
`,
"yourdir/yourfile.json",
`{
"name": "Mary",
"age": 59
}`
)
Directories are created automatically when they contain at least one file or subdirectory.
The caller is responsible for removing the directory once it is no longer needed.
Types ¶
type Command ¶
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.
type CommandBuilder ¶
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 ¶
func NewCommand() *CommandBuilder
NewCommand creates a builder that can then be used to configure and create a new command.
func (*CommandBuilder) AddArgs ¶
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 ¶
func (b *CommandBuilder) Build() (result *Command, err error)
func (*CommandBuilder) SetArgs ¶
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 ¶
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) SetHome ¶
func (b *CommandBuilder) SetHome(value string) *CommandBuilder
SetHome sets the project home directory. This is optional, and it is used to shorten the directory in log messages when it is a subdirectory of the project home directory, replacing it with '~'. This is used to make log messages more readable.
func (*CommandBuilder) SetLogger ¶
func (b *CommandBuilder) SetLogger(value *slog.Logger) *CommandBuilder
SetLogger sets the logger. This is mandatory.
func (*CommandBuilder) SetName ¶
func (b *CommandBuilder) SetName(name string) *CommandBuilder
SetName sets the name of the command. This is mandatory.
func (*CommandBuilder) SetQuiet ¶
func (b *CommandBuilder) SetQuiet(value bool) *CommandBuilder
SetQuiet sets whether the command output should be quiet. When quiet is true (the default), the command output is buffered and only logged if the command fails. When quiet is false, each line of output is logged as it happens. This is useful to avoid flooding the logs with output that is not of interest.
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database is a PostgreSQL database.
func (*Database) MakeHandle ¶
MakeHandle creates a new database handle 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) MakeDatabase ¶
func (s *DatabaseServer) MakeDatabase() *Database
MakeDatabase creates a new database.
type Kind ¶
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) ClientSet ¶
func (k *Kind) ClientSet() *kubernetes.Clientset
ClientSet returns the Kubernetes set client for the cluster.
func (*Kind) Dump ¶
Dump uses 'kubectl cluster-info dump' to dump the state and logs of all namespaces to the specified directory. If the directory already exists, all its contents will be removed before dumping. If it doesn't exist, it will be created.
func (*Kind) Kubeconfig ¶
Kubeconfig returns the kubeconfig bytes.
func (*Kind) LoadArchive ¶
LoadArchive loads the specified image archive into the Kind cluster.
func (*Kind) LoadImage ¶
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.
type KindBuilder ¶
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 ¶
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 ¶
func (b *KindBuilder) AddCrdFile(file string) *KindBuilder
AddCrdFile adds a file containing custom resource definition to be installed in the cluster.
func (*KindBuilder) Build ¶
func (b *KindBuilder) Build() (result *Kind, err error)
Build uses the configuration stored in the builder to create a new Kind cluster
func (*KindBuilder) SetHome ¶
func (b *KindBuilder) SetHome(value string) *KindBuilder
SetHome sets the project home directory. This is optional, and it is used to shorten the directory in log messages when it is a subdirectory of the project home directory, replacing it with '~'. This is used to make log messages more readable.
func (*KindBuilder) SetLogger ¶
func (b *KindBuilder) SetLogger(value *slog.Logger) *KindBuilder
SetLogger sets the logger. This is mandatory.
func (*KindBuilder) SetName ¶
func (b *KindBuilder) SetName(name string) *KindBuilder
SetName sets the name of the Kind cluster. This is mandatory.
func (*KindBuilder) SetQuiet ¶
func (b *KindBuilder) SetQuiet(value bool) *KindBuilder
SetQuiet sets whether the output of the command executed to manage the cluster should be quiet. When quiet is true (the default), the command output is buffered and only logged if the command fails. When quiet is false, each line of output is logged as it happens. This is useful to avoid flooding the logs with output that is not of interest.
type MetricsServer ¶
type MetricsServer struct {
// contains filtered or unexported fields
}
MetricsServer is an HTTP server configured to return Prometheus metrics. Don't create objects of this type directly, use the NewMetricsServer function instead.
func NewMetricsServer ¶
func NewMetricsServer() *MetricsServer
NewMetricsServer creates a metrics server.
func (*MetricsServer) Close ¶
func (s *MetricsServer) Close()
Close stops the server and releases the resources it uses.
func (*MetricsServer) Metrics ¶
func (s *MetricsServer) Metrics() []string
Metrics returns an array of strings containing the metrics available in this server. Each item in this array is a line in the Prometheus exposition format. This is intended to be used together with the MatchLine matcher.
func (*MetricsServer) Registry ¶
func (s *MetricsServer) Registry() prometheus.Registerer
Registry returns the registry that should be used to register metrics for this server.