framework

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 84 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(ctx context.Context, t *testing.T, kubeClusterClient kcpkubernetesclientset.ClusterInterface, clusterName logicalcluster.Path, users []string, groups []string, admin bool)

AdmitWorkspaceAccess create RBAC rules that allow the given users and/or groups to access the given workspace, optionally as admin.

func ClientCAUserConfig added in v0.11.0

func ClientCAUserConfig(t *testing.T, cfg *rest.Config, clientCAConfigDirectory, username string, groups ...string) *rest.Config

ClientCAUserConfig returns a config based on a dynamically created client certificate. The returned client CA is signed by "test/e2e/framework/client-ca.crt".

func ConfigWithToken added in v0.6.0

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

func CreateClientCA added in v0.11.0

func CreateClientCA(t *testing.T) (string, string)

func CreateResources added in v0.11.0

func CreateResources(ctx context.Context, fs embed.FS, upstreamConfig *rest.Config, clusterName logicalcluster.Path, transformers ...helpers.TransformFileFunc) error

CreateResources creates all resources from a filesystem in the given workspace identified by upstreamConfig.

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 reason string value returned by the condition function (eventually after 20% of the wait time) to aid in debugging.

func EventuallyCondition added in v0.11.0

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

EventuallyCondition asserts that the object returned by getter() eventually has a condition that matches the evaluator.

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 ExportVirtualWorkspaceURLs added in v0.11.0

func ExportVirtualWorkspaceURLs(export *apisv1alpha1.APIExport) []string

func GatherMetrics added in v0.11.0

func GatherMetrics(ctx context.Context, t *testing.T, server RunningServer, directory string)

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 LoadKubeConfig added in v0.11.0

func LoadKubeConfig(kubeconfigPath, contextName string) (clientcmd.ClientConfig, error)

LoadKubeConfig loads a kubeconfig from disk. This method is intended to be common between fixture for servers whose lifecycle is test-managed and fixture for servers whose lifecycle is managed separately from a test run.

func LogToConsoleEnvSet added in v0.6.0

func LogToConsoleEnvSet() bool

func LogicalClusterRawConfig added in v0.6.0

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

LogicalClusterRawConfig returns the raw cluster config of the given config.

func NewBindCompute added in v0.10.0

func NewBindCompute(t *testing.T, path logicalcluster.Path, server RunningServer, opts ...BindComputeOption) *bindCompute

func NewOrganizationFixture added in v0.6.0

func NewOrganizationFixture(t *testing.T, server RunningServer, options ...UnprivilegedWorkspaceOption) (logicalcluster.Path, *tenancyv1alpha1.Workspace)

func NewPrivilegedOrganizationFixture added in v0.11.0

func NewPrivilegedOrganizationFixture[O WorkspaceOption](t *testing.T, server RunningServer, options ...O) (logicalcluster.Path, *tenancyv1alpha1.Workspace)

func NewWorkspaceFixture added in v0.6.0

func NewWorkspaceFixture(t *testing.T, server RunningServer, parent logicalcluster.Path, options ...UnprivilegedWorkspaceOption) (logicalcluster.Path, *tenancyv1alpha1.Workspace)

func NoGoRunEnvSet added in v0.6.0

func NoGoRunEnvSet() bool

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 ScrapeMetrics added in v0.11.0

func ScrapeMetrics(ctx context.Context, cfg *rest.Config, promUrl, promCfgDir, jobName, caFile string, labels map[string]string) error

func ScrapeMetricsForServer added in v0.11.0

func ScrapeMetricsForServer(t *testing.T, srv RunningServer)

func ScratchDirs

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

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

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 StaticTokenUserConfig added in v0.11.0

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

StaticTokenUserConfig returns a user config based on static user tokens defined in "test/e2e/framework/auth-tokens.csv". The token being used is "[username]-token".

func Suite added in v0.10.0

func Suite(t *testing.T, suite string)

Suite should be called at the very beginning of a test case, to ensure that a test is only run when the suite containing it is selected by the user running tests.

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 TestServerWithAuditPolicyFile added in v0.9.0

func TestServerWithAuditPolicyFile(auditPolicyFile string) []string

TestServerWithAuditPolicyFile returns the set of kcp args used to start a test server with the given audit policy file.

func TestServerWithClientCAFile added in v0.11.0

func TestServerWithClientCAFile(clientCAFile string) []string

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 VirtualWorkspaceURL added in v0.11.0

func VirtualWorkspaceURL(ctx context.Context, kcpClusterClient kcpclientset.ClusterInterface, ws *tenancyv1alpha1.Workspace, urls []string) (string, bool, error)

func VirtualWorkspaceURLOrDie added in v0.11.0

func VirtualWorkspaceURLOrDie(t *testing.T, kcpClusterClient kcpclientset.ClusterInterface, ws *tenancyv1alpha1.Workspace, urls []string) string

func WaitForReady added in v0.11.0

func WaitForReady(ctx context.Context, t *testing.T, cfg *rest.Config, keepMonitoring bool) error

func WithLogStreaming

func WithLogStreaming(o *runOptions)

func WorkspaceShard added in v0.11.0

func WorkspaceShardOrDie added in v0.11.0

func WorkspaceShardOrDie(t *testing.T, kcpClient kcpclientset.ClusterInterface, ws *tenancyv1alpha1.Workspace) *corev1alpha1.Shard

func WriteEmbedFile added in v0.9.0

func WriteEmbedFile(t *testing.T, source string) string

func WriteLogicalClusterConfig added in v0.6.0

func WriteLogicalClusterConfig(t *testing.T, rawConfig clientcmdapi.Config, contextName string, clusterName logicalcluster.Path) (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 BindComputeOption added in v0.10.0

type BindComputeOption func(t *testing.T, w *bindCompute)

func WithAPIExportsWorkloadBindOption added in v0.10.0

func WithAPIExportsWorkloadBindOption(apiexports ...string) BindComputeOption

func WithLocationSelectorWorkloadBindOption added in v0.10.0

func WithLocationSelectorWorkloadBindOption(selectors ...metav1.LabelSelector) BindComputeOption

func WithLocationWorkspaceWorkloadBindOption added in v0.10.0

func WithLocationWorkspaceWorkloadBindOption(clusterName logicalcluster.Path) BindComputeOption

func WithNSSelectorWorkloadBindOption added in v0.10.0

func WithNSSelectorWorkloadBindOption(selector metav1.LabelSelector) BindComputeOption

func WithPlacementNameBindOption added in v0.10.0

func WithPlacementNameBindOption(placementName string) BindComputeOption

type ConditionEvaluator added in v0.11.0

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

func Is added in v0.11.0

func IsNot added in v0.11.0

func (*ConditionEvaluator) WithReason added in v0.11.0

func (c *ConditionEvaluator) WithReason(reason string) *ConditionEvaluator

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 KcpConfigOption added in v0.10.0

type KcpConfigOption func(*kcpConfig) *kcpConfig

KcpConfigOption a function that wish to modify a given kcp configuration.

func WithCustomArguments added in v0.10.0

func WithCustomArguments(args ...string) KcpConfigOption

WithCustomArguments applies provided arguments to a given kcp configuration.

func WithScratchDirectories added in v0.10.0

func WithScratchDirectories(artifactDir, dataDir string) KcpConfigOption

WithScratchDirectories adds custom scratch directories to a kcp configuration.

type PrivilegedWorkspaceOption added in v0.11.0

type PrivilegedWorkspaceOption func(ws *tenancyv1alpha1.Workspace)

func WithRequiredGroups added in v0.11.0

func WithRequiredGroups(groups ...string) PrivilegedWorkspaceOption

WithRequiredGroups is a privileged action, so we return a privileged option type, and only the helpers that use the system:master config can consume this. However, workspace initialization requires a valid user annotation on the workspace object to impersonate during initialization, and system:master bypasses setting that, so we end up needing to hard-code something conceivable.

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 kcpclient.Interface,
) (RegisterWorkspaceExpectation, error)

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

type RegisterWorkspaceShardExpectation

type RegisterWorkspaceShardExpectation func(seed *corev1alpha1.Shard, 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
	ShardSystemMasterBaseConfig(t *testing.T, shard string) *rest.Config
	ShardNames() []string
	Artifact(t *testing.T, producer func() (runtime.Object, error))
	ClientCAUserConfig(t *testing.T, config *rest.Config, name string, groups ...string) *rest.Config
	CADirectory() string
}

func NewFakeWorkloadServer added in v0.6.0

func NewFakeWorkloadServer(t *testing.T, server RunningServer, org logicalcluster.Path, syncTargetName string) 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, options ...KcpConfigOption) 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 UnprivilegedWorkspaceOption added in v0.11.0

type UnprivilegedWorkspaceOption func(ws *tenancyv1alpha1.Workspace)

func TODO_WithoutMultiShardSupport added in v0.11.0

func TODO_WithoutMultiShardSupport() UnprivilegedWorkspaceOption

func WithLocation added in v0.11.0

func WithName added in v0.6.0

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

func WithNameSuffix added in v0.11.0

func WithNameSuffix(suffix string) UnprivilegedWorkspaceOption

func WithRootShard added in v0.11.0

func WithRootShard() UnprivilegedWorkspaceOption

func WithShard added in v0.11.0

func WithShard(name string) UnprivilegedWorkspaceOption

func WithType added in v0.6.0

func WithType(path logicalcluster.Path, name tenancyv1alpha1.WorkspaceTypeName) UnprivilegedWorkspaceOption

type WorkspaceExpectation

type WorkspaceExpectation func(*tenancyv1alpha1.Workspace) error

WorkspaceExpectation evaluates an expectation about the object.

type WorkspaceOption added in v0.11.0

type WorkspaceOption interface {
	PrivilegedWorkspaceOption | UnprivilegedWorkspaceOption
}

type WorkspaceShardExpectation

type WorkspaceShardExpectation func(*corev1alpha1.Shard) 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