framework

package
v0.0.0-...-d2430a7 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 26 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 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 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 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
	ApiExtClient *apiextensionsclientset.Clientset

	// Helm
	HelmClient  helm.Client
	HelmLogFile *os.File
	HelmLogger  *log.Logger

	// 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

	HelmLogFile string

	// 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

Jump to

Keyboard shortcuts

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