framework

package
v0.23.2 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package framework provides the E2E test framework for cloudflare-operator. It manages Kind cluster lifecycle, mock server, and test utilities.

Index

Constants

View Source
const (
	// DefaultTimeout is the default timeout for operations
	DefaultTimeout = 5 * time.Minute
	// DefaultInterval is the default polling interval
	DefaultInterval = 2 * time.Second
	// KindClusterName is the name of the Kind cluster
	KindClusterName = "cloudflare-operator-e2e"
	// OperatorNamespace is the namespace where the operator is deployed
	OperatorNamespace = "cloudflare-operator-system"
	// TestNamespace is the default namespace for E2E tests
	TestNamespace = "e2e-test"
	// MockServerNamespace is the namespace where the mock server is deployed
	MockServerNamespace = "cloudflare-mock"
	// MockServerName is the name of the mock server deployment/service
	MockServerName = "mockserver"
	// MockServerImage is the Docker image for the mock server
	MockServerImage = "cloudflare-mockserver:e2e-test"
	// MockServerPort is the port the mock server listens on
	MockServerPort = 8787
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Framework

type Framework struct {
	Client         client.Client
	MockServer     *mockserver.Server
	KubeconfigPath string
	ClusterCreated bool
	// contains filtered or unexported fields
}

Framework provides utilities for E2E testing

func New

func New(opts *Options) (*Framework, error)

New creates a new test framework

func (*Framework) BuildMockServerImage

func (*Framework) BuildMockServerImage() error

BuildMockServerImage builds the mock server Docker image

func (*Framework) Cleanup

func (f *Framework) Cleanup()

Cleanup cleans up the test framework resources

func (*Framework) CleanupTestNamespace

func (f *Framework) CleanupTestNamespace(name string) error

CleanupTestNamespace deletes a test namespace

func (*Framework) Context

func (f *Framework) Context() context.Context

Context returns the framework context

func (*Framework) CreateCloudflareCredentials

func (f *Framework) CreateCloudflareCredentials(name string, apiToken string, accountID string, isDefault bool) error

CreateCloudflareCredentials creates a CloudflareCredentials resource and its secret

func (*Framework) CreateSecret

func (f *Framework) CreateSecret(namespace, name string, data map[string]string) error

CreateSecret creates a secret in the specified namespace

func (*Framework) CreateTestService

func (f *Framework) CreateTestService(namespace, name string, port int32) error

CreateTestService creates a test deployment and service for TunnelBinding tests

func (*Framework) DeleteResource

func (f *Framework) DeleteResource(obj client.Object) error

DeleteResource deletes a resource without waiting

func (*Framework) DeleteResourceAndWait

func (f *Framework) DeleteResourceAndWait(obj client.Object, timeout time.Duration) error

DeleteResourceAndWait deletes a resource and waits for deletion to complete

func (*Framework) DeployMockServerToCluster

func (f *Framework) DeployMockServerToCluster() error

DeployMockServerToCluster deploys the mock server as a Kubernetes deployment

func (*Framework) EnsureNamespaceExists

func (f *Framework) EnsureNamespaceExists(name string) error

EnsureNamespaceExists creates a namespace if it doesn't exist

func (*Framework) GetResource

func (f *Framework) GetResource(obj client.Object, name, namespace string) error

GetResource fetches a resource by name and namespace

func (*Framework) InClusterMockServerURL

func (*Framework) InClusterMockServerURL() string

InClusterMockServerURL returns the in-cluster URL for the mock server

func (*Framework) LoadMockServerImageToKind

func (*Framework) LoadMockServerImageToKind() error

LoadMockServerImageToKind loads the mock server image into Kind

func (*Framework) MockServerURL

func (f *Framework) MockServerURL() string

MockServerURL returns the mock server URL

func (*Framework) PatchOperatorWithMockServerURL

func (f *Framework) PatchOperatorWithMockServerURL() error

PatchOperatorWithMockServerURL patches the operator deployment to use the mock server URL

func (*Framework) ResetMockServer

func (f *Framework) ResetMockServer()

ResetMockServer resets the mock server state

func (*Framework) SetupMockServerInCluster

func (f *Framework) SetupMockServerInCluster() error

SetupMockServerInCluster builds, loads, and deploys the mock server to the cluster

func (*Framework) SetupTestNamespace

func (f *Framework) SetupTestNamespace(name string) error

SetupTestNamespace creates a test namespace

func (*Framework) WaitForCondition

func (f *Framework) WaitForCondition(
	obj client.Object,
	conditionType string,
	expectedStatus metav1.ConditionStatus,
	timeout time.Duration,
) error

WaitForCondition waits for a condition to be true on a resource

func (*Framework) WaitForDeletion

func (f *Framework) WaitForDeletion(obj client.Object, timeout time.Duration) error

WaitForDeletion waits for a resource to be deleted

func (*Framework) WaitForMockServerReady

func (f *Framework) WaitForMockServerReady(timeout time.Duration) error

WaitForMockServerReady waits for the mock server deployment to be available

func (*Framework) WaitForOperatorReady

func (f *Framework) WaitForOperatorReady(timeout time.Duration) error

WaitForOperatorReady waits for the operator deployment to be available

func (*Framework) WaitForStatusField

func (f *Framework) WaitForStatusField(
	obj client.Object,
	fieldChecker func(client.Object) bool,
	timeout time.Duration,
) error

WaitForStatusField waits for a specific status field to have an expected value

type Options

type Options struct {
	// UseExistingCluster uses an existing cluster instead of creating a Kind cluster
	UseExistingCluster bool
	// KubeconfigPath is the path to the kubeconfig file
	KubeconfigPath string
	// MockServerPort is the port for the mock Cloudflare API server (deprecated, use in-cluster mock)
	MockServerPort int
	// SkipMockServer skips starting the mock server (deprecated, use UseInClusterMockServer)
	SkipMockServer bool
	// UseInClusterMockServer deploys mock server to cluster instead of running locally
	UseInClusterMockServer bool
	// SkipMockServerSetup skips all mock server setup (for tests using real API)
	SkipMockServerSetup bool
}

Options configures the test framework

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions returns default framework options

Jump to

Keyboard shortcuts

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