testing

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultScriptOutputPrefix = "##output##"

DefaultScriptOutputPrefix the prefix of script output

Variables

View Source
var IgnoreVolatileTime = cmpopts.IgnoreTypes(apis.VolatileTime{})

IgnoreVolatileTime is a cmp option to ignore VolatileTime

Functions

func Case added in v0.11.0

func Case(caseName string) Labels

Case the unique case name label

func ConditionIsReady added in v0.7.0

func ConditionIsReady(condition *apis.Condition) error

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

func DeleteResources(file string, clt client.Client) (err error)

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

func GetCaseNames(name string) []string

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

func GetDefaultEnv(key string, defaultValue string) string

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 LoadJSON added in v0.7.0

func LoadJSON(file string, obj interface{}) (err error)

LoadJSON loads json

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

func LoadMultiYamlOrJson[T any](file string, list *[]T) (err error)

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 LoadResourceFromFile(scheme *runtime.Scheme, path string) (obj runtime.Object, err error)

func LoadResourcesFromFile

func LoadResourcesFromFile(scheme *runtime.Scheme, path string) (objs []runtime.Object, err error)

func LoadYAML

func LoadYAML(file string, obj interface{}) (err error)

LoadYAML loads yaml

func MustLoadFileBytes added in v0.10.0

func MustLoadFileBytes(file string) []byte

MustLoadFileBytes loads a file as []bytes will panic if if failes ONLY FOR TEST USAGE

func MustLoadFileString added in v0.7.0

func MustLoadFileString(file string, content *string)

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

func MustLoadMultiYamlOrJson[T any](file string, list *[]T)

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

func RestoreDirectories(fs embed.FS, dirName string, targetDir string)

RestoreDirectories restore directories from embed.FS to targetDir

func RuntimeObjectFromUnstructured

func RuntimeObjectFromUnstructured(scheme *runtime.Scheme, u *unstructured.Unstructured) (runtime.Object, error)

RuntimeObjectFromUnstructured converts an unstructured to a runtime object

func SetName

func SetName(name string) func(metav1.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

func SliceToRuntimeOjbect[T any](s []T) []runtime.Object

SliceToRuntimeOjbect convert slice to runtime.Object

func ToObjectList added in v0.7.0

func ToObjectList[T client.Object](list []T) []client.Object

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

type ConditionBuilder struct {
	apis.Condition
}

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

SetStatus sets the status for the condition

func (*ConditionBuilder) SetType

SetType sets the type for the condition

type ConvertRuntimeObjctToClientObjectFunc added in v0.3.0

type ConvertRuntimeObjctToClientObjectFunc func(runtime.Object) (client.Object, error)

type ScriptResult added in v0.10.0

type ScriptResult struct {
	OutputDataPrefix string
	// contains filtered or unexported fields
}

ScriptResult the result of script execution

func ExecBashScript added in v0.10.0

func ExecBashScript(script string, params ...string) *ScriptResult

ExecBashScript exec bash script with params

func ExecScript added in v0.10.0

func ExecScript(name string, arg ...string) *ScriptResult

ExecScript exec script with params

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

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.
opa
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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL