matcher

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrContainElementNTimesInvalidArgument is returned when ContainElementNTimes ACTUAL is not array/slice/map
	ErrContainElementNTimesInvalidArgument = errors.New("ContainElementNTimes matcher expects an array/slice/map")
)
View Source
var (
	// ErrMatcherExpectsAPIObjectPointer is returned when matcher is called with an actual other than *APIObject
	ErrMatcherExpectsAPIObjectPointer = errors.New("matcher expects an *APIObject")
)
View Source
var (
	// ErrObjectMatcherTypeMismatch is returned when ObjectMatcher is called with different Object types
	ErrObjectMatcherTypeMismatch = errors.New("Provided Objects have different types")
)

Functions

func ContainElementNTimes

func ContainElementNTimes(element interface{}, n int) types.GomegaMatcher

ContainElementNTimes succeeds if actual contains the given element n-times. This matcher is a slightly modified version of gomegas own ContainElement matcher.

func Created

func Created(n int) gomegaTypes.GomegaMatcher

Created checks if *APIObject was created n times (ignoring FakeExisting)

func Destroyed

func Destroyed(n int) gomegaTypes.GomegaMatcher

Destroyed checks if *APIObject was destroyed n times

Example

Destroyed is a custom gomega matcher which is used to test if an object was destroyed

// defer GinkgoRecover() is not needed when assertion is done within Ginkgo environment
defer GinkgoRecover()

a := mock.NewMockAPI()

record := clouddnsv1.Record{ZoneName: "example.com", Name: "webmail"}

if err := a.Create(context.TODO(), &record); err != nil {
	log.Fatalf("failed to create record: %s", err)
}

if err := a.Destroy(context.TODO(), &clouddnsv1.Record{Identifier: record.Identifier}); err != nil {
	log.Fatalf("failed destroy record: %s", err)
}

Expect(a.All()).To(
	ContainElement(
		SatisfyAll(
			Destroyed(1),
			Object(&clouddnsv1.Record{Identifier: record.Identifier}, "Identifier"),
		),
	),
)

fmt.Println("Success")
Output:

Success

func Existing

func Existing() gomegaTypes.GomegaMatcher

Existing checks if APIObject does currently exist

func Object

func Object(obj types.Object, matchFields ...string) gomegaTypes.GomegaMatcher

Object matches APIObject with provided Object It compares Objects by matchFields

Example

Object is a custom gomega matcher which is used to test for matching objects on the MockAPI instance by comparing the type and provided field names

// defer GinkgoRecover() is not needed when assertion is done within Ginkgo environment
defer GinkgoRecover()

a := mock.NewMockAPI()

if err := a.Create(context.TODO(), &clouddnsv1.Record{ZoneName: "example.com", Name: "webmail"}); err != nil {
	log.Fatalf("failed to create DNS record: %s", err)
}

// a.Existing() retrieves all objects which aren't currently flagged as destroyed
Expect(a.Existing()).To(
	ContainElement(
		Object(&clouddnsv1.Record{ZoneName: "example.com"}, "ZoneName"),
	),
)

fmt.Println("Success")
Output:

Success

func TaggedWith

func TaggedWith(tags ...string) gomegaTypes.GomegaMatcher

TaggedWith checks if APIObject is tagged with tags

Example

TaggedWith is a custom gomega matcher which is used to test if an object was tagged with the provided tags

// defer GinkgoRecover() is not needed when assertion is done within Ginkgo environment
defer GinkgoRecover()

a := mock.NewMockAPI()

zone := clouddnsv1.Zone{Name: "example.com"}

if err := a.Create(context.TODO(), &zone); err != nil {
	log.Fatalf("failed to create DNS zone: %s", err)
}

if err := corev1.Tag(context.Background(), a, &zone, "Tag-0", "Tag-1", "Tag-2"); err != nil {
	log.Fatalf("failed to tag zone: %s", err)
}

Expect(a.Existing()).To(
	ContainElement(
		SatisfyAll(
			Object(&zone, "Name"),
			TaggedWith("Tag-0", "Tag-1"),
		),
	),
)

fmt.Println("Success")
Output:

Success

func Updated

func Updated(n int) gomegaTypes.GomegaMatcher

Updated checks if *APIObject was updated n times

Types

This section is empty.

Jump to

Keyboard shortcuts

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