komega

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: May 17, 2022 License: Apache-2.0 Imports: 3 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(obj client.Object) func() error

Get returns a function that fetches a resource and returns the occurring error. It can be used with gomega.Eventually() like this

deployment := appsv1.Deployment{ ... }
gomega.Eventually(komega.Get(&deployment)).To(gomega.Succeed())

By calling the returned function directly it can also be used with gomega.Expect(komega.Get(...)()).To(...)

func List

func List(list client.ObjectList, opts ...client.ListOption) func() error

List returns a function that lists resources and returns the occurring error. It can be used with gomega.Eventually() like this

deployments := v1.DeploymentList{ ... }
gomega.Eventually(k.List(&deployments)).To(gomega.Succeed())

By calling the returned function directly it can also be used as gomega.Expect(k.List(...)()).To(...)

func Object

func Object(obj client.Object) func() (client.Object, error)

Object returns a function that fetches a resource and returns the object. It can be used with gomega.Eventually() like this:

deployment := appsv1.Deployment{ ... }
gomega.Eventually(k.Object(&deployment)).To(HaveField("Spec.Replicas", gomega.Equal(pointer.Int32(3))))

By calling the returned function directly it can also be used as gomega.Expect(k.Object(...)()).To(...)

func ObjectList

func ObjectList(list client.ObjectList, opts ...client.ListOption) func() (client.ObjectList, error)

ObjectList returns a function that fetches a resource and returns the object. It can be used with gomega.Eventually() like this:

deployments := appsv1.DeploymentList{ ... }
gomega.Eventually(k.ObjectList(&deployments)).To(HaveField("Items", HaveLen(1)))

By calling the returned function directly it can also be used as gomega.Expect(k.ObjectList(...)()).To(...)

func SetClient

func SetClient(c client.Client)

SetClient sets the client used by the package global functions.

func SetContext

func SetContext(c context.Context)

SetContext sets the context used by the package global functions.

func Update

func Update(obj client.Object, f func(), opts ...client.UpdateOption) func() error

Update returns a function that fetches a resource, applies the provided update function and then updates the resource. It can be used with gomega.Eventually() like this:

deployment := appsv1.Deployment{ ... }
gomega.Eventually(k.Update(&deployment, func (o client.Object) {
  deployment.Spec.Replicas = 3
  return &deployment
})).To(gomega.Succeed())

By calling the returned function directly it can also be used as gomega.Expect(k.Update(...)()).To(...)

func UpdateStatus

func UpdateStatus(obj client.Object, f func(), opts ...client.UpdateOption) func() error

UpdateStatus returns a function that fetches a resource, applies the provided update function and then updates the resource's status. It can be used with gomega.Eventually() like this:

deployment := appsv1.Deployment{ ... }
gomega.Eventually(k.UpdateStatus(&deployment, func (o client.Object) {
  deployment.Status.AvailableReplicas = 1
  return &deployment
})).To(gomega.Succeed())

By calling the returned function directly it can also be used as gomega.Expect(k.UpdateStatus(...)()).To(...)

Types

type Komega

type Komega interface {
	// Get returns a function that fetches a resource and returns the occurring error.
	// It can be used with gomega.Eventually() like this
	//   deployment := appsv1.Deployment{ ... }
	//   gomega.Eventually(k.Get(&deployment)).To(gomega.Succeed())
	// By calling the returned function directly it can also be used with gomega.Expect(k.Get(...)()).To(...)
	Get(client.Object) func() error

	// List returns a function that lists resources and returns the occurring error.
	// It can be used with gomega.Eventually() like this
	//   deployments := v1.DeploymentList{ ... }
	//   gomega.Eventually(k.List(&deployments)).To(gomega.Succeed())
	// By calling the returned function directly it can also be used as gomega.Expect(k.List(...)()).To(...)
	List(client.ObjectList, ...client.ListOption) func() error

	// Update returns a function that fetches a resource, applies the provided update function and then updates the resource.
	// It can be used with gomega.Eventually() like this:
	//   deployment := appsv1.Deployment{ ... }
	//   gomega.Eventually(k.Update(&deployment, func (o client.Object) {
	//     deployment.Spec.Replicas = 3
	//     return &deployment
	//   })).To(gomega.Succeed())
	// By calling the returned function directly it can also be used as gomega.Expect(k.Update(...)()).To(...)
	Update(client.Object, func(), ...client.UpdateOption) func() error

	// UpdateStatus returns a function that fetches a resource, applies the provided update function and then updates the resource's status.
	// It can be used with gomega.Eventually() like this:
	//   deployment := appsv1.Deployment{ ... }
	//   gomega.Eventually(k.Update(&deployment, func (o client.Object) {
	//     deployment.Status.AvailableReplicas = 1
	//     return &deployment
	//   })).To(gomega.Succeed())
	// By calling the returned function directly it can also be used as gomega.Expect(k.UpdateStatus(...)()).To(...)
	UpdateStatus(client.Object, func(), ...client.UpdateOption) func() error

	// Object returns a function that fetches a resource and returns the object.
	// It can be used with gomega.Eventually() like this:
	//   deployment := appsv1.Deployment{ ... }
	//   gomega.Eventually(k.Object(&deployment)).To(HaveField("Spec.Replicas", gomega.Equal(pointer.Int32(3))))
	// By calling the returned function directly it can also be used as gomega.Expect(k.Object(...)()).To(...)
	Object(client.Object) func() (client.Object, error)

	// ObjectList returns a function that fetches a resource and returns the object.
	// It can be used with gomega.Eventually() like this:
	//   deployments := appsv1.DeploymentList{ ... }
	//   gomega.Eventually(k.ObjectList(&deployments)).To(HaveField("Items", HaveLen(1)))
	// By calling the returned function directly it can also be used as gomega.Expect(k.ObjectList(...)()).To(...)
	ObjectList(client.ObjectList, ...client.ListOption) func() (client.ObjectList, error)

	// WithContext returns a copy that uses the given context.
	WithContext(context.Context) Komega
}

Komega is a collection of utilites for writing tests involving a mocked Kubernetes API.

func New

func New(c client.Client) Komega

New creates a new Komega instance with the given client.

Jump to

Keyboard shortcuts

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