# Functions
DefaultEnvAlways should be used to give the "env" glue target priority to override inherited environment variables
Normally if the environment variables returned by the "env" glue target are already set in the inherited environment (e.g.
DefaultMakeDir should be called by the test code to set the relative path of the "glue" makefile
For example, assuming that the "glue" targets are defined inside the Makefile residing in the project root directory and acceptance tests are in the "acceptance" directory, as demonstrated below:
| Makefile + acceptance | main_test.go
then the TestMain function defined inside main_test.go should pass DefaultMakeDir("..") to Parse function.
DefaultMakefile can be used to override the default name of the "glue" makefile
The default name is "Makefile", however if the "glue" targets are defined in a different makefile, the test code can set a different default using this function.
DefaultManifests can be called to override the default location of manifest files relative to main_test.go
If not set inside the test code, hardcoded subdirectory "manifests" will be used.
DefaultNoCleanup can be called to disable cleanup after tests
This function has the same effect as command line option -k8s.no-cleanup=true , however it can be overridden by the user setting -k8s.no-cleanup=false .
DefaultOperatorDelay is how long the framework will wait for the operator being tested to report an error
If not set inside the test code, hardcoded 2 seconds will be used.
DefaultPrefix can be called to override the default prefix of "glue" targets inside Makefile
If not set inside the test code, hardcoded prefix "test" will be used.
DeleteValue (element, array or section) from the unstructured object
Requires a path consisting of nested element names e.g.
LoadInto load an object from the textual data into an existing K8s object
This function supports both strong-typed object and Unstructured object.
LoadUnstructured load an object from the textual data
Using standard Reader interface (i.e.
OverrideCmdLine can be used by test code to override the default FlagSet used for tests
Normally tests should not use this function.
OverrideOsArgs can be used by the test code to override command line parameters passed to tests
Normally tests should not use this function, unless they really want to ignore command line parameters, but still want to call Parse function (rather than prepare Options object explicitly in code).
Parse function should be called at the start of test suite to parse the command line options provided by the user
Test code may set the default values of the test options using Default..
ReadValue (element, array or section) from an unstructured object
Requires a path consisting of nested element names e.g.
Start function will prepare and start the test cluster and create the K8s client for operating on it
This is arguably the key function of the test framework, since it performs most work: - validation of all "glue" targets - shutting the previously running cluster (if there was one and "no cleanup" is not set) - starting up a test Kubernetes cluster - creating a controller-runtime/client.Client object for manipulating the test cluster - this client object will be made available for use in test code as framework.Kube.Client
Aside from the regular options, test code may also set: - Sinks, to programmatically receive and handle the output of "glue" targets - runtime.Scheme for CRD used by the test controller-runtime/client.Client object.
WaitFor waits until "from" function returns a given number of instances
If the "from" function returns a strongly-typed K8s object of a type which can own pods, this number of instances refers to the number of ready pods.
WriteValue (element, array or section) from an unstructured object
Requires a path consisting of nested element names e.g.
# Variables
Kube is the global Harness object, created inside Start function.
# Structs
Harness represents the global state of the test framework.
Options for test framework
These options can be set from the command line, in which case they will be applied inside Parse function.
ParseOptions is used by Parse function to enable the test code to set own defaults
We are applying Functional Options pattern, described by Rob Pike at https://commandcenter.blogspot.com/2014/01/self-referential-functions-and-design.html (first half only) and further documented by Dave Cheney at https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis A short version of this pattern is described with Parse function below.
Sinks can be used to capture the "console" output from the spawned sub-processes (e.g.
No description provided by the author
# Interfaces
This interface is used to handle the process after it's been started It is expected to call *FIRST* wg.Wait() and *THEN* cmd.Wait() This helps to ensure that the output scanners will read the full output before the pipes are closed inside cmd.Wait().