{"modulePath":"github.com/AlaudaDevops/pkg","version":"v0.14.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package assertions\n\nPackage assertions contains all the assertions that can be used in tests for general testing. All methods are Gomega compatible and can be used directly with gomega library\n\nPackage assertions contains all the assertions that can be used in tests for general testing. All methods are Gomega compatible and can be used directly with gomega library\n\nPackage assertions contains all the assertions that can be used in tests for cluster testing. All methods are Gomega compatible as async assertions or assertions that can be used directly with other Gomega methods\n\n## Variables\n\n```go\nvar DeepEqual = DiffEqual\n```\nDeepEqual is an alias for DiffEqual uses github.com/google/go-cmp/cmp.Diff to compare objects\n\n```go\nvar DefaultIgnoreObjectMetaFields = []string{\"CreationTimestamp\", \"DeletionTimestamp\", \"DeletionGracePeriodSeconds\", \"Finalizers\", \"UID\", \"Generation\", \"ManagedFields\", \"ResourceVersion\", \"SelfLink\", \"UID\"}\n```\nDefaultIgnoreObjectMetaFields common fields to ignore in metav1.ObjectMeta using cmp.Diff method\n\n```go\nvar IgnoreRawExtension = cmpopts.IgnoreTypes(runtime.RawExtension{})\n```\nIgnoreRawExtension will ignore the fields in runtime.RawExtension in a cmp.Diff comparison\n\n```go\nvar IgnoreTypeMeta = cmpopts.IgnoreTypes(metav1.TypeMeta{})\n```\nIgnoreTypeMeta will ignore the fields in metav1.TypeMeta in a cmp.Diff comparison\n\n## Functions\n\n```go\nfunc BeNilOrEmpty() gtypes.GomegaMatcher\n```\nBeNilOrEmpty generates a GomegaMatcher that checks if the value is nil or empty. works for pointers and to empty values\n\n```go\nfunc DiffEqual(expected interface{}, cmpOptions ...cmp.Option) gomega.OmegaMatcher\n```\nDiffEqual will use github.com/google/go-cmp/cmp.Diff to compare using a list of cmp.Option to add any additional cmp configuration like ignoring types or fields not necessary in the tests. This package offers a few default options like IgnoreObjectMetaFields that can be used with kubernetes Objects\n\n```go\nfunc IgnoreObjectMetaFields(fields ...string) cmp.Option\n```\nIgnoreObjectMetaFields will ignore the fields in metav1.ObjectMeta that are flaky or hard to create expectations for in tests. If no fields are passed, the default set fields are used as DefaultIgnoreTypeMetaFields variable\n\n```go\nfunc IsDone(ctx TestContexter, obj client.Object) error\n```\nIsDone will check if a object is done using IsDone() bool function and return nil when it is. Otherwise will return an error printing the object struct and current data. Recommended to be used with WaitResource method Example:\n\n\tWaitObject(ctx, obj, IsDone).To(Succeed(), \"object should be done: %#v\"  obj)\n\n```go\nfunc WaitObject(ctx TestContexter, obj client.Object, checkFunc ...CheckObjectFunc) AsyncAssertion\n```\nWaitObject will create an Eventually AsyncAssertion that checks for a resource status given the checkFunc function will print an error and return if getting the resource fails. Since it returns AsyncAssertion it is possible to use it with other Gomega methods Example:\n\n\tcheckPod := func(ctx TestContexter, obj client.Object) error { return check.Pod.Check(ctx, obj) }\n\tpod := \u0026corev1.Pod{ObjectMeta{Name: \"pod\", Namespace: \"default\"}}\n\tWaitObject(ctx, pod, checkPod).To(Succeed())\n\n\t// or with custom timeout and intervals\n\tWaitObject(ctx, pod, checkPod).\n\t  WithPolling(time.Second).\n\t  WithTimeout(time.Minute*10).To(Succeed())\n\n## Types\n\n```go\ntype CheckObjectFunc func(ctx TestContexter, obj client.Object) error\n```\nCheckObjectFunc is a function that checks an object and returns an error if it fails useful to be used with WaitResource AsyncAssertion for custom object checks\n\n```go\ntype DiffEqualMatcher struct {\n\t// Expected object\n\tExpected interface{}\n\t// Options for cmp.Diff function. There are multiple available options\n\t// inside the github.com/google/go-cmp/cmp/cmpopts package\n\t// as well as IgnoreTypeMetaFields and the sort of package\n\tOptions []cmp.Option\n\n\t// DiffCleanFunc are deprecated and should be replaced with []cmp.Option\n\tDiffCleanFunc []func(object interface{}) interface{}\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (matcher *DiffEqualMatcher) FailureMessage(_ interface{}) (message string)\n```\nFailureMessage returns a message to be displayed if the actual value does not match the expected value.\n\n```go\nfunc (matcher *DiffEqualMatcher) Match(actual interface{}) (success bool, err error)\n```\nMatch compares the actual and expected values using cmp.Diff and given Options will return true if the values are equivalent, otherwise it will return false with any necessary error messages\n\n```go\nfunc (matcher *DiffEqualMatcher) NegatedFailureMessage(_ interface{}) (message string)\n```\nNegatedFailureMessage returns a message to be displayed if the actual value matches the expected value but is expected to not.\n\n```go\ntype IsDoneObject interface {\n\tclient.Object\n\tIsDone() bool\n}\n```\nIsDoneObject interface to have a client.Object that also implements a IsDone() bool function\n\n```go\ntype TestContexter interface {\n\tGetClient() client.Client\n\tGetLogger() *zap.SugaredLogger\n\tGetContext() context.Context\n}\n```\nTestContexter a basic text context that provides Client, Context and SugeredLogger\n\n","path":"github.com/AlaudaDevops/pkg/testing/assertions","name":"assertions","synopsis":"Package assertions contains all the assertions that can be used in tests for general testing.","isRedistributable":true}
