Documentation ¶
Index ¶
- func EnsureTestResources(ctx context.Context, c client.Client, path string) ([]client.Object, error)
- func ReadTestResources(scheme *runtime.Scheme, path string) ([]client.Object, error)
- func WithEnvVar(key, value string) func()
- func WithFeatureGate(gate featuregate.FeatureGate, f featuregate.Feature, value bool) func()
- func WithTempFile(dir, pattern string, content []byte, fileName *string) func()
- func WithVar(dst, src interface{}) func()
- func WithVars(dstsAndSrcs ...interface{}) func()
- func WithWd(path string) func()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureTestResources ¶ added in v1.17.0
func EnsureTestResources(ctx context.Context, c client.Client, path string) ([]client.Object, error)
EnsureTestResources reads test resources from path, applies them using the given client and returns the created objects.
func ReadTestResources ¶ added in v1.17.0
ReadTestResources reads test resources from path, decodes them using the given scheme and returns the parsed objects. Objects are values of the proper API types, if registered in the given scheme, and *unstructured.Unstructured otherwise.
func WithEnvVar ¶
func WithEnvVar(key, value string) func()
WithEnvVar sets the env variable to the given environment variable and returns a function to revert. If the value is empty, the environment variable will be unset.
func WithFeatureGate ¶ added in v1.12.0
func WithFeatureGate(gate featuregate.FeatureGate, f featuregate.Feature, value bool) func()
WithFeatureGate sets the specified gate to the specified value, and returns a function that restores the original value. Failures to set or restore cause the test to fail. Example use:
defer WithFeatureGate(utilfeature.DefaultFeatureGate, features.<FeatureName>, true)()
func WithTempFile ¶ added in v1.18.0
WithTempFile creates a temporary file with the given dir and pattern, writes the given content to it, and returns a function to delete it. Failures to create, open, close, or delete the file case the test to fail.
The filename is generated by taking pattern and adding a random string to the end. If pattern includes a "*", the random string replaces the last "*". If dir is the empty string, WriteTempFile uses the default directory for temporary files (see ioutil.TempFile). The caller can use the value of fileName to find the pathname of the file.
Example usage:
var fileName string defer WithTempFile("", "test", []byte("test file content"), &fileName)()
func WithVar ¶
func WithVar(dst, src interface{}) func()
WithVar sets the given var to the src value and returns a function to revert to the original state. The type of `dst` has to be a settable pointer. The value of `src` has to be assignable to the type of `dst`.
Example usage:
v := "foo" defer WithVar(&v, "bar")()
Types ¶
This section is empty.