Documentation ¶
Index ¶
- Variables
- func AppendRandomString(prefix string) string
- func ContextWith(ctx context.Context, f *Feature) context.Context
- func DeleteResources(ctx context.Context, t T, refs []corev1.ObjectReference) error
- func GetBaseFuncName(fullFuncName string) string
- func MakeK8sNamePrefix(s string) string
- func MakeRandomK8sName(prefix string) string
- func ObjectNameForTest(t Namer) string
- func ObjectPrefixForTest(t Namer) string
- func RandomString() string
- type Assertable
- type Asserter
- func (a *Asserter) Assert(l Levels, name string, fn StepFn)
- func (a *Asserter) May(name string, fn StepFn) Assertable
- func (a *Asserter) Must(name string, fn StepFn) Assertable
- func (a *Asserter) MustNot(name string, fn StepFn) Assertable
- func (a *Asserter) Should(name string, fn StepFn) Assertable
- func (a *Asserter) ShouldNot(name string, fn StepFn) Assertable
- type Feature
- func (f *Feature) AddStep(step ...Step)
- func (f *Feature) Alpha(name string) Assertable
- func (f *Feature) Assert(name string, fn StepFn)
- func (f *Feature) Beta(name string) Assertable
- func (f *Feature) DeleteResources(ctx context.Context, t T)
- func (f *Feature) DumpWith(log func(args ...interface{}))
- func (f *Feature) GetGroups() []*Feature
- func (f *Feature) Group(name string, group func(f *Feature))
- func (f *Feature) GroupF(other *Feature)
- func (f *Feature) MarshalJSON() ([]byte, error)
- func (f *Feature) Prerequisite(name string, fn ShouldRun)
- func (f *Feature) Reference(ref ...corev1.ObjectReference)
- func (f *Feature) References() []corev1.ObjectReference
- func (f *Feature) Requirement(name string, fn StepFn)
- func (f *Feature) Setup(name string, fn StepFn)
- func (f *Feature) Stable(name string) Assertable
- func (f *Feature) Teardown(name string, fn StepFn)
- type FeatureSet
- type Levels
- type Namer
- type Option
- type PrerequisiteResult
- type ShouldRun
- type States
- type Step
- type StepFn
- type Steps
- type T
- type Timing
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func AppendRandomString ¶
AppendRandomString will generate a random string that begins with prefix. This is useful if you want to make sure that your tests can run at the same time against the same environment without conflicting. This method will use "-" as the separator between the prefix and the random suffix.
func ContextWith ¶
ContextWith decorates the given context with the provided Feature, and returns the resulting context.
func DeleteResources ¶
func GetBaseFuncName ¶
GetBaseFuncName returns the baseFuncName parsed from the fullFuncName. eg. test/e2e.TestMain will return TestMain.
func MakeK8sNamePrefix ¶
MakeK8sNamePrefix converts each chunk of non-alphanumeric character into a single dash and also convert camelcase tokens into dash-delimited lowercase tokens.
func ObjectNameForTest ¶
ObjectNameForTest generates a random object Name based on the test Name.
func ObjectPrefixForTest ¶
ObjectPrefixForTest returns the Name prefix for this test's random names.
Types ¶
type Assertable ¶
type Assertable interface { Must(name string, fn StepFn) Assertable Should(name string, fn StepFn) Assertable May(name string, fn StepFn) Assertable MustNot(name string, fn StepFn) Assertable ShouldNot(name string, fn StepFn) Assertable }
Assertable is a fluent interface based on Levels for creating an Assert step.
type Asserter ¶
type Asserter struct {
// contains filtered or unexported fields
}
type Feature ¶
type Feature struct { Name string Steps []Step State state.Store // contains filtered or unexported fields }
Feature is a list of steps and feature name.
func FromContext ¶
FromContext returns the Feature from Context, if not found FromContext will return nil.
func NewFeature ¶
func NewFeature() *Feature
NewFeature creates a new feature with name taken from the caller name
Example ¶
f := NewFeature() f.State = &state.KVStore{} f.Reference(corev1.ObjectReference{ Kind: "Pod", Namespace: "ns", Name: "name", APIVersion: "v1", }) f.Setup("step 1", func(ctx context.Context, t T) {}) _ = f.State.Set(context.Background(), "key", "value") b, err := f.MarshalJSON() if err != nil { panic(err) } fmt.Println(string(b))
Output: { "name": "ExampleNewFeature", "steps": [ { "name": "step 1", "states": "Any", "levels": "All", "timing": "Setup" } ], "state": { "key": "\"value\"" }, "refs": [ { "kind": "Pod", "namespace": "ns", "name": "name", "apiVersion": "v1" } ] }
func NewFeatureNamed ¶
NewFeatureNamed creates a new feature with the provided name
func (*Feature) Alpha ¶
func (f *Feature) Alpha(name string) Assertable
Alpha is a fluent style method for creating an Assert step in Alpha State.
func (*Feature) Assert ¶
Assert is a shortcut for Stable().Must(name, fn), useful for developing integration tests that don't require assertion levels.
func (*Feature) Beta ¶
func (f *Feature) Beta(name string) Assertable
Beta is a fluent style method for creating an Assert step in Beta State.
func (*Feature) DeleteResources ¶
DeleteResources delete all known resources to the Feature registered via `Reference`.
Expected to be used as a StepFn.
func (*Feature) DumpWith ¶
func (f *Feature) DumpWith(log func(args ...interface{}))
DumpWith calls the provided log function with a nicely formatted string that represents the Feature.
func (*Feature) Group ¶
Group add a new group to the feature, groups are executed in the order they are inserted and before the feature steps.
func (*Feature) GroupF ¶
GroupF add a new sub Feature to the feature, groups are executed in the order they are inserted and before the feature steps.
func (*Feature) MarshalJSON ¶
func (*Feature) Prerequisite ¶
Prerequisite adds a step function to the feature set at the Prerequisite timing phase.
func (*Feature) Reference ¶
func (f *Feature) Reference(ref ...corev1.ObjectReference)
Reference adds references to keep track of for example, for cleaning things after a Feature completes.
func (*Feature) References ¶
func (f *Feature) References() []corev1.ObjectReference
References returns all known resources to the Feature registered via `Reference`.
func (*Feature) Requirement ¶
Requirement adds a step function to the feature set at the Requirement timing phase.
func (*Feature) Stable ¶
func (f *Feature) Stable(name string) Assertable
Stable is a fluent style method for creating an Assert step in Stable State.
type FeatureSet ¶
FeatureSet is a list of features and feature set name.
type Levels ¶
type Levels uint8
const ( // Must means that the definition is an absolute requirement of the specification. Must Levels = 1 << iota // MustNot means that the definition is an absolute prohibition of the specification. MustNot // Should means that there may exist valid reasons in particular circumstances to // ignore a particular item Should // Should means that there may exist valid reasons in particular circumstances when the // particular behavior is acceptable or even useful ShouldNot // May means that an item is truly optional May // All flag enables all requirement levels All = Must | MustNot | Should | ShouldNot | May )
func (Levels) MarshalJSON ¶
type PrerequisiteResult ¶
type PrerequisiteResult struct { // ShouldRun is the flag signaling whether other timings will run or not. // True means other timings will run, false will skip other timings. ShouldRun bool // Reason will report why a given prerequisite is not satisfied. // This is used to report a clear skip reason to the user. Reason string }
PrerequisiteResult is the result returned by ShouldRun.
type ShouldRun ¶
type ShouldRun func(ctx context.Context, t T) (PrerequisiteResult, error)
ShouldRun is the function signature for Prerequisite steps.
type Step ¶
type Step struct { Name string `json:"name"` S States `json:"states"` L Levels `json:"levels"` T Timing `json:"timing"` Fn StepFn `json:"-"` }
Step is a structure to hold the step function, step name and state, level and timing configuration.
type StepFn ¶
StepFn is the function signature for steps.
func LogReferences ¶
func LogReferences(refs ...corev1.ObjectReference) StepFn
func SetStateOrFail ¶
SetStateOrFail augments the state as part of a feature step
type T ¶
type T interface { Name() string Log(args ...interface{}) Logf(format string, args ...interface{}) Error(args ...interface{}) Errorf(format string, args ...interface{}) Fail() Fatal(args ...interface{}) Fatalf(format string, args ...interface{}) FailNow() Skip(args ...interface{}) Skipf(format string, args ...interface{}) SkipNow() Failed() bool Skipped() bool // Note: these are step scoped! Cleanup(f func()) Deadline() (deadline time.Time, ok bool) }
T is an interface similar to testing.T passed to StepFn to perform logging and assertions