framework

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2022 License: Apache-2.0 Imports: 67 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TestConfig *testConfig

Functions

func AdmitWorkspaceAccess added in v0.6.0

func AdmitWorkspaceAccess(t *testing.T, ctx context.Context, kubeClusterClient kubernetesclient.Interface, orgClusterName logicalcluster.Name, users []string, groups []string, verbs []string)

AdmitWorkspaceAccess create RBAC rules that allow the given users and/or groups to access the given, fully-qualified workspace, i.e. the RBAC objects are create in its parent.

func ConfigWithToken added in v0.6.0

func ConfigWithToken(token string, cfg *rest.Config) *rest.Config

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 DirectOrGoRunCommand added in v0.6.0

func DirectOrGoRunCommand(executableName string) []string

DirectOrGoRunCommand returns the string tokens required to start the given executable in the currently configured mode (direct or via `go run`).

func Eventually added in v0.6.0

func Eventually(t *testing.T, condition func() (success bool, reason string), waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{})

Eventually asserts that given condition will be met in waitFor time, periodically checking target function each tick. In addition to require.Eventually, this function t.Logs the raason string value returned by the condition function (eventually after 20% of the wait time) to aid in debugging.

func EventuallyReady added in v0.6.0

func EventuallyReady(t *testing.T, getter func() (conditions.Getter, error), msgAndArgs ...interface{})

EventuallyReady asserts that the object returned by getter() eventually has a ready condition

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 KcpCliPluginCommand added in v0.6.0

func KcpCliPluginCommand() []string

KcpCliPluginCommand returns the cli args to run the workspace plugin directly or via go run (depending on whether NO_GORUN is set).

func Kubectl added in v0.6.0

func Kubectl(t *testing.T, kubeconfigPath string, args ...string) []byte

Kubectl runs kubectl with the given arguments and returns the combined stderr and stdout.

func KubectlApply added in v0.6.0

func KubectlApply(t *testing.T, kubeconfigPath string, input []byte) []byte

KubectlApply runs kubectl apply -f with the supplied input piped to stdin and returns the combined stderr and stdout output.

func LogToConsoleEnvSet added in v0.6.0

func LogToConsoleEnvSet() bool

func LogicalClusterRawConfig added in v0.6.0

func LogicalClusterRawConfig(rawConfig clientcmdapi.Config, logicalClusterName logicalcluster.Name, contextName string) clientcmdapi.Config

LogicalClusterRawConfig returns the raw cluster config of the given config.

func NewOrganizationFixture added in v0.6.0

func NewOrganizationFixture(t *testing.T, server RunningServer, options ...ClusterWorkspaceOption) (orgClusterName logicalcluster.Name)

func NewSyncerFixture added in v0.7.0

func NewSyncerFixture(t *testing.T, server RunningServer, clusterName logicalcluster.Name, opts ...SyncerOption) *syncerFixture

func NewWorkspaceFixture added in v0.6.0

func NewWorkspaceFixture(t *testing.T, server RunningServer, orgClusterName logicalcluster.Name, options ...ClusterWorkspaceOption) (clusterName logicalcluster.Name)

func NoGoRunEnvSet added in v0.6.0

func NoGoRunEnvSet() bool

func Ready

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

Ready blocks until the server is healthy and ready.

func RepositoryBinDir added in v0.6.0

func RepositoryBinDir() string

RepositoryBinDir returns the absolute path of <repo-dir>/bin. That's where `make build` produces our binaries.

func RepositoryDir added in v0.6.0

func RepositoryDir() string

RepositoryDir returns the absolute path of <repo-dir>.

func RunInProcess

func RunInProcess(o *runOptions)

func RunKcpCliPlugin added in v0.6.0

func RunKcpCliPlugin(t *testing.T, kubeconfigPath string, subcommand []string) []byte

RunKcpCliPlugin runs the kcp workspace plugin with the provided subcommand and returns the combined stderr and stdout output.

func ScratchDirs

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

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

func ShardConfig added in v0.6.0

func ShardConfig(t *testing.T, kcpClusterClient kcpclient.Interface, shardName string, cfg *rest.Config) *rest.Config

ShardConfig returns a rest config that talk directly to the given shard.

func StartKcpCommand added in v0.6.0

func StartKcpCommand() []string

StartKcpCommand returns the string tokens required to start kcp in the currently configured mode (direct or via `go run`).

func TestServerArgs added in v0.6.0

func TestServerArgs() []string

TestServerArgs returns the set of kcp args used to start a test server using the token auth file from the working tree.

func TestServerArgsWithTokenAuthFile added in v0.6.0

func TestServerArgsWithTokenAuthFile(tokenAuthFile string) []string

TestServerArgsWithTokenAuthFile returns the set of kcp args used to start a test server with the given token auth file.

func UniqueGroup added in v0.7.0

func UniqueGroup(suffix string) string

UniqueGroup returns a unique API group with the given suffix by prefixing some random 8 character base36 string. suffix must start with a dot if the random string should be dot-separated.

func UserConfig added in v0.6.0

func UserConfig(username string, cfg *rest.Config) *rest.Config

func WithLogStreaming

func WithLogStreaming(o *runOptions)

func WriteLogicalClusterConfig added in v0.6.0

func WriteLogicalClusterConfig(t *testing.T, rawConfig clientcmdapi.Config, contextName string, clusterName logicalcluster.Name) (clientcmd.ClientConfig, string)

WriteLogicalClusterConfig creates a logical cluster config for the given config and cluster name and writes it to the test's artifact path. Useful for configuring the workspace plugin with --kubeconfig.

func WriteTokenAuthFile added in v0.6.0

func WriteTokenAuthFile(t *testing.T) string

WriteTokenAuthFile writes the embedded token file to the current test's data dir.

Persistent servers can target the file in the source tree with `--token-auth-file` and test-managed servers can target a file written to a temp path. This avoids requiring a test to know the location of the token file.

TODO(marun) Is there a way to avoid embedding by determining the path to the file during test execution?

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, name string, cmd ...string) *Accessory

NewAccessory creates a new accessory process.

func (*Accessory) Run

func (a *Accessory) Run(t *testing.T, opts ...RunOption) error

type ArtifactFunc added in v0.6.0

type ArtifactFunc func(*testing.T, func() (runtime.Object, error))

type ClusterWorkspaceExpectation added in v0.6.0

type ClusterWorkspaceExpectation func(*tenancyv1alpha1.ClusterWorkspace) error

ClusterWorkspaceExpectation evaluates an expectation about the object.

type ClusterWorkspaceOption added in v0.6.0

type ClusterWorkspaceOption func(ws *tenancyv1alpha1.ClusterWorkspace)

func WithName added in v0.6.0

func WithName(s string, formatArgs ...interface{}) ClusterWorkspaceOption

func WithShardConstraints added in v0.6.0

func WithType added in v0.6.0

func WithType(path logicalcluster.Name, name tenancyv1alpha1.ClusterWorkspaceTypeName) ClusterWorkspaceOption

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 ExpectationController added in v0.6.0

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

ExpectationController knows how to register expectations and trigger them

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 (*ExpectationController) ExpectBefore added in v0.6.0

func (c *ExpectationController) ExpectBefore(ctx context.Context, expectation Expectation, duration time.Duration) error

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 RegisterClusterWorkspaceExpectation added in v0.6.0

type RegisterClusterWorkspaceExpectation func(seed *tenancyv1alpha1.ClusterWorkspace, expectation ClusterWorkspaceExpectation) error

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

func ExpectClusterWorkspaces added in v0.6.0

func ExpectClusterWorkspaces(ctx context.Context, t *testing.T, client kcpclient.Interface) (RegisterClusterWorkspaceExpectation, error)

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

type RegisterWorkspaceShardExpectation

type RegisterWorkspaceShardExpectation func(seed *tenancyv1alpha1.ClusterWorkspaceShard, 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 kcpclient.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)
	BaseConfig(t *testing.T) *rest.Config
	RootShardSystemMasterBaseConfig(t *testing.T) *rest.Config
	Artifact(t *testing.T, producer func() (runtime.Object, error))
}

func NewFakeWorkloadServer added in v0.6.0

func NewFakeWorkloadServer(t *testing.T, server RunningServer, org logicalcluster.Name) RunningServer

NewFakeWorkloadServer creates a workspace in the provided server and org and creates a server fixture for the logical cluster that results.

func PrivateKcpServer added in v0.6.0

func PrivateKcpServer(t *testing.T, args ...string) RunningServer

PrivateKcpServer returns a new kcp server fixture managing a new server process that is not intended to be shared between tests.

func SharedKcpServer added in v0.6.0

func SharedKcpServer(t *testing.T) RunningServer

SharedKcpServer returns a kcp server fixture intended to be shared between tests. A persistent server will be configured if `--kcp-kubeconfig` or `--use-default-kcp-server` is supplied to the test runner. Otherwise a test-managed server will be started. Only tests that are known to be hermetic are compatible with shared fixture.

type StartedSyncerFixture added in v0.6.0

type StartedSyncerFixture struct {
	SyncerConfig *syncer.SyncerConfig

	// Provide cluster-admin config and client for test purposes. The downstream config in
	// SyncerConfig will be less privileged.
	DownstreamConfig     *rest.Config
	DownstreamKubeClient kubernetesclient.Interface
}

StartedSyncerFixture contains the configuration used to start a syncer and interact with its downstream cluster.

func (*StartedSyncerFixture) WaitForClusterReady added in v0.7.0

func (sf *StartedSyncerFixture) WaitForClusterReady(t *testing.T, ctx context.Context)

WaitForClusterReady waits for the cluster to be ready with the given reason.

type SyncTargetOption added in v0.6.0

type SyncTargetOption func(cluster *workloadv1alpha1.SyncTarget)

type SyncerOption added in v0.7.0

type SyncerOption func(t *testing.T, fs *syncerFixture)

func WithDownstreamPreparation added in v0.7.0

func WithDownstreamPreparation(prepare func(config *rest.Config, isFakePCluster bool)) SyncerOption

func WithExtraResources added in v0.7.0

func WithExtraResources(resources ...string) SyncerOption

func WithSyncTarget added in v0.7.0

func WithSyncTarget(clusterName logicalcluster.Name, name string) SyncerOption

type WorkspaceShardExpectation

type WorkspaceShardExpectation func(*tenancyv1alpha1.ClusterWorkspaceShard) 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