test

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UpdateGoldenFiles = flag.Bool("update", false, "update golden files")

Functions

func AContext added in v0.9.0

func AContext() gomock.Matcher

AContext returns a gomock matchers that evaluates if the receive value can fullfills the context.Context interface

func AssertContentToFile

func AssertContentToFile(t *testing.T, gotContent, wantFile string)

func AssertFilesEquals

func AssertFilesEquals(t *testing.T, gotPath, wantPath string)

func Bundles added in v0.6.0

func Bundles(t *testing.T) *releasev1alpha1.Bundles

func EksdRelease added in v0.8.0

func EksdRelease(t *testing.T) *eksdv1alpha1.Release

func FakeNow

func FakeNow() time.Time

func NewClusterSpec

func NewClusterSpec(opts ...ClusterSpecOpt) *cluster.Spec

func NewFullClusterSpec

func NewFullClusterSpec(t *testing.T, clusterConfigFile string) *cluster.Spec

func NewHTTPServerForFile added in v0.9.0

func NewHTTPServerForFile(t *testing.T, filePath string) *httptest.Server

func NewNullLogger added in v0.11.0

func NewNullLogger() logr.Logger

func NewWriter

func NewWriter(t *testing.T) (dir string, writer filewriter.FileWriter)

func OfType

func OfType(t string) gomock.Matcher

func RandString added in v0.7.1

func RandString(n int) string

func ReadFile

func ReadFile(t *testing.T, file string) string

func ReadFileAsBytes added in v0.12.0

func ReadFileAsBytes(t *testing.T, file string) []byte

func RemoveFileIfExists added in v0.12.0

func RemoveFileIfExists(t *testing.T, filename string)

RemoveFileIfExists is a helper for ValidateFilename tests.

func SanitizePath added in v0.8.0

func SanitizePath(s string) string

SanitizePath sanitizes s so its usable as a path name. For safety, it assumes all characters that are not A-Z, a-z, 0-9, _ or - are illegal and replaces them with _.

func SetTag

func SetTag(image *releasev1alpha1.Image, tag string)

func UseEnvTest added in v0.12.0

func UseEnvTest(t *testing.T) *rest.Config

UseEnvTest sets up the controller-runtime EnvTest framework.

The test will be skipped if EnvTest framework isn't detected.

EnvTest provides fake k8s control plane components for testing purposes. The process of bringing up and tearing down the EnvTest framework involves running a few binaries, and is not integrated into a vanilla "go test" run, but rather can be run via the unit-test target in Makefile. See https://book.kubebuilder.io/reference/envtest.html for details.

TODO: What could be done to integrate EnvTest with go test, so that "go test" would work?

func WithFakeFile added in v0.12.0

func WithFakeFile(t *testing.T) (f *os.File)

WithFakeFile returns a throwaway file in a test-specific directory.

The file is automatically closed and removed when the test ends.

func WithFakeFileContents added in v0.12.0

func WithFakeFileContents(t *testing.T, r io.Reader) (f *os.File)

WithFakeFileContents returns a throwaway file containing some data.

The file is automatically closed and removed when the test ends.

Types

type ClusterSpecOpt

type ClusterSpecOpt func(*cluster.Spec)

type KubeClient added in v0.12.0

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

KubeClient implements kubernetes.Client by using client.Client

func NewFakeKubeClient added in v0.12.0

func NewFakeKubeClient(objs ...client.Object) *KubeClient

NewFakeKubeClient returns a KubeClient that uses a fake client.Client under the hood

func NewFakeKubeClientAlwaysError added in v0.12.0

func NewFakeKubeClientAlwaysError(objs ...client.Object) *KubeClient

NewFakeKubeClientAlwaysError returns a KubeClient that will always fail in any operation This is achieved by injecting an empty Scheme, which will make the underlying client.Client incapable of determining the resource type for a particular client.Object

func NewKubeClient added in v0.12.0

func NewKubeClient(client client.Client) *KubeClient

func (*KubeClient) Get added in v0.12.0

func (c *KubeClient) Get(ctx context.Context, name, namespace string, obj kubernetes.Object) error

Get retrieves an obj for the given name and namespace from the Kubernetes Cluster.

type Reader added in v0.9.0

type Reader interface {
	ReadFile(url string) ([]byte, error)
}

Reader is a commonly used interface in multiple packages We are replicating here just to create a single mock we can use in multiple test packages

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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