environment

package
v0.0.0-...-2023469 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: Apache-2.0 Imports: 31 Imported by: 35

Documentation

Index

Constants

View Source
const (
	DefaultPollInterval = 1 * time.Second
	DefaultPollTimeout  = 2 * time.Minute
)

this has been moved to state pkg to break cycle between environment and feature package, keeping the consts here for backwards API compatibility

View Source
const (
	NamespaceDeleteErrorReason = "NamespaceDeleteError"
)

Variables

This section is empty.

Functions

func ContextWith

func ContextWith(ctx context.Context, e Environment) context.Context

func ContextWithPollTimings

func ContextWithPollTimings(ctx context.Context, interval, timeout time.Duration) context.Context

ContextWithPollTimings returns a context with poll timings set

func InitFlags

func InitFlags(fs *flag.FlagSet)

InitFlags registers the requirement and state filter flags supported by the testing framework.

func PollTimingsFromContext

func PollTimingsFromContext(ctx context.Context) (time.Duration, time.Duration)

PollTimingsFromContext will get the previously set poll timing from context, or return the defaults if not found. - values from context. - defaults.

func ProduceImages

func ProduceImages(ctx context.Context) (map[string]string, error)

ProduceImages returns back the packages that have been added. Will produce images once, can be called many times.

func WithPostInit

func WithPostInit(ctx context.Context, fn InitFn) context.Context

Types

type Configuration

type Configuration struct {
	Flags
	context.Context
	*rest.Config
}

Configuration holds a configuration options for standard GlobalEnvironment.

type ConfigurationOption

type ConfigurationOption func(Configuration) Configuration

ConfigurationOption allows to reconfigure default options, by returning modified configuration.

type EnvOpts

type EnvOpts func(ctx context.Context, env Environment) (context.Context, error)

EnvOpts are options used to adjust the context or change how the environment is setup.

func Cleanup

func Cleanup(t feature.T) EnvOpts

Cleanup is an environment option to register a cleanup that will call Environment.Finish function at test end automatically.

func InNamespace

func InNamespace(namespace string) EnvOpts

InNamespace takes the namespace that the tests should be run in instead of creating a namespace. This is useful if the Unit Under Test (UUT) is created ahead of the tests to be run. Longer term this should make it easier to decouple the UUT from the generic conformance tests, for example, create a Broker of type {Kafka, RabbitMQ} and the tests themselves should not care.

func Managed

func Managed(t feature.T) EnvOpts

Managed enables auto-lifecycle management of the environment. Including registration of following opts:

  • Cleanup,
  • WithTestLogger.

func RegisterPackage

func RegisterPackage(pack ...string) EnvOpts

RegisterPackage registers an interest in producing an image based on the provided package. Can be called multiple times with the same package. A package will be used to produce the image and used like `image: ko://<package>` inside test yaml.

func UnionOpts

func UnionOpts(opts ...EnvOpts) EnvOpts

UnionOpts joins the given opts into a single opts function.

func WithEmitter

func WithEmitter(emitter milestone.Emitter) EnvOpts

func WithImageProducer

func WithImageProducer(producer ImageProducer) EnvOpts

WithImageProducer allows using a different ImageProducer when creating an Environment through GlobalEnvironment. Example usage: GlobalEnvironment.Environment(WithImageProducer(file.ImageProducer("images.yaml")))

func WithImagePullSecret

func WithImagePullSecret(namespace string, name string) EnvOpts

WithImagePullSecret takes namespace and name of a Secret to be added to ServiceAccounts of newly created namespaces. This is useful if tests refer to private registries that require authentication.

func WithImages

func WithImages(given map[string]string) EnvOpts

WithImages will bypass ProduceImages() and use the provided image set instead. Should be called before ProduceImages(), if used, likely in an init() method. An images value should be a container registry image. The images map is presented to the templates on the field `images`, and used like `image: <key>` inside test yaml.

func WithNamespace

func WithNamespace(namespace string) EnvOpts

WithNamespace overrides test namespace for given environment.

func WithNamespaceTransformFuncs

func WithNamespaceTransformFuncs(transforms ...NamespaceTransformFunc) EnvOpts

func WithPollTimings

func WithPollTimings(interval, timeout time.Duration) EnvOpts

WithPollTimings is an environment option to override default poll timings.

func WithTestLogger

func WithTestLogger(t zaptest.TestingT, opts ...zaptest.LoggerOption) EnvOpts

WithTestLogger returns a context with test logger configured.

type Environment

type Environment interface {
	// Prerequisite will execute the feature using the given Context and T,
	// the feature should not have any asserts.
	Prerequisite(ctx context.Context, t *testing.T, f *feature.Feature)

	// Test will execute the feature test using the given Context and T.
	Test(ctx context.Context, t *testing.T, f *feature.Feature)

	// ParallelTest will execute the feature test using the given Context and T in parallel with
	// other parallel features.
	ParallelTest(ctx context.Context, t *testing.T, f *feature.Feature)

	// TestSet will execute the feature set using the given Context and T.
	TestSet(ctx context.Context, t *testing.T, fs *feature.FeatureSet)

	// ParallelTestSet will execute the feature set using the given Context and T with each feature
	// running in parallel with other parallel features.
	ParallelTestSet(ctx context.Context, t *testing.T, f *feature.FeatureSet)

	// Namespace returns the namespace of this environment.
	Namespace() string

	// RequirementLevel returns the requirement level for this environment.
	RequirementLevel() feature.Levels

	// FeatureState returns the requirement level for this environment.
	FeatureState() feature.States

	// TemplateConfig returns the base template config to use when processing
	// yaml templates.
	TemplateConfig(base map[string]interface{}) map[string]interface{}

	// Reference registers an object reference to the environment, so that it
	// can be listed in env.References() or be cleaned up in env.Finish().
	// This can be one way a feature communicates with future features run in
	// the same environment.
	Reference(ref ...corev1.ObjectReference)

	// References returns the list of known object references that have been
	// installed in the environment.
	References() []corev1.ObjectReference

	// Finish signals to the environment no future features will be run. The
	// namespace will be deleted if it was created by the environment,
	// References will be cleaned up if registered.
	Finish()
}

Environment is the ephemeral testing environment to test features.

func FromContext

func FromContext(ctx context.Context) Environment

type Flags

type Flags interface {
	// Get returns the flag set object on which specific flags are registered.
	// After registration is complete, the Parse method should be called.
	Get(ctx context.Context) *flag.FlagSet

	// Parse invokes the processing of underlying inputs that will update the
	// previously returned flag.FlagSet object. Thi method should be called after
	// the specific flags has been defined on object returned from the Get method.
	Parse(ctx context.Context) error
}

Flags is used to pass flags implementation.

type GlobalEnvironment

type GlobalEnvironment interface {
	Environment(opts ...EnvOpts) (context.Context, Environment)
}

GlobalEnvironment is the factory for an instance of Environment. GlobalEnvironment holds the understanding of the particular cluster that will be used for the feature testing.

func NewGlobalEnvironment

func NewGlobalEnvironment(ctx context.Context, initializers ...func()) GlobalEnvironment

NewGlobalEnvironment creates a new global environment based on a context.Context, and optional initializers slice. The provided context is expected to contain the configured Kube client already.

func NewStandardGlobalEnvironment

func NewStandardGlobalEnvironment(opts ...ConfigurationOption) GlobalEnvironment

NewStandardGlobalEnvironment will create a new global environment in a standard way. The Kube client will be initialized within the context.Context for later use.

func NewStandardGlobalEnvironmentWithRestConfig

func NewStandardGlobalEnvironmentWithRestConfig(cfg *rest.Config, opts ...ConfigurationOption) GlobalEnvironment

NewStandardGlobalEnvironment will create a new global environment in a standard way. The Kube client will be initialized within the context.Context for later use. It uses the provided rest config when creating the informers.

type ImageProducer

type ImageProducer func(ctx context.Context, pack string) (string, error)

ImageProducer is a function that will be used to produce the container images.

pack is a Go main package reference like `knative.dev/reconciler-test/cmd/eventshub`.

func GetImageProducer

func GetImageProducer(ctx context.Context) ImageProducer

GetImageProducer extracts an ImageProducer from the given context.

type InitFn

type InitFn = EnvOpts

func GetPostInit

func GetPostInit(ctx context.Context) []InitFn

type IstioConfig

type IstioConfig struct {
	Enabled bool
}

func GetIstioConfig

func GetIstioConfig(ctx context.Context) *IstioConfig

GetIstioConfig returns the configured IstioConfig

type MagicEnvironment

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

func (*MagicEnvironment) CreateNamespaceIfNeeded

func (mr *MagicEnvironment) CreateNamespaceIfNeeded() error

CreateNamespaceIfNeeded creates a new namespace if it does not exist.

func (*MagicEnvironment) DeleteNamespaceIfNeeded

func (mr *MagicEnvironment) DeleteNamespaceIfNeeded(result milestone.Result) error

func (*MagicEnvironment) FeatureState

func (mr *MagicEnvironment) FeatureState() feature.States

func (*MagicEnvironment) Finish

func (mr *MagicEnvironment) Finish()

func (*MagicEnvironment) Namespace

func (mr *MagicEnvironment) Namespace() string

func (*MagicEnvironment) ParallelTest

func (mr *MagicEnvironment) ParallelTest(ctx context.Context, originalT *testing.T, f *feature.Feature)

ParallelTest implements Environment.ParallelTest. It is similar to Test with the addition of running the feature in parallel

func (*MagicEnvironment) ParallelTestSet

func (mr *MagicEnvironment) ParallelTestSet(ctx context.Context, t *testing.T, fs *feature.FeatureSet)

ParallelTestSet implements Environment.ParallelTestSet

func (*MagicEnvironment) Prerequisite

func (mr *MagicEnvironment) Prerequisite(ctx context.Context, t *testing.T, f *feature.Feature)

func (*MagicEnvironment) Reference

func (mr *MagicEnvironment) Reference(ref ...corev1.ObjectReference)

func (*MagicEnvironment) References

func (mr *MagicEnvironment) References() []corev1.ObjectReference

func (*MagicEnvironment) RequirementLevel

func (mr *MagicEnvironment) RequirementLevel() feature.Levels

func (*MagicEnvironment) TemplateConfig

func (mr *MagicEnvironment) TemplateConfig(base map[string]interface{}) map[string]interface{}

func (*MagicEnvironment) Test

func (mr *MagicEnvironment) Test(ctx context.Context, originalT *testing.T, f *feature.Feature)

Test implements Environment.Test. In the MagicEnvironment implementation, the Store that is inside of the Feature will be assigned to the context. If no Store is set on Feature, Test will create a new store.KVStore and set it on the feature and then apply it to the Context.

func (*MagicEnvironment) TestSet

func (mr *MagicEnvironment) TestSet(ctx context.Context, t *testing.T, fs *feature.FeatureSet)

TestSet implements Environment.TestSet

type MagicGlobalEnvironment

type MagicGlobalEnvironment struct {
	RequirementLevel feature.Levels
	FeatureState     feature.States
	FeatureMatch     *regexp.Regexp
	// contains filtered or unexported fields
}

func (*MagicGlobalEnvironment) Environment

func (mr *MagicGlobalEnvironment) Environment(opts ...EnvOpts) (context.Context, Environment)

type NamespaceTransformFunc

type NamespaceTransformFunc func(ns *corev1.Namespace) error

Jump to

Keyboard shortcuts

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