framework

package
v0.15.0 Latest Latest
Warning

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

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

Documentation

Overview

Package framework contains provider-independent helper code for building and running E2E tests with Ginkgo. The actual Ginkgo test suites gets assembled by combining this framework, the optional provider support code and specific tests via a separate .go file like Kubernetes' test/e2e.go.

Index

Constants

View Source
const (
	// DefaultNamespaceDeletionTimeout is timeout duration for waiting for a namespace deletion.
	DefaultNamespaceDeletionTimeout = 5 * time.Minute
)
View Source
const (
	// PollInterval is how often to Poll pods, nodes and claims.
	PollInterval = 2 * time.Second
)

Variables

View Source
var ErrFailure error = FailureError{}

ErrFailure is an empty error that can be wrapped to indicate that an error is a FailureError. It can also be used to test for a FailureError:.

return fmt.Errorf("some problem%w", ErrFailure)
...
err := someOperation()
if errors.Is(err, ErrFailure) {
    ...
}
View Source
var RunID = uuid.NewUUID()

RunID is a unique identifier of the e2e run. Beware that this ID is not the same for all tests in the e2e run, because each Ginkgo node creates it separately.

View Source
var TestContext = TestContextType{}

TestContext should be used by all tests to access common context data.

Functions

func CreateTestingNS

func CreateTestingNS(ctx context.Context, baseName string, c clientset.Interface, labels map[string]string) (*corev1.Namespace, error)

CreateTestingNS should be used by every test, note that we append a common prefix to the provided test name. Please see NewFramework instead of using this directly.

func ExpectNoError

func ExpectNoError(err error, explain ...interface{})

ExpectNoError checks if "err" is set, and if so, fails assertion while logs the error.

func ExpectNoErrorWithOffset

func ExpectNoErrorWithOffset(offset int, err error, explain ...interface{})

ExpectNoErrorWithOffset checks if "err" is set, and if so, fails assertion while logs the error at "offset" levels above its caller (for example, for call chain f -> g -> ExpectNoErrorWithOffset(1, ...) error would be logged for "f").

func LoadConfig

func LoadConfig() (config *restclient.Config, err error)

LoadConfig returns a config for a rest client with the UserAgent set to include the current test name.

func RandomSuffix

func RandomSuffix() string

RandomSuffix provides a random sequence to append to pods,services,rcs.

func RegisterClusterFlags

func RegisterClusterFlags(flags *flag.FlagSet)

RegisterClusterFlags registers flags specific to the cluster e2e test suite.

func WaitForNamespacesDeleted

func WaitForNamespacesDeleted(ctx context.Context, c clientset.Interface, namespaces []string, timeout time.Duration) error

WaitForNamespacesDeleted waits for the namespaces to be deleted.

Types

type CreateTestingNSFn

type CreateTestingNSFn func(ctx context.Context, baseName string, c clientset.Interface, labels map[string]string) (*corev1.Namespace, error)

CreateTestingNSFn is a func that is responsible for creating namespace used for executing e2e tests.

type FailureError

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

FailureError is an error where the error string is meant to be passed to ginkgo.Fail directly, i.e. adding some prefix like "unexpected error" is not necessary. It is also not necessary to dump the error struct.

func (FailureError) Backtrace

func (f FailureError) Backtrace() string

func (FailureError) Error

func (f FailureError) Error() string

type Framework

type Framework struct {
	BaseName string

	// Set together with creating the ClientSet and the namespace.
	// Guaranteed to be unique in the cluster even when running the same
	// test multiple times in parallel.
	UniqueName string

	ClientSet clientset.Interface

	// configuration for framework's client
	Options Options

	SkipNamespaceCreation    bool              // Whether to skip creating a namespace
	Namespace                *corev1.Namespace // Every test has at least one namespace unless creation is skipped
	NamespaceDeletionTimeout time.Duration
	// contains filtered or unexported fields
}

Framework supports common operations used by e2e tests; it will keep a client & a namespace for you. Eventual goal is to merge this with integration test framework.

You can configure the pod security level for your test by setting the `NamespacePodSecurityLevel` which will set all three of pod security admission enforce, warn and audit labels on the namespace. The default pod security profile is "restricted". Each of the labels can be overridden by using more specific NamespacePodSecurity* attributes of this struct.

func NewFramework

func NewFramework(baseName string) *Framework

NewFramework creates a test framework.

func (*Framework) AddNamespacesToDelete

func (f *Framework) AddNamespacesToDelete(namespaces ...*corev1.Namespace)

AddNamespacesToDelete adds one or more namespaces to be deleted when the test completes.

func (*Framework) AfterEach

func (f *Framework) AfterEach(ctx context.Context)

AfterEach deletes the namespace, after reading its events.

func (*Framework) BeforeEach

func (f *Framework) BeforeEach(ctx context.Context)

BeforeEach gets a client and makes a namespace.

func (*Framework) ClientConfig

func (f *Framework) ClientConfig() *rest.Config

ClientConfig an externally accessible method for reading the kube client config.

func (*Framework) CreateNamespace

func (f *Framework) CreateNamespace(ctx context.Context, baseName string, labels map[string]string) (*corev1.Namespace, error)

CreateNamespace creates a namespace for e2e testing.

func (*Framework) DeleteNamespace

func (f *Framework) DeleteNamespace(ctx context.Context, name string)

DeleteNamespace can be used to delete a namespace

type Options

type Options struct {
	ClientQPS    float32
	ClientBurst  int
	GroupVersion *schema.GroupVersion
}

Options is a struct for managing test framework options.

type TestContextType

type TestContextType struct {
	KubeConfig               string
	KubeContext              string
	DeleteNamespace          bool
	DeleteNamespaceOnFailure bool

	// CreateTestingNS is responsible for creating namespace used for executing e2e tests.
	// It accepts namespace base name, which will be prepended with e2e prefix, kube client
	// and labels to be applied to a namespace.
	CreateTestingNS CreateTestingNSFn
}

TestContextType contains test settings and global state

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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