framework

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2022 License: Apache-2.0 Imports: 56 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareWithFixture

func CompareWithFixture(t *testing.T, output interface{}, opts ...Option)

CompareWithFixture will compare output with a test fixture and allows to automatically update them by setting the UPDATE env var. If output is not a []byte or string, it will get serialized as yaml prior to the comparison. The fixtures are stored in $PWD/testdata/prefix${testName}.yaml

func CreateTempDirForTest

func CreateTempDirForTest(t *testing.T, dirName string) (string, error)

createTempDirForTest creates the named directory with a unique base path derived from the name of the current test.

func DetectClusterName

func DetectClusterName(cfg *rest.Config, ctx context.Context, crdName string) (string, error)

DetectClusterName returns the name of the cluster that contains the desired CRD. TODO: we need to undo the prefixing and get normal sharding behavior in soon ... ?

func GetClientForServer

func GetClientForServer(ctx context.Context, server RunningServer, crdName string) (kubernetesclientset.Interface, error)

GetClientForServer returns a kubernetes clientset for a given server.

func GetFreePort

func GetFreePort(t *testing.T) (string, error)

GetFreePort asks the kernel for a free open port that is ready to use.

func InProcessEnvSet

func InProcessEnvSet() bool

func InstallCluster

func InstallCluster(t *testing.T, ctx context.Context, source, server RunningServer, crdName, clusterName string) error

InstallCluster creates a new Cluster resource with the desired name on a given server and waits for it to be ready.

func InstallCrd

func InstallCrd(ctx context.Context, gr metav1.GroupResource, servers map[string]RunningServer, embeddedResources embed.FS) error

InstallCrd installs a CRD on one or multiple servers.

func InstallNamespace

func InstallNamespace(ctx context.Context, server RunningServer, crdName, testNamespace string) error

InstallNamespace creates a new namespace into the desired server.

func NewExpecter

func NewExpecter(informer cache.SharedIndexInformer) *expectationController

NewExpecter creates a informer-driven registry of expectations, which will be triggered on every event that the informer ingests.

func NewPollingExpecter

func NewPollingExpecter(interval time.Duration) *expectationController

NewPollingExpecter creates a poll-driven registry of expectations, which will be triggered on every tick that the controller experiences. This is useful for resources which do not support WATCH and cannot use the expectationController

func ReadFromFixture

func ReadFromFixture(t *testing.T, identifier string) []byte

ReadFromFixture reads an input fixture file and returns the data

func Ready

func Ready(ctx context.Context, t *testing.T, port string) bool

Ready blocks until the server is healthy and ready.

func RequireDiff

func RequireDiff(t *testing.T, x, y interface{}, msgAndArgs ...interface{})

func RequireNoDiff

func RequireNoDiff(t *testing.T, x, y interface{}, msgAndArgs ...interface{})

func RunInProcess

func RunInProcess(o *runOptions)

func ScratchDirs

func ScratchDirs(t *testing.T) (string, string, error)

ScratchDirs determines where artifacts and data should live for a test server.

func WithLogStreaming

func WithLogStreaming(o *runOptions)

func WriteToFixture

func WriteToFixture(t *testing.T, identifier string, data []byte)

WriteToFixture reads an input fixture file and returns the data

Types

type Accessory

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

Accessory knows how to run an executable with arguments for the duration of the context.

func NewAccessory

func NewAccessory(t *testing.T, artifactDir string, cmd string, name string, args ...string) *Accessory

NewAccessory creates a new accessory process.

func (*Accessory) Run

func (a *Accessory) Run(parentCtx context.Context, opts ...RunOption) error

type Expectation

type Expectation func(ctx context.Context) (done bool, err error)

Expectation closes over a statement of intent, allowing the caller to accumulate errors and determine when the expectation should cease to be evaluated.

type Expecter

type Expecter interface {
	// ExpectBefore will result in the Expectation being evaluated whenever
	// state changes, up until the desired timeout is reached.
	ExpectBefore(context.Context, Expectation, time.Duration) error
}

Expecter allows callers to register expectations

type KcpConfig

type KcpConfig struct {
	Name string
	Args []string

	LogToConsole bool
	RunInProcess bool
}

KcpConfig qualify a kcp server to start

type KcpFixture

type KcpFixture struct {
	Servers map[string]RunningServer
}

KcpFixture manages the lifecycle of a set of kcp servers.

func NewKcpFixture

func NewKcpFixture(t *testing.T, cfgs ...KcpConfig) *KcpFixture

type Option

type Option func(*Options)

func WithExtension

func WithExtension(extension string) Option

func WithPrefix

func WithPrefix(prefix string) Option

func WithSuffix

func WithSuffix(suffix string) Option

type Options

type Options struct {
	Prefix    string
	Suffix    string
	Extension string
}

type RegisterWorkspaceExpectation

type RegisterWorkspaceExpectation func(seed *tenancyv1alpha1.Workspace, expectation WorkspaceExpectation) error

RegisterWorkspaceExpectation registers an expectation about the future state of the seed.

func ExpectWorkspaces

func ExpectWorkspaces(ctx context.Context, t *testing.T, client kcpclientset.Interface) (RegisterWorkspaceExpectation, error)

ExpectWorkspaces sets up an Expecter in order to allow registering expectations in tests with minimal setup.

type RegisterWorkspaceListExpectation

type RegisterWorkspaceListExpectation func(expectation WorkspaceListExpectation) error

RegisterWorkspaceListExpectation registers an expectation about the future state of the system.

func ExpectWorkspaceListPolling

func ExpectWorkspaceListPolling(ctx context.Context, t *testing.T, client kcpclientset.Interface) (RegisterWorkspaceListExpectation, error)

ExpectWorkspaceListPolling sets up an Expecter in order to allow registering expectations in tests with minimal setup.

type RegisterWorkspaceShardExpectation

type RegisterWorkspaceShardExpectation func(seed *tenancyv1alpha1.WorkspaceShard, expectation WorkspaceShardExpectation) error

RegisterWorkspaceShardExpectation registers an expectation about the future state of the seed.

func ExpectWorkspaceShards

func ExpectWorkspaceShards(ctx context.Context, t *testing.T, client kcpclientset.Interface) (RegisterWorkspaceShardExpectation, error)

ExpectWorkspaceShards sets up an Expecter in order to allow registering expectations in tests with minimal setup.

type RunOption

type RunOption func(o *runOptions)

type RunningServer

type RunningServer interface {
	Name() string
	KubeconfigPath() string
	RawConfig() (clientcmdapi.Config, error)
	Config() (*rest.Config, error)
	Artifact(t *testing.T, producer func() (runtime.Object, error))
}

type User

type User struct {
	Name   string
	Token  string
	UID    string
	Groups []string
}
var LoopbackUser User = User{
	Name: "loopback",
}

func (User) String

func (u User) String() string

type Users

type Users []User

func (Users) ArgsForKCP

func (us Users) ArgsForKCP(t *testing.T) ([]string, error)

type WorkspaceExpectation

type WorkspaceExpectation func(*tenancyv1alpha1.Workspace) error

WorkspaceExpectation evaluates an expectation about the object.

type WorkspaceListExpectation

type WorkspaceListExpectation func(*tenancyv1alpha1.WorkspaceList) error

WorkspaceListExpectation evaluates an expectation about the object.

type WorkspaceShardExpectation

type WorkspaceShardExpectation func(*tenancyv1alpha1.WorkspaceShard) error

WorkspaceShardExpectation evaluates an expectation about the object.

Jump to

Keyboard shortcuts

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