test

package
v1.124.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const Namespace = "namespace-1"

Variables

This section is empty.

Functions

func AddSinkToContext added in v1.114.0

func AddSinkToContext(ctx context.Context, sinks ...EventSink) context.Context

AddSinkToContext attaches the sinks to the returned context.

func AddTestLabelsToMap

func AddTestLabelsToMap(m map[string]string)

AddTestLabelsToMap adds test labels to a map directly.

func CRDForGVK added in v1.95.0

func CompareGoldenFile added in v1.114.0

func CompareGoldenFile(t *testing.T, p string, got string, normalizers ...func(s string) string)

CompareGoldenFile performs a file comparison for a golden test.

func CompareGoldenObject added in v1.116.0

func CompareGoldenObject(t *testing.T, p string, got []byte)

func EnsureObjectExists

func EnsureObjectExists(t *testing.T, obj *unstructured.Unstructured, c client.Client)

func EnsureObjectsExist

func EnsureObjectsExist(t *testing.T, objs []*unstructured.Unstructured, c client.Client)

func Equals

func Equals(t *testing.T, o1, o2 interface{}) bool

func FakeCRDsWithHierarchicalResources

func FakeCRDsWithHierarchicalResources() []*apiextensions.CustomResourceDefinition

FakeCRDsWithHierarchicalResources returns a CRD list which includes hierarchical resources to allow for the testing of resources that reference hierarchical resources (e.g. "Project")

func FakeServiceMappings

func FakeServiceMappings() []v1alpha1.ServiceMapping

func FakeServiceMappingsWithHierarchicalResources

func FakeServiceMappingsWithHierarchicalResources() []v1alpha1.ServiceMapping

FakeServiceMappingsWithHierarchicalResources returns a ServiceMapping list which includes hierarchical resources to allow for the testing of resources that reference hierarchical resources (e.g. "Project")

func FromContext added in v1.114.0

func FromContext(ctx context.Context) *testing.T

func IgnoreLeadingComments added in v1.114.0

func IgnoreLeadingComments(s string) string

IgnoreLeadingComments is a normalizer function that strips comments. It will stop when it finds the first non-comment line. It is intended to be used with CompareGoldenFile.

func MustReadFile added in v1.112.0

func MustReadFile(t *testing.T, p string) []byte

MustReadFile reads the specified file, failing the test on error.

func NewBarUnstructured

func NewBarUnstructured(name, ns string, readyStatus corev1.ConditionStatus) *unstructured.Unstructured

func NewFolderUnstructured

func NewFolderUnstructured(name, folderID string, readyStatus corev1.ConditionStatus) *unstructured.Unstructured

func NewIAMServiceAccountUnstructured

func NewIAMServiceAccountUnstructured(name, namespace string) *unstructured.Unstructured

func NewProjectUnstructured

func NewProjectUnstructured(name, projectID string, readyStatus corev1.ConditionStatus) *unstructured.Unstructured

func NewSecretUnstructured

func NewSecretUnstructured(name, ns string, stringData map[string]interface{}) *unstructured.Unstructured

func NewUnstructuredWithObservedState added in v1.114.1

func NewUnstructuredWithObservedState(name, ns string, readyStatus corev1.ConditionStatus) *unstructured.Unstructured

func StringMatchesRegexList

func StringMatchesRegexList(t *testing.T, regexesToMatch []string, targetString string) bool

StringMatchesRegexList is a test utility that returns true if the string matches any regex in a list of strings.

if a regex fails to compile, the test will fail.

func ToUnstruct

func ToUnstruct(t *testing.T, bytes []byte) *unstructured.Unstructured

func ToUnstructWithNamespace

func ToUnstructWithNamespace(t *testing.T, b []byte, namespace string) *unstructured.Unstructured

func TrimLicenseHeaderFromTF

func TrimLicenseHeaderFromTF(yaml string) string

TrimLicenseHeaderFromTF trims the license header in the tf string.

func TrimLicenseHeaderFromYaml

func TrimLicenseHeaderFromYaml(yaml string) string

TrimLicenseHeaderFromYaml trims the license header in the yaml string.

func WithContext added in v1.96.0

func WithContext(ctx context.Context, t *testing.T) context.Context

Types

type DirectoryEventSink added in v1.114.0

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

func NewDirectoryEventSink added in v1.114.0

func NewDirectoryEventSink(outputDir string) *DirectoryEventSink

func (*DirectoryEventSink) AddHTTPEvent added in v1.114.0

func (r *DirectoryEventSink) AddHTTPEvent(ctx context.Context, entry *LogEntry)

type EventSink added in v1.114.0

type EventSink interface {
	AddHTTPEvent(ctx context.Context, entry *LogEntry)
}

An EventSink listens for various events we are able to capture during tests, currently just http requests/responses.

func EventSinksFromContext added in v1.114.0

func EventSinksFromContext(ctx context.Context) []EventSink

EventSinksFromContext gets the EventSink listeners attached to the passed context.

type HTTPRecorder added in v1.96.0

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

func NewHTTPRecorder added in v1.96.0

func NewHTTPRecorder(inner http.RoundTripper, eventSinks ...EventSink) *HTTPRecorder

func (*HTTPRecorder) RoundTrip added in v1.96.0

func (r *HTTPRecorder) RoundTrip(req *http.Request) (*http.Response, error)

type JSONMutator added in v1.114.0

type JSONMutator func(obj map[string]any)

type KubeHarness added in v1.120.0

type KubeHarness struct {
	*testing.T
	Ctx context.Context

	KubeEvents *MemoryEventSink
	// contains filtered or unexported fields
}

KubeHarness is a test harness that brings up a kube-apiserver (only).

func NewKubeHarness added in v1.120.0

func NewKubeHarness(ctx context.Context, t *testing.T) *KubeHarness

NewKubeHarness creates a new KubeHarness.

func (*KubeHarness) CreateDummyCRD added in v1.120.0

func (h *KubeHarness) CreateDummyCRD(group, version, kind string)

CreateDummyCRD registers a CRD so we can create objects in tests

func (*KubeHarness) EnsureNamespaceExists added in v1.120.0

func (h *KubeHarness) EnsureNamespaceExists(name string)

func (*KubeHarness) GetClient added in v1.120.0

func (h *KubeHarness) GetClient() client.Client

func (*KubeHarness) GetRESTConfig added in v1.120.0

func (h *KubeHarness) GetRESTConfig() *rest.Config

func (*KubeHarness) MustReadFile added in v1.120.0

func (h *KubeHarness) MustReadFile(p string) []byte

type LogEntries added in v1.114.1

type LogEntries []*LogEntry

func (LogEntries) FormatHTTP added in v1.114.1

func (s LogEntries) FormatHTTP() string

func (LogEntries) KeepIf added in v1.114.1

func (s LogEntries) KeepIf(pred func(e *LogEntry) bool) LogEntries

KeepIf returns a new LogEntries with only the entries that satisfy the predicate. (where the predicate function returns true)

func (*LogEntries) PrettifyJSON added in v1.114.1

func (s *LogEntries) PrettifyJSON(mutators ...JSONMutator)

func (*LogEntries) RemoveHTTPRequestHeader added in v1.118.2

func (s *LogEntries) RemoveHTTPRequestHeader(key string)

func (*LogEntries) RemoveHTTPResponseHeader added in v1.114.1

func (s *LogEntries) RemoveHTTPResponseHeader(key string)

type LogEntry added in v1.96.0

type LogEntry struct {
	Timestamp time.Time `json:"timestamp,omitempty"`
	Request   Request   `json:"request,omitempty"`
	Response  Response  `json:"response,omitempty"`
	Error     string    `json:"error,omitempty"`
}

func (*LogEntry) FormatHTTP added in v1.114.0

func (e *LogEntry) FormatHTTP() string

func (*LogEntry) PrettifyJSON added in v1.114.0

func (e *LogEntry) PrettifyJSON(mutators ...JSONMutator)

type MemoryEventSink added in v1.114.0

type MemoryEventSink struct {
	HTTPEvents []*LogEntry `json:"httpEvents,omitempty"`
	// contains filtered or unexported fields
}

MemoryEventSink is an EventSink that stores events in memory

func NewMemoryEventSink added in v1.114.0

func NewMemoryEventSink() *MemoryEventSink

func (*MemoryEventSink) AddHTTPEvent added in v1.114.0

func (s *MemoryEventSink) AddHTTPEvent(ctx context.Context, entry *LogEntry)

type Request added in v1.96.0

type Request struct {
	Method string      `json:"method,omitempty"`
	URL    string      `json:"url,omitempty"`
	Header http.Header `json:"header,omitempty"`
	Body   string      `json:"body,omitempty"`
}

func (*Request) AddHeader added in v1.119.0

func (r *Request) AddHeader(key, value string)

func (*Request) FormatHTTP added in v1.114.0

func (r *Request) FormatHTTP() string

func (*Request) ParseBody added in v1.114.0

func (r *Request) ParseBody() map[string]any

func (*Request) PrettifyJSON added in v1.114.0

func (r *Request) PrettifyJSON(mutators ...JSONMutator)

func (*Request) RemoveHeader added in v1.114.0

func (r *Request) RemoveHeader(key string)

func (*Request) ReplaceHeader added in v1.119.0

func (r *Request) ReplaceHeader(key, value string)

type Response added in v1.96.0

type Response struct {
	Status     string      `json:"status,omitempty"`
	StatusCode int         `json:"statusCode,omitempty"`
	Header     http.Header `json:"header,omitempty"`
	Body       string      `json:"body,omitempty"`
}

func (*Response) AddHeader added in v1.119.0

func (r *Response) AddHeader(key, value string)

func (*Response) FormatHTTP added in v1.114.0

func (r *Response) FormatHTTP() string

func (*Response) ParseBody added in v1.114.0

func (r *Response) ParseBody() map[string]any

func (*Response) PrettifyJSON added in v1.114.0

func (r *Response) PrettifyJSON(mutators ...JSONMutator)

func (*Response) RemoveHeader added in v1.114.0

func (r *Response) RemoveHeader(key string)

func (*Response) ReplaceHeader added in v1.119.0

func (r *Response) ReplaceHeader(key, value string)

type Type added in v1.114.0

type Type string
const (
	UnitTestType        Type = "Unit"
	IntegrationTestType Type = "Integration"
)

Directories

Path Synopsis
testsconstants contains constants used in tests.
testsconstants contains constants used in tests.

Jump to

Keyboard shortcuts

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