create

package
v1.151.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: Apache-2.0 Imports: 67 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultWaitForReadyTimeout = 35 * time.Minute

Variables

This section is empty.

Functions

func DeleteResources added in v1.111.0

func DeleteResources(t *Harness, opts CreateDeleteTestOptions)

func MaybeSkip added in v1.101.0

func MaybeSkip(t *testing.T, testKey string, resources []*unstructured.Unstructured)

func RunCreateDeleteTest

func RunCreateDeleteTest(t *Harness, opt CreateDeleteTestOptions)

func SetupNamespacesAndApplyDefaults

func SetupNamespacesAndApplyDefaults(t *Harness, resources []*unstructured.Unstructured, project testgcp.GCPProject)

func WaitForObservedGeneration added in v1.151.0

func WaitForObservedGeneration(h *Harness, timeout time.Duration, unstructs ...*unstructured.Unstructured)

func WaitForReady added in v1.114.1

func WaitForReady(h *Harness, timeout time.Duration, unstructs ...*unstructured.Unstructured)

Types

type CreateDeleteTestOptions added in v1.112.0

type CreateDeleteTestOptions struct {
	// Create is the set of objects to create
	Create []*unstructured.Unstructured

	// Updates is the set of objects to update (after all objects have been created)
	Updates []*unstructured.Unstructured

	// PrimaryResource is the primary resource for the test
	PrimaryResource *unstructured.Unstructured

	// CleanupResources is true if we should delete resources when we are done
	CleanupResources bool

	// SkipWaitForDelete true means that we don't wait to query that a resource has been deleted.
	SkipWaitForDelete bool

	// SkipWaitForReady true is mainly used for Paused resources as we don't emit an event for those yet.
	SkipWaitForReady bool

	// CreateInOrder true means that we create each object and wait for the object to be ready.
	// This requires that objects be sorted in creation order.
	CreateInOrder bool

	// DeleteInOrder true means that we delete each object and wait for deletion to complete.
	// This requires that objects be sorted in deletion order.
	DeleteInOrder bool

	// DoNotUseServerSideApplyForCreate uses a normal create for object creation
	// Note: we should use server-side apply for both create and update.
	// If we mix-and-match, we get surprising behaviours e.g. we can't clear a field
	DoNotUseServerSideApplyForCreate bool
}

type GCPTargetMode added in v1.132.0

type GCPTargetMode string
const (
	GCPTargetModeReal GCPTargetMode = "real"
	GCPTargetModeMock GCPTargetMode = "mock"
	GCPTargetModeVCR  GCPTargetMode = "vcr"
)

type Harness

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

	Events     *test.MemoryEventSink
	KubeEvents *test.MemoryEventSink

	Project testgcp.GCPProject

	VCRRecorderNonTF *recorder.Recorder
	VCRRecorderTF    *recorder.Recorder
	VCRRecorderOauth *recorder.Recorder

	// MockGCP holds our mockgcp instance, if we are running against mockgcp
	MockGCP mockgcp.Interface

	// KubeTarget is the kube-emulation mode to use
	// If not set, will use the E2E_KUBE_TARGET env var
	KubeTarget string

	// GCPTarget is the GCP mode to use (real, mock, vcr)
	// If not set, will use the E2E_GCP_TARGET env var
	GCPTarget GCPTargetMode
	// contains filtered or unexported fields
}

func NewHarness

func NewHarness(ctx context.Context, t *testing.T, opts ...HarnessOption) *Harness

func NewHarnessWithManager added in v1.101.0

func NewHarnessWithManager(ctx context.Context, t *testing.T, mgr manager.Manager) *Harness

NewHarnessWithManager builds a Harness for an existing manager. deprecated: Prefer NewHarness, which can construct a manager and mock gcp etc.

func (*Harness) AssertGoldenFileNotFound added in v1.145.0

func (h *Harness) AssertGoldenFileNotFound(path string)

func (*Harness) CompareGoldenFile added in v1.111.0

func (h *Harness) CompareGoldenFile(p string, got string, normalizers ...func(s string) string)

func (*Harness) CompareGoldenObject added in v1.145.0

func (h *Harness) CompareGoldenObject(p string, got []byte)

func (*Harness) ExportParams added in v1.111.0

func (h *Harness) ExportParams() exportparameters.Parameters

ExportParams returns the default parameters.Parameters to use for an export

func (*Harness) FolderID added in v1.130.1

func (t *Harness) FolderID() string

func (*Harness) GCPAuthorization added in v1.132.0

func (h *Harness) GCPAuthorization() oauth2.TokenSource

func (*Harness) GCPHTTPClient added in v1.132.0

func (h *Harness) GCPHTTPClient() *http.Client

GCPHTTPClient is the http.Client to use when talking to GCP It is wired up to our mocks for tests.

func (*Harness) GetClient

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

func (*Harness) GetRESTConfig added in v1.118.2

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

func (*Harness) MustReadFile added in v1.111.0

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

func (*Harness) NoExtraGoldenFiles added in v1.114.1

func (h *Harness) NoExtraGoldenFiles(glob string)

func (*Harness) RegisteredServices added in v1.129.2

func (h *Harness) RegisteredServices() mockgcpregistry.Normalizer

type HarnessOption added in v1.125.0

type HarnessOption func(*Harness)

func FilterCRDs added in v1.125.0

func FilterCRDs(filterCRDs func(gk schema.GroupKind) bool) HarnessOption

func WithGCPTarget added in v1.132.0

func WithGCPTarget(gcpTarget GCPTargetMode) HarnessOption

func WithKubeTarget added in v1.132.0

func WithKubeTarget(kubeTarget string) HarnessOption

func WithVCRPath added in v1.125.0

func WithVCRPath(vcrPath string) HarnessOption

type Sample

type Sample struct {
	Name      string
	APIGroup  string
	Resources []*unstructured.Unstructured
}

func LoadAllSamples added in v1.113.0

func LoadAllSamples(t *testing.T, project testgcp.GCPProject) []Sample

LoadAllSamples loads all the samples.

func LoadMatchingSamples added in v1.113.0

func LoadMatchingSamples(t *testing.T, regex *regexp.Regexp, project testgcp.GCPProject) []Sample

LoadMatchingSamples loads the samples that match the regex

func LoadSample added in v1.113.0

func LoadSample(t *testing.T, sampleKey SampleKey, project testgcp.GCPProject) Sample

LoadSample loads one sample

type SampleKey added in v1.113.0

type SampleKey struct {
	// Name is the sample name; it is typically only the last directory name
	// deprecated: prefer TestKey instead
	Name string

	// TestKey is the relative path to the sample from the "root" samples directory
	TestKey string

	// AbsoluteSourceDir is the absolute path to the directory containing the sample
	AbsoluteSourceDir string

	APIGroup string
	// contains filtered or unexported fields
}

SampleKey contains the metadata for a sample. This lets us defer variable substitution.

func ListAllSamples added in v1.113.0

func ListAllSamples(t *testing.T) []SampleKey

ListAllSamples gets the keys for all the samples without loading them.

func ListMatchingSamples added in v1.113.0

func ListMatchingSamples(t *testing.T, regex *regexp.Regexp) []SampleKey

ListMatchingSamples gets the keys for all samples matching the regex, without loading them.

Jump to

Keyboard shortcuts

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