var ( CfgFlagName = "test-config" CfgPath = "test/config.json" Labels map[string]string SkipLabels map[string]string )
ErrSkip can be returned by FrameworkFns to signal that the entire test suite should be skipped. When this error is detected, the framework exits from TestMain with an exit code of 0. Callers should wrap this error with a specific reason for skipping that includes information on why the test suite was skipped and how to remediate it.
This error is not checked on Teardown, because what is the point in skipping something which is already terminating?
var ErrSkip = errors.New("skipping")
Flags is the flag set parsed and used by the Framework. Test authors should bind custom flags to this instead of directly adding to the global command line.
var Flags = flag.NewFlagSet("", flag.ContinueOnError)
func CopyFlags(source *flag.FlagSet, target *flag.FlagSet)
CopyFlags ensures that all flags that are defined in the source flag set appear in the target flag set as if they had been defined there directly. From the flag package it inherits the behavior that there is a panic if the target already contains a flag from the source.
func RegisterCommonFlags(flags *flag.FlagSet)
func SkipBasedOnLabels(test, labels, skip map[string]string) (bool, string)
SkipBasedOnLabels determines if a test should be skipped based on label maps which should be executed and labels that should be skipped.
func Validate() error
Validate checks that the base test context was provided valid values via config
Context is a type alias
type Context = fctx.Context
type Extension interface { RegisterFns(Framework) IntoContext(Context) Context }
type Feature interface { Name() string Labels() map[string]string Steps() []Step }
FeatureBuilder allows concise test definition with the builder pattern without increasing the surface area of the Feature interface
type FeatureBuilder struct {
// contains filtered or unexported fields
}
func NewFeature(name string) *FeatureBuilder
func (b *FeatureBuilder) Component(c ...string) *FeatureBuilder
Component is syntactic sugar for adding a component label to the test block. Returns a pointer to itself for function chaining.
func (b *FeatureBuilder) Disruptive() *FeatureBuilder
Disruptive is a label that should be applied to all test suites that are likely to disrupt other test cases being ran at the same time.
func (b *FeatureBuilder) Feature() Feature
func (b *FeatureBuilder) Flaky() *FeatureBuilder
Flaky is a label that should be applied to tests with inconsistent results.
func (b *FeatureBuilder) Priviledged(p ...string) *FeatureBuilder
Priviledged is a label that defines tests that require escalted privileges in various contexts. Examples: FolderAdmin, BillingAdmin, ProjectAdmin describe GCP privileges that tests may need.
func (b *FeatureBuilder) Serial() *FeatureBuilder
Serial is a label that should be applied to all test suites that can't be run in parallel.
func (b *FeatureBuilder) Setup(name string, fn StepFn) *FeatureBuilder
func (b *FeatureBuilder) Slow() *FeatureBuilder
Slow is a label that should be applied to all test suites which take longer than 5 minutes to execute.
func (b *FeatureBuilder) Teardown(name string, fn StepFn) *FeatureBuilder
func (b *FeatureBuilder) Test(name string, t StepFn) *FeatureBuilder
func (b *FeatureBuilder) WithID(f ...string) *FeatureBuilder
WithID is a label used to associate Tests with specific user-facing features. Should be identified by unique identifier (GitHub issue number or JIRA ticket) Can have multiple values, separated by comma.
func (b *FeatureBuilder) WithLabel(key string, values ...string) *FeatureBuilder
WithLabel adds a label with one or more values to the framework to describe the block of tests the framework instance will be used for. Returns a pointer to itself so it can be chained together to add multiple labels:
fin := f2.NewFeature("hello feature").WithLabel("bar", "boo", "baz", "boz").Flaky().Feature()
func (b *FeatureBuilder) WithStep(name string, p Phase, fn StepFn) *FeatureBuilder
FeatureFn is a feature-level lifecycle function executed by Framework, e.g. before the framework executes each feature, in the context of a test run. It is a FrameworkTestFn that gets information about the Feature being tested injected.
Changes to context are expected to be returned to caller.
type FeatureFn func(Context, *testing.T, Feature) (Context, error)
type FlagBinder interface { BindFlags(*flag.FlagSet) }
type Framework interface { Setup(...FrameworkFn) Framework Teardown(...FrameworkFn) Framework BeforeEachFeature(...FeatureFn) Framework AfterEachFeature(...FeatureFn) Framework BeforeEachTest(...FrameworkTestFn) Framework AfterEachTest(...FrameworkTestFn) Framework // Test executes features from a standard Go test function. Test(*testing.T, ...Feature) // TestInParallel executes features in parallel. TestInParallel(*testing.T, ...Feature) // Run executes the collection of tests from TestMain. Run(*testing.M) int // WithLabel adds framework-level labels for skipping or categorizing entire // test suites. Use [FeatureBuilder.WithLabel] to label individual features // within a suite. WithLabel(k string, v ...string) Framework Component(c ...string) Framework Priviledged(c ...string) Framework WithID(c ...string) Framework Slow() Framework Disruptive() Framework Serial() Framework Flaky() Framework }
func New(ctx context.Context, opts ...Option) Framework
FrameworkFn is a framework-level lifecycle function defined by the user, called by [Framework.Setup] and [Framework.Teardown].
Changes to context are expected to be returned to caller.
type FrameworkFn func(Context) (Context, error)
FrameworkTestFn is a lifecycle function executed by Framework in the context of a test run, e.g. [Framework.BeforeEachTest].
Changes to context are expected to be returned to caller.
type FrameworkTestFn func(Context, *testing.T) (Context, error)
type Labeler interface { Labels() map[string]string }
type Option = func(*options)
func WithExtensions(ext ...Extension) Option
WithExtensions initializes the Framework with the provided extensions, allowing reusable test code to handle things like binding flags, registering test lifecycle functions, etc for the user.
Phase defines the individual lifecycle phases.
type Phase uint8
func (p Phase) String() string
type Step struct { Name string Fn StepFn Phase Phase }
StepFn is the function called for each step of a Feature test, including actual test execution, executed by the Feature, not by the Framework directly.
Changes to context are expected to be returned to caller.
type StepFn func(Context, *testing.T) Context
Interface for testing.M so that we can provide alternative implementations for e.g. testing framework behavior.
type TestingMain interface { Run() (code int) }
Name | Synopsis |
---|---|
.. | |
examples | |
embed | |
kustomization | |
container | This is a very simple golang binary which will be packaged up into a container image, and referenced in a deployment manifest |
sharingdata | |
shared | |
fctx | Package fctx provides utilities for working with f2 test contexts. |
integration | |
x | Package x contains test framework extensions. |
bslauth | Package bslauth implements an f2 extension for working with BSL credentials |
ktest | |
envtest | Package envtest helps to set up various pieces of controller-runtime's envtest library to simplify writing K8s controller tests |
kpoll | Package kpoll provides a wrapper around gotest.tools/v3/poll to facilitate continually evaluating checks on K8s objects against a live cluster. |
kustomization | package kustomization provides a set of helpers useful when applying manifests to a k8s cluster during L2 integration tests |
postgres | Package postgres implements an f2 extension for working with PostgreSQL databases |
pstest | |
warehouse | Package warehouse implements a testing framework extension for working with Warehouse OCI packages and registries. |