Documentation ¶
Index ¶
- Constants
- Variables
- func AddReportEntriesAsYaml(name string, objs ...interface{})
- func AddReportEntryAsYaml(name string, obj interface{})
- func Case(caseName string) Labels
- func ConditionIsReady(condition *apis.Condition) error
- func ConvertTypeMetaToGroupVersionResource(typeMeta metav1.TypeMeta) schema.GroupVersionResource
- func DefaultConvertRuntimeToClientobjectFunc(runtimeObj runtime.Object) (obj client.Object, err error)
- func DeleteResources(file string, clt client.Client) (err error)
- func DiffEqualTo(expected interface{}, diffCleanFuncs ...func(object interface{}) interface{}) gomega.OmegaMatcher
- func ExpectDiff(actual interface{}, expected interface{}, ...) gomega.Assertiondeprecated
- func GetCaseNames(name string) []string
- func GetDefaultEnv(key string, defaultValue string) string
- func GetDefaultLogger() *uberzap.SugaredLogger
- func InitGinkgoWithLogger() *uberzap.SugaredLogger
- func InitializeGinkgoConfig()
- func KubeObjectDiffClean(object interface{}) interface{}deprecated
- func ListByGVK(gvk schema.GroupVersionKind) *unstructured.UnstructuredList
- func LoadJSON(file string, obj interface{}) (err error)
- func LoadKubeResources(file string, clt client.Client, ...) (err error)
- func LoadKubeResourcesAsUnstructured(file string) (objs []unstructured.Unstructured, err error)
- func LoadMultiYamlOrJson[T any](file string, list *[]T) (err error)
- func LoadObjectOrDie(g *WithT, file string, obj metav1.Object, patches ...func(metav1.Object)) metav1.Object
- func LoadObjectReferenceOrDie(g *WithT, file string, obj *corev1.ObjectReference, ...) *corev1.ObjectReference
- func LoadResourceFromFile(scheme *runtime.Scheme, path string) (obj runtime.Object, err error)
- func LoadResourcesFromFile(scheme *runtime.Scheme, path string) (objs []runtime.Object, err error)
- func LoadYAML(file string, obj interface{}) (err error)
- func MustLoadFileBytes(file string) []byte
- func MustLoadFileString(file string, content *string)
- func MustLoadJSON(file string, obj interface{})
- func MustLoadMultiYamlOrJson[T any](file string, list *[]T)
- func MustLoadReturnObjectFromYAML(file string, obj interface{}) interface{}
- func MustLoadYaml(file string, obj interface{})
- func NewGinkgoLogger() *uberzap.SugaredLogger
- func ReflectName(obj interface{}) string
- func RestoreDirectories(fs embed.FS, dirName string, targetDir string)
- func RuntimeObjectFromUnstructured(scheme *runtime.Scheme, u *unstructured.Unstructured) (runtime.Object, error)
- func SetName(name string) func(metav1.Object)
- func SliceToInterfaceSlice[T any](s []T) []interface{}
- func SliceToRuntimeOjbect[T any](s []T) []runtime.Object
- func ToObjectList[T client.Object](list []T) []client.Object
- func UnstructedToTyped(from unstructured.Unstructured, to interface{}) error
- func WarningOnError(logger *zap.SugaredLogger, err error, message string)
- type ConditionBuilder
- func (c *ConditionBuilder) Done() *apis.Condition
- func (c *ConditionBuilder) SetReasonMessage(reason, message string, formtKeyValues ...interface{}) *ConditionBuilder
- func (c *ConditionBuilder) SetStatus(stat corev1.ConditionStatus) *ConditionBuilder
- func (c *ConditionBuilder) SetType(ct apis.ConditionType) *ConditionBuilder
- type ConvertRuntimeObjctToClientObjectFunc
- type ScriptResult
Constants ¶
const DefaultScriptOutputPrefix = "##output##"
DefaultScriptOutputPrefix the prefix of script output Deprecated: move to testing/script DefaultScriptOutputPrefix
Variables ¶
var IgnoreVolatileTime = cmpopts.IgnoreTypes(apis.VolatileTime{})
IgnoreVolatileTime is a cmp option to ignore VolatileTime
Functions ¶
func AddReportEntriesAsYaml ¶ added in v0.12.0
func AddReportEntriesAsYaml(name string, objs ...interface{})
AddReportEntriesAsYaml adds multiple report entries formatted as YAML to the current SpecReport. The Report entry visibility is set to ReportEntryVisibilityFailureOrVerbose.
Example:
configMap := &corev1.ConfigMap{} service := &corev1.Service{} client.Get(ctx, key, configMap) client.Get(ctx, serviceKey, service) AddReportEntriesAsYaml("configuration", configMap, service)
Note: Any pointer will be only printed as the final value when testing is completed for current value provide the object as value:
AddReportEntriesAsYaml("previous-configuration", *configMap)
func AddReportEntryAsYaml ¶ added in v0.12.0
func AddReportEntryAsYaml(name string, obj interface{})
AddReportEntryAsYaml marshals the given object as YAML and adds it to the test report with the given name. The Report entry visibility is set to ReportEntryVisibilityFailureOrVerbose. Note: Any pointer will be only printed as the final value when testing is completed for current value provide the object as value.
Example:
configMap := &corev1.ConfigMap{} client.Get(ctx, key, configMap) AddReportEntryAsYaml("configuration", configMap)
Note: Any pointer will be only printed as the final value when testing is completed for current value provide the object as value:
AddReportEntryAsYaml("previous-configuration", *configMap)
Will automatically redact secret data for corev1.Secret objects.
func ConditionIsReady ¶ added in v0.7.0
ConditionIsReady returns an error if the condition status is not True useful for Eventually checks
func ConvertTypeMetaToGroupVersionResource ¶ added in v0.11.0
func ConvertTypeMetaToGroupVersionResource(typeMeta metav1.TypeMeta) schema.GroupVersionResource
ConvertTypeMetaToGroupVersionResource converts type meta to group version resource
func DefaultConvertRuntimeToClientobjectFunc ¶ added in v0.7.0
func DefaultConvertRuntimeToClientobjectFunc(runtimeObj runtime.Object) (obj client.Object, err error)
DefaultConvertRuntimeToClientobjectFunc convert runtime.Object to client.Object be similar to convertFromUnstructuredIfNecessary
func DeleteResources ¶
DeleteResources delete resources contained in the file
func DiffEqualTo ¶ added in v0.11.0
func DiffEqualTo(expected interface{}, diffCleanFuncs ...func(object interface{}) interface{}) gomega.OmegaMatcher
DiffEqualTo will use github.com/google/go-cmp/cmp.Diff to compare you can use diffCleanFuncs to change object in order to clean some fields that you don't want to compare Deprecated: use assertions.DiffEqual instead
func ExpectDiff
deprecated
added in
v0.11.0
func ExpectDiff(actual interface{}, expected interface{}, diffCleanFuncs ...func(object interface{}) interface{}) gomega.Assertion
ExpectDiff will using github.com/google/go-cmp/cmp.Diff to compare two data as default, it will not compare fields that have some undetermined value like uid, timestamp when compare kubernetes object you can use diffCleanFuncs to change object in order to clean some fields that you don't want to compare eg: clean status when compare
ExpectDiff(actual, expected, KubeObjectDiffClean, func(object ctrlclient.Object) { object.(*corev1.Pod).Status = corev1.PodStatus{} // do not compare Status return object }).Should(BeEmpty())
Deprecated: should use regular Expect with assertions.DiffEqual instead Example:
Expect(obj).To(DiffEqual(expected, cmpopts.IgnoreTypes(v1.TypeMeta{}, v1.PodStatus{})))
func GetCaseNames ¶ added in v0.11.0
GetCaseNames Resolve the case identifier from the testcase name in the junit report For go test junit report, the case name may be started with `Test`, e.g: TestGetProject For ginkgo test junit report, the case name may contain the {case:%s} string, e.g: [It] when xxxx [{case:GetProject}]
func GetDefaultEnv ¶ added in v0.10.0
GetDefaultEnv get the parameter from env, if not set it use the defaultValue instead
func GetDefaultLogger ¶ added in v0.11.0
func GetDefaultLogger() *uberzap.SugaredLogger
GetDefaultLogger returns the default logger for testing
func InitGinkgoWithLogger ¶ added in v0.11.0
func InitGinkgoWithLogger() *uberzap.SugaredLogger
InitGinkgoWithLogger initializes Ginkgo and returns a logger.
func InitializeGinkgoConfig ¶ added in v0.11.0
func InitializeGinkgoConfig()
InitializeGinkgoConfig initializes the Ginkgo configuration.
func KubeObjectDiffClean
deprecated
added in
v0.11.0
func KubeObjectDiffClean(object interface{}) interface{}
KubeObjectDiffClean will clean these fields in order to clean when diff kubernetes objects
- CreationTimestamp
- ManagedFields
- UID
- ResourceVersion
- Generation
- SelfLink
Deprecated: use assertions.DiffEqual and assertions.IgnoreObjectMetaFields instead
func ListByGVK ¶ added in v0.12.0
func ListByGVK(gvk schema.GroupVersionKind) *unstructured.UnstructuredList
ListByGVK creates a new UnstructuredList initialized with the given GroupVersionKind. Very useful for listing resources using only GroupVersionKind.
func LoadKubeResources ¶
func LoadKubeResources(file string, clt client.Client, converts ...ConvertRuntimeObjctToClientObjectFunc) (err error)
LoadKubeResources loading kubernetes resources
func LoadKubeResourcesAsUnstructured ¶
func LoadKubeResourcesAsUnstructured(file string) (objs []unstructured.Unstructured, err error)
func LoadMultiYamlOrJson ¶ added in v0.7.0
LoadMultiYamlOrJson loads multi yamls
func LoadObjectOrDie ¶
func LoadObjectOrDie(g *WithT, file string, obj metav1.Object, patches ...func(metav1.Object)) metav1.Object
LoadObjectOrDie loads object from yaml and returns
func LoadObjectReferenceOrDie ¶
func LoadObjectReferenceOrDie(g *WithT, file string, obj *corev1.ObjectReference, patches ...func(*corev1.ObjectReference)) *corev1.ObjectReference
LoadObjectReferenceOrDie loads object reference from yaml and returns
func LoadResourceFromFile ¶
func LoadResourcesFromFile ¶
func MustLoadFileBytes ¶ added in v0.10.0
MustLoadFileBytes loads a file as []bytes will panic if if failes ONLY FOR TEST USAGE
func MustLoadFileString ¶ added in v0.7.0
MustLoadFileString loads a file as string will panic if if failes ONLY FOR TEST USAGE
func MustLoadJSON ¶ added in v0.7.0
func MustLoadJSON(file string, obj interface{})
MustLoadJSON loads json or panics if the parse fails.
func MustLoadMultiYamlOrJson ¶ added in v0.7.0
MustLoadMultiYamlOrJson loads multi yamls or panics if the parse fails.
func MustLoadReturnObjectFromYAML ¶ added in v0.7.0
func MustLoadReturnObjectFromYAML(file string, obj interface{}) interface{}
MustLoadReturnObjectFromYAML loads and object from yaml file and returns as interface{} if any loading errors happen will panic TO BE USED IN TESTS, DO NOT USE IN PRODUCTION CODE
func MustLoadYaml ¶ added in v0.7.0
func MustLoadYaml(file string, obj interface{})
MustLoadYaml loads yaml or panics if the parse fails.
func NewGinkgoLogger ¶ added in v0.11.0
func NewGinkgoLogger() *uberzap.SugaredLogger
NewGinkgoLogger creates a new logger for Ginkgo tests.
func ReflectName ¶ added in v0.10.0
func ReflectName(obj interface{}) string
ReflectName reflect the type name of the object
func RestoreDirectories ¶ added in v0.10.0
RestoreDirectories restore directories from embed.FS to targetDir Deprecated: move to testing/script RestoreDirectories
func RuntimeObjectFromUnstructured ¶
func RuntimeObjectFromUnstructured(scheme *runtime.Scheme, u *unstructured.Unstructured) (runtime.Object, error)
RuntimeObjectFromUnstructured converts an unstructured to a runtime object
func SliceToInterfaceSlice ¶ added in v0.11.0
func SliceToInterfaceSlice[T any](s []T) []interface{}
SliceToInterfaceSlice convert a slice to a slice of interface
func SliceToRuntimeOjbect ¶ added in v0.11.0
SliceToRuntimeOjbect convert slice to runtime.Object
func ToObjectList ¶ added in v0.7.0
ToObjectList converts resource list to a list of client.Object
func UnstructedToTyped ¶
func UnstructedToTyped(from unstructured.Unstructured, to interface{}) error
UnstructedToTyped converts an unstructured object into a object Warning: This SHOULD never be used in production code, only in test code
func WarningOnError ¶
func WarningOnError(logger *zap.SugaredLogger, err error, message string)
WarningOnError set a warning on error
Types ¶
type ConditionBuilder ¶
ConditionBuilder builds a conditions in a builder pattern
func BuildCondition ¶
func BuildCondition() *ConditionBuilder
BuildCondition starts a condition builder object useful for unit tests that require validating multiple conditions
func (*ConditionBuilder) Done ¶
func (c *ConditionBuilder) Done() *apis.Condition
SetReasonMessage returns a condition
func (*ConditionBuilder) SetReasonMessage ¶
func (c *ConditionBuilder) SetReasonMessage(reason, message string, formtKeyValues ...interface{}) *ConditionBuilder
SetReasonMessage sets the message for the condition
func (*ConditionBuilder) SetStatus ¶
func (c *ConditionBuilder) SetStatus(stat corev1.ConditionStatus) *ConditionBuilder
SetStatus sets the status for the condition
func (*ConditionBuilder) SetType ¶
func (c *ConditionBuilder) SetType(ct apis.ConditionType) *ConditionBuilder
SetType sets the type for the condition
type ConvertRuntimeObjctToClientObjectFunc ¶ added in v0.3.0
type ScriptResult ¶ added in v0.10.0
type ScriptResult struct { OutputDataPrefix string // contains filtered or unexported fields }
ScriptResult the result of script execution Deprecated: move to testing/script ScriptResult
func ExecBashScript ¶ added in v0.10.0
func ExecBashScript(script string, params ...string) *ScriptResult
ExecBashScript exec bash script with params Deprecated: move to testing/script ExecBashScript
func ExecScript ¶ added in v0.10.0
func ExecScript(name string, arg ...string) *ScriptResult
ExecScript exec script with params Deprecated: move to testing/script ExecScript
func (*ScriptResult) Error ¶ added in v0.10.0
func (p *ScriptResult) Error() error
Error get the error of a script execution
func (*ScriptResult) ExitCode ¶ added in v0.10.0
func (p *ScriptResult) ExitCode() int
ExitCode get the exit code of a script execution
func (*ScriptResult) ExitMessage ¶ added in v0.10.0
func (p *ScriptResult) ExitMessage() string
ExitMessage get the exit message of a script execution
func (*ScriptResult) OutputData ¶ added in v0.10.0
func (p *ScriptResult) OutputData(dataPrefix string) string
OutputData get the output of a script execution, it can be a structured data, e.g: json string
func (*ScriptResult) Stderr ¶ added in v0.10.0
func (p *ScriptResult) Stderr() string
Stderr get the error output of a script execution
func (*ScriptResult) Stdout ¶ added in v0.10.0
func (p *ScriptResult) Stdout() string
Stdout get the output of a script execution
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package assertions contains all the assertions that can be used in tests for general testing.
|
Package assertions contains all the assertions that can be used in tests for general testing. |
conformance
Package conformance is a framework for conformance test
|
Package conformance is a framework for conformance test |
Package mock contains useful functionality for testing
|
Package mock contains useful functionality for testing |
github.com/katanomi/pkg
Package sharedmain is a generated GoMock package.
|
Package sharedmain is a generated GoMock package. |
github.com/katanomi/pkg/apis/meta/v1alpha1
Package apis is a generated GoMock package.
|
Package apis is a generated GoMock package. |
github.com/katanomi/pkg/conditioner
Package mock is a generated GoMock package.
|
Package mock is a generated GoMock package. |
github.com/katanomi/pkg/multicluster
Package multicluster is a generated GoMock package.
|
Package multicluster is a generated GoMock package. |
github.com/katanomi/pkg/plugin/client
Package client is a generated GoMock package.
|
Package client is a generated GoMock package. |
github.com/katanomi/pkg/plugin/storage
Package storage is a generated GoMock package.
|
Package storage is a generated GoMock package. |
github.com/katanomi/pkg/plugin/storage/capabilities/archive/v1alpha1
Package v1alpha1 is a generated GoMock package.
|
Package v1alpha1 is a generated GoMock package. |
github.com/katanomi/pkg/plugin/storage/capabilities/filestore/v1alpha1
Package v1alpha1 is a generated GoMock package.
|
Package v1alpha1 is a generated GoMock package. |
github.com/katanomi/pkg/plugin/storage/client
Package v1alpha1 is a generated GoMock package.
|
Package v1alpha1 is a generated GoMock package. |
github.com/katanomi/pkg/plugin/storage/client/versioned/archive/v1alpha1
Package v1alpha1 is a generated GoMock package.
|
Package v1alpha1 is a generated GoMock package. |
github.com/katanomi/pkg/plugin/storage/client/versioned/filestore/v1alpha1
Package v1alpha1 is a generated GoMock package.
|
Package v1alpha1 is a generated GoMock package. |
github.com/katanomi/pkg/plugin/types
Package types is a generated GoMock package.
|
Package types is a generated GoMock package. |
github.com/katanomi/pkg/warnings/condition
Package warnings is a generated GoMock package.
|
Package warnings is a generated GoMock package. |
github.com/katanomi/pkg/webhook/admission
Package admission is a generated GoMock package.
|
Package admission is a generated GoMock package. |
github.com/minio/minio-go
Package pkg is a generated GoMock package.
|
Package pkg is a generated GoMock package. |
k8s.io/cli-runtime/pkg/genericclioptions
Package genericclioptions is a generated GoMock package.
|
Package genericclioptions is a generated GoMock package. |
k8s.io/client-go/kubernetes
Package kubernetes is a generated GoMock package.
|
Package kubernetes is a generated GoMock package. |
k8s.io/client-go/tools/clientcmd
Package clientcmd is a generated GoMock package.
|
Package clientcmd is a generated GoMock package. |
knative.dev/pkg/apis
Package apis is a generated GoMock package.
|
Package apis is a generated GoMock package. |
sigs.k8s.io/controller-runtime/pkg/client
Package client is a generated GoMock package.
|
Package client is a generated GoMock package. |
sigs.k8s.io/controller-runtime/pkg/manager
Package manager is a generated GoMock package.
|
Package manager is a generated GoMock package. |
testing/fake
Package fake is a generated GoMock package.
|
Package fake is a generated GoMock package. |