{"modulePath":"github.com/AlaudaDevops/pkg","version":"v0.14.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package testing\n\n## Constants\n\n```go\nconst DefaultScriptOutputPrefix = \"##output##\"\n```\nDefaultScriptOutputPrefix the prefix of script output Deprecated: move to testing/script DefaultScriptOutputPrefix\n\n## Variables\n\n```go\nvar IgnoreVolatileTime = cmpopts.IgnoreTypes(apis.VolatileTime{})\n```\nIgnoreVolatileTime is a cmp option to ignore VolatileTime\n\n## Functions\n\n```go\nfunc AddReportEntriesAsYaml(name string, objs ...interface{})\n```\nAddReportEntriesAsYaml adds multiple report entries formatted as YAML to the current SpecReport. The Report entry visibility is set to ReportEntryVisibilityFailureOrVerbose.\n\nExample:\n\n\tconfigMap := \u0026corev1.ConfigMap{}\n\tservice := \u0026corev1.Service{}\n\tclient.Get(ctx, key, configMap)\n\tclient.Get(ctx, serviceKey, service)\n\tAddReportEntriesAsYaml(\"configuration\", configMap, service)\n\nNote: Any pointer will be only printed as the final value when testing is completed for current value provide the object as value:\n\n\tAddReportEntriesAsYaml(\"previous-configuration\", *configMap)\n\n```go\nfunc AddReportEntryAsYaml(name string, obj interface{})\n```\nAddReportEntryAsYaml 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.\n\nExample:\n\n\tconfigMap := \u0026corev1.ConfigMap{}\n\tclient.Get(ctx, key, configMap)\n\tAddReportEntryAsYaml(\"configuration\", configMap)\n\nNote: Any pointer will be only printed as the final value when testing is completed for current value provide the object as value:\n\n\tAddReportEntryAsYaml(\"previous-configuration\", *configMap)\n\nWill automatically redact secret data for corev1.Secret objects.\n\n```go\nfunc Case(caseName string) Labels\n```\nCase the unique case name label\n\n```go\nfunc ConditionIsReady(condition *apis.Condition) error\n```\nConditionIsReady returns an error if the condition status is not True useful for Eventually checks\n\n```go\nfunc ConvertTypeMetaToGroupVersionResource(typeMeta metav1.TypeMeta) schema.GroupVersionResource\n```\nConvertTypeMetaToGroupVersionResource converts type meta to group version resource\n\n```go\nfunc DefaultConvertRuntimeToClientobjectFunc(runtimeObj runtime.Object) (obj client.Object, err error)\n```\nDefaultConvertRuntimeToClientobjectFunc convert runtime.Object to client.Object be similar to convertFromUnstructuredIfNecessary\n\n```go\nfunc DeleteResources(file string, clt client.Client) (err error)\n```\nDeleteResources delete resources contained in the file\n\n```go\nfunc DiffEqualTo(expected interface{}, diffCleanFuncs ...func(object interface{}) interface{}) gomega.OmegaMatcher\n```\nDiffEqualTo 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\n\n```go\nfunc ExpectDiff(actual interface{}, expected interface{}, diffCleanFuncs ...func(object interface{}) interface{}) gomega.Assertion\n```\nExpectDiff 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\n\n\tExpectDiff(actual, expected, KubeObjectDiffClean, func(object ctrlclient.Object) {\n\t\tobject.(*corev1.Pod).Status = corev1.PodStatus{} // do not compare Status\n\t\treturn object\n\t}).Should(BeEmpty())\n\nDeprecated: should use regular Expect with assertions.DiffEqual instead Example:\n\n\tExpect(obj).To(DiffEqual(expected, cmpopts.IgnoreTypes(v1.TypeMeta{}, v1.PodStatus{})))\n\n```go\nfunc GetCaseNames(name string) []string\n```\nGetCaseNames 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}]\n\n```go\nfunc GetDefaultEnv(key string, defaultValue string) string\n```\nGetDefaultEnv get the parameter from env, if not set it use the defaultValue instead\n\n```go\nfunc GetDefaultLogger() *uberzap.SugaredLogger\n```\nGetDefaultLogger returns the default logger for testing\n\n```go\nfunc InitGinkgoWithLogger() *uberzap.SugaredLogger\n```\nInitGinkgoWithLogger initializes Ginkgo and returns a logger.\n\n```go\nfunc InitializeGinkgoConfig()\n```\nInitializeGinkgoConfig initializes the Ginkgo configuration.\n\n```go\nfunc KubeObjectDiffClean(object interface{}) interface{}\n```\nKubeObjectDiffClean will clean these fields in order to clean when diff kubernetes objects\n\n  - CreationTimestamp\n  - ManagedFields\n  - UID\n  - ResourceVersion\n  - Generation\n  - SelfLink\n\nDeprecated: use assertions.DiffEqual and assertions.IgnoreObjectMetaFields instead\n\n```go\nfunc ListByGVK(gvk schema.GroupVersionKind) *unstructured.UnstructuredList\n```\nListByGVK creates a new UnstructuredList initialized with the given GroupVersionKind. Very useful for listing resources using only GroupVersionKind.\n\n```go\nfunc LoadJSON(file string, obj interface{}) (err error)\n```\nLoadJSON loads json\n\n```go\nfunc LoadKubeResources(file string, clt client.Client, converts ...ConvertRuntimeObjctToClientObjectFunc) (err error)\n```\nLoadKubeResources loading kubernetes resources\n\n```go\nfunc LoadKubeResourcesAsUnstructured(file string) (objs []unstructured.Unstructured, err error)\n```\n\n```go\nfunc LoadMultiYamlOrJson[T any](file string, list *[]T) (err error)\n```\nLoadMultiYamlOrJson loads multi yamls\n\n```go\nfunc LoadMultiYamlOrJsonFromBytes[T any](data []byte, list *[]T) (err error)\n```\nLoadMultiYamlOrJsonFromBytes loads multi yamls For historical reasons, this method still supports JSON documents separated by --- However, --- is not a valid separator for JSON documents. To be compatible with the previous handling logic, we cannot directly use the k8s built-in multiple document unmarshalling method and need to read line by line to implement it.\n\n```go\nfunc LoadObjectOrDie(g *WithT, file string, obj metav1.Object, patches ...func(metav1.Object)) metav1.Object\n```\nLoadObjectOrDie loads object from yaml and returns\n\n```go\nfunc LoadObjectReferenceOrDie(g *WithT, file string, obj *corev1.ObjectReference, patches ...func(*corev1.ObjectReference)) *corev1.ObjectReference\n```\nLoadObjectReferenceOrDie loads object reference from yaml and returns\n\n```go\nfunc LoadResourceFromFile(scheme *runtime.Scheme, path string) (obj runtime.Object, err error)\n```\n\n```go\nfunc LoadResourcesFromFile(scheme *runtime.Scheme, path string) (objs []runtime.Object, err error)\n```\n\n```go\nfunc LoadYAML(file string, obj interface{}) (err error)\n```\nLoadYAML loads yaml\n\n```go\nfunc MustLoadFileBytes(file string) []byte\n```\nMustLoadFileBytes loads a file as \\[]bytes will panic if if failes ONLY FOR TEST USAGE\n\n```go\nfunc MustLoadFileString(file string, content *string)\n```\nMustLoadFileString loads a file as string will panic if if failes ONLY FOR TEST USAGE\n\n```go\nfunc MustLoadJSON(file string, obj interface{})\n```\nMustLoadJSON loads json or panics if the parse fails.\n\n```go\nfunc MustLoadMultiYamlOrJson[T any](file string, list *[]T)\n```\nMustLoadMultiYamlOrJson loads multi yamls or panics if the parse fails.\n\n```go\nfunc MustLoadReturnObjectFromYAML(file string, obj interface{}) interface{}\n```\nMustLoadReturnObjectFromYAML 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\n\n```go\nfunc MustLoadYaml(file string, obj interface{})\n```\nMustLoadYaml loads yaml or panics if the parse fails.\n\n```go\nfunc NewGinkgoLogger() *uberzap.SugaredLogger\n```\nNewGinkgoLogger creates a new logger for Ginkgo tests.\n\n```go\nfunc PrintDiffWantGot(diff string) string\n```\nPrintDiffWantGot takes a diff string generated by cmp.Diff and returns it in a consistent format for reuse across all of our tests. This func assumes that the order of arguments passed to cmp.Diff was (want, got) or, in other words, the expectedResult then the actualResult.\n\n```go\nfunc ReflectName(obj interface{}) string\n```\nReflectName reflect the type name of the object\n\n```go\nfunc RestoreDirectories(fs embed.FS, dirName string, targetDir string)\n```\nRestoreDirectories restore directories from embed.FS to targetDir Deprecated: move to testing/script RestoreDirectories\n\n```go\nfunc RuntimeObjectFromUnstructured(scheme *runtime.Scheme, u *unstructured.Unstructured) (runtime.Object, error)\n```\nRuntimeObjectFromUnstructured converts an unstructured to a runtime object\n\n```go\nfunc SetName(name string) func(metav1.Object)\n```\n\n```go\nfunc SliceToInterfaceSlice[T any](s []T) []interface{}\n```\nSliceToInterfaceSlice convert a slice to a slice of interface\n\n```go\nfunc SliceToRuntimeOjbect[T any](s []T) []runtime.Object\n```\nSliceToRuntimeOjbect convert slice to runtime.Object\n\n```go\nfunc ToObjectList[T client.Object](list []T) []client.Object\n```\nToObjectList converts resource list to a list of client.Object\n\n```go\nfunc UnstructedToTyped(from unstructured.Unstructured, to interface{}) error\n```\nUnstructedToTyped converts an unstructured object into a object Warning: This SHOULD never be used in production code, only in test code\n\n```go\nfunc WarningOnError(logger *zap.SugaredLogger, err error, message string)\n```\nWarningOnError set a warning on error\n\n## Types\n\n```go\ntype ConditionBuilder struct {\n\tapis.Condition\n}\n```\nConditionBuilder builds a conditions in a builder pattern\n\n```go\nfunc BuildCondition() *ConditionBuilder\n```\nBuildCondition starts a condition builder object useful for unit tests that require validating multiple conditions\n\n```go\nfunc (c *ConditionBuilder) Done() *apis.Condition\n```\nSetReasonMessage returns a condition\n\n```go\nfunc (c *ConditionBuilder) SetReasonMessage(reason, message string, formtKeyValues ...interface{}) *ConditionBuilder\n```\nSetReasonMessage sets the message for the condition\n\n```go\nfunc (c *ConditionBuilder) SetStatus(stat corev1.ConditionStatus) *ConditionBuilder\n```\nSetStatus sets the status for the condition\n\n```go\nfunc (c *ConditionBuilder) SetType(ct apis.ConditionType) *ConditionBuilder\n```\nSetType sets the type for the condition\n\n```go\ntype ConvertRuntimeObjctToClientObjectFunc func(runtime.Object) (client.Object, error)\n```\n\n```go\ntype ScriptResult struct {\n\tOutputDataPrefix string\n\t// contains filtered or unexported fields\n}\n```\nScriptResult the result of script execution Deprecated: move to testing/script ScriptResult\n\n```go\nfunc ExecBashScript(script string, params ...string) *ScriptResult\n```\nExecBashScript exec bash script with params Deprecated: move to testing/script ExecBashScript\n\n```go\nfunc ExecScript(name string, arg ...string) *ScriptResult\n```\nExecScript exec script with params Deprecated: move to testing/script ExecScript\n\n```go\nfunc (p *ScriptResult) Error() error\n```\nError get the error of a script execution\n\n```go\nfunc (p *ScriptResult) ExitCode() int\n```\nExitCode get the exit code of a script execution\n\n```go\nfunc (p *ScriptResult) ExitMessage() string\n```\nExitMessage get the exit message of a script execution\n\n```go\nfunc (p *ScriptResult) OutputData(dataPrefix string) string\n```\nOutputData get the output of a script execution, it can be a structured data, e.g: json string\n\n```go\nfunc (p *ScriptResult) Stderr() string\n```\nStderr get the error output of a script execution\n\n```go\nfunc (p *ScriptResult) Stdout() string\n```\nStdout get the output of a script execution\n\n","path":"github.com/AlaudaDevops/pkg/testing","name":"testing","synopsis":"","isRedistributable":true}
