test

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

package test contains helpers for writing tests

Index

Constants

This section is empty.

Variables

View Source
var (

	// These variables are initialized if HasCluster succeeds.
	// Safe for use in tests after calling SkipIfNoCluster.
	RESTConfig *rest.Config
	K8sClient  client.WithWatch
	HTTPClient *http.Client
)

Functions

func ExecError

func ExecError(err error) error

ExecError extracts stderr if err is an exec.ExitError

func HasCluster

func HasCluster() error

func JSONPretty

func JSONPretty(v any) string

JSONPretty returns an indented JSON string, or error message if marshal fails.

func JSONString

func JSONString(v any) string

JSONString returns the JSON marshaled string from v, or the error message if marshal fails

func ListenPort

func ListenPort() (int, error)

ListenPort returns a free ephemeral port for listening.

func Must

func Must[T any](v T, err error) T

Must panics if err is not nil, else returns v.

func PanicErr

func PanicErr(err error)

PanicErr panics if err is not nil

func SkipIfNoCluster

func SkipIfNoCluster(t *testing.T)

SkipIfNoCluster calls t.Skip if no cluster is detected.

func SkipIfNoCommand

func SkipIfNoCommand(t *testing.T, cmd string)

SkipIfNoCommand skips a test if the cmd is not found in PATH

func TempNamespace

func TempNamespace(t *testing.T, c client.Client) string

TempNamespace creates a unique namespace.

func Watch

func Watch(t *testing.T, w watch.Interface, timeout time.Duration, f func(e watch.Event) (finished bool))

Watch in a loop, call f for each event, return when f returns true. Fatal if watch closes or times out

Types

type LokiServer

type LokiServer struct {
	Port        int
	ContainerID string
}

LokiServer is a single-process Loki instance running in a container.

func NewLokiServer

func NewLokiServer() (server *LokiServer, err error)

func RequireLokiServer

func RequireLokiServer(t *testing.T) *LokiServer

func (*LokiServer) Close

func (s *LokiServer) Close() error

func (*LokiServer) Push

func (s *LokiServer) Push(labels map[string]string, lines ...string) error

func (*LokiServer) URL

func (s *LokiServer) URL() *url.URL

Directories

Path Synopsis
package mock is a mock implementation of a korrel8r domain for testing.
package mock is a mock implementation of a korrel8r domain for testing.

Jump to

Keyboard shortcuts

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