testutil

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2022 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package testutil contains some methods useful to mock components while testing

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BeNotFound added in v0.3.1

func BeNotFound() types.GomegaMatcher

BeNotFound returns a new IsNotFoundErrorMatcher to catch k8s not-found errors.

func FailBecauseNotFound added in v0.3.1

func FailBecauseNotFound() types.GomegaMatcher

FailBecauseNotFound returns a new IsNotFoundErrorMatcher to catch k8s not-found errors.

func FakeCSRRequest

func FakeCSRRequest(commonName string) (csrBytes []byte, err error)

FakeCSRRequest returns the content of a CSR request for testing purposes.

func FakeConfigMap

func FakeConfigMap(namespace, name string, data map[string]string) *corev1.ConfigMap

FakeConfigMap returns a configmap with the specified namespace, name and data.

func FakeEventRecorder

func FakeEventRecorder(bufferSize int) *record.FakeRecorder

FakeEventRecorder returns an event recorder that can be used to capture events.

func FakePodWithSingleContainer

func FakePodWithSingleContainer(namespace, name, image string) *corev1.Pod

FakePodWithSingleContainer returns a pod with the specified namespace and name, and having a single container with the specified image.

func FakeSecret

func FakeSecret(namespace, name string, data map[string]string) *corev1.Secret

FakeSecret returns a secret with the specified namespace, name and data.

func FakeSelfSignedCertificate

func FakeSelfSignedCertificate(commonName string) (certificate []byte, err error)

FakeSelfSignedCertificate returns the content of a self-signed certificate for testing purposes.

func FakeService

func FakeService(namespace, name, clusterIP, protocol string, port int32) *corev1.Service

FakeService returns a service with the specified namespace and name and service info.

func LogsToGinkgoWriter added in v0.4.0

func LogsToGinkgoWriter()

LogsToGinkgoWriter configures klog to output the logs to GinkgoWriter, instead of stdout. This allows to output the logs only in case of failing tests, simplifying troubleshooting.

Types

type Cluster

type Cluster struct {
	// contains filtered or unexported fields
}

func NewTestCluster

func NewTestCluster(crdPath []string) (Cluster, manager.Manager, error)

func (*Cluster) GetCfg

func (c *Cluster) GetCfg() *rest.Config

func (*Cluster) GetClient

func (c *Cluster) GetClient() kubernetes.Interface

GetClient returns the crd client.

func (*Cluster) GetEnv

func (c *Cluster) GetEnv() *envtest.Environment

GetEnv returns the test environment.

type DnsServer

type DnsServer struct {
	// contains filtered or unexported fields
}

func (*DnsServer) GetAddr

func (s *DnsServer) GetAddr() string

func (*DnsServer) GetName

func (s *DnsServer) GetName() string

func (*DnsServer) Serve

func (s *DnsServer) Serve()

func (*DnsServer) ServeDNS

func (s *DnsServer) ServeDNS(w dns.ResponseWriter, r *dns.Msg)

func (*DnsServer) Shutdown

func (s *DnsServer) Shutdown()

type IsNotFoundErrorMatcher added in v0.3.1

type IsNotFoundErrorMatcher struct{}

IsNotFoundErrorMatcher is a custom matcher to check when kubernetes resources do not exist.

func (*IsNotFoundErrorMatcher) FailureMessage added in v0.3.1

func (s *IsNotFoundErrorMatcher) FailureMessage(actual interface{}) (message string)

FailureMessage is called when the matcher fails positively.

func (*IsNotFoundErrorMatcher) Match added in v0.3.1

func (s *IsNotFoundErrorMatcher) Match(actual interface{}) (success bool, err error)

Match is a GomegaMatcher interface method to actually run the matcher.

func (*IsNotFoundErrorMatcher) NegatedFailureMessage added in v0.3.1

func (s *IsNotFoundErrorMatcher) NegatedFailureMessage(actual interface{}) (message string)

NegatedFailureMessage is called when the matcher fails negatively.

type MatchObject added in v0.4.0

type MatchObject struct {
	Name      string
	Namespace string
}

MatchObject is a matcher that matches an object with a given name and namespace.

func (*MatchObject) FailureMessage added in v0.4.0

func (m *MatchObject) FailureMessage(actual interface{}) (message string)

FailureMessage returns a failure message.

func (*MatchObject) Match added in v0.4.0

func (m *MatchObject) Match(actual interface{}) (success bool, err error)

Match checks if it matches an object with a given name and namespace.

func (*MatchObject) NegatedFailureMessage added in v0.4.0

func (m *MatchObject) NegatedFailureMessage(actual interface{}) (message string)

NegatedFailureMessage returns a negated failure message.

Jump to

Keyboard shortcuts

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