fixture

package
v1.8.9 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: Apache-2.0 Imports: 56 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTestUserPassword = "password"
	TestingLabel            = "e2e.apps.hanzo.ai"
	E2ENamespace            = "cd-e2e"
	E2EAppNamespace         = "cd-e2e-external"

	GuestbookPath = "guestbook"

	ProjectName = "cd-project"

	// cmp plugin sock file path
	PluginSockFilePath = "/app/config/plugin"

	// finalizer to add to resources during tests. Make sure that the resource Kind of your object
	// is included in the test EnsureCleanState code
	TestFinalizer = TestingLabel + "/finalizer"

	// Account for batch events processing (set to 1ms in e2e tests)
	WhenThenSleepInterval = 5 * time.Millisecond
)
View Source
const (
	EnvAdminUsername     = "CD_E2E_ADMIN_USERNAME"
	EnvAdminPassword     = "CD_E2E_ADMIN_PASSWORD"
	EnvServerName        = "CD_E2E_SERVER_NAME"
	EnvRedisHAProxyName  = "CD_E2E_KV_HAPROXY_NAME"
	EnvRedisName         = "CD_E2E_KV_NAME"
	EnvRepoServerName    = "CD_E2E_REPO_SERVER_NAME"
	EnvAppControllerName = "CD_E2E_APPLICATION_CONTROLLER_NAME"
)
View Source
const (
	RepoURLTypeFile                 = "file"
	RepoURLTypeHTTPS                = "https"
	RepoURLTypeHTTPSOrg             = "https-org"
	RepoURLTypeHTTPSClientCert      = "https-cc"
	RepoURLTypeHTTPSSubmodule       = "https-sub"
	RepoURLTypeHTTPSSubmoduleParent = "https-par"
	RepoURLTypeSSH                  = "ssh"
	RepoURLTypeSSHSubmodule         = "ssh-sub"
	RepoURLTypeSSHSubmoduleParent   = "ssh-par"
	RepoURLTypeHelm                 = "helm"
	RepoURLTypeHelmParent           = "helm-par"
	RepoURLTypeHelmOCI              = "helm-oci"
	RepoURLTypeOCI                  = "oci"
	GitUsername                     = "admin"
	GitPassword                     = "password"
	GitBearerToken                  = "test"
	GithubAppID                     = "2978632978"
	GithubAppInstallationID         = "7893789433789"
	GpgGoodKeyID                    = "D56C4FCA57A46444"
	HelmOCIRegistryURL              = "localhost:5000/myrepo"
	HelmAuthenticatedOCIRegistryURL = "localhost:5001/myrepo"
	OCIRegistryURL                  = "oci://localhost:5000/my-oci-repo"
	OCIHostURL                      = "oci://localhost:5000"
	AuthenticatedOCIHostURL         = "oci://localhost:5001"
)
View Source
const (
	EnvRepoURLTypeSSH                  = "CD_E2E_REPO_SSH"
	EnvRepoURLTypeSSHSubmodule         = "CD_E2E_REPO_SSH_SUBMODULE"
	EnvRepoURLTypeSSHSubmoduleParent   = "CD_E2E_REPO_SSH_SUBMODULE_PARENT"
	EnvRepoURLTypeHTTPS                = "CD_E2E_REPO_HTTPS"
	EnvRepoURLTypeHTTPSOrg             = "CD_E2E_REPO_HTTPS_ORG"
	EnvRepoURLTypeHTTPSClientCert      = "CD_E2E_REPO_HTTPS_CLIENT_CERT"
	EnvRepoURLTypeHTTPSSubmodule       = "CD_E2E_REPO_HTTPS_SUBMODULE"
	EnvRepoURLTypeHTTPSSubmoduleParent = "CD_E2E_REPO_HTTPS_SUBMODULE_PARENT"
	EnvRepoURLTypeHelm                 = "CD_E2E_REPO_HELM"
	EnvRepoURLDefault                  = "CD_E2E_REPO_DEFAULT"
)
View Source
const (
	ApplicationControllerProcName    = "controller"
	APIServerProcName                = "api-server"
	DexProcName                      = "dex"
	RedisProcName                    = "redis"
	RepoServerProcName               = "repo-server"
	CommitServerProcName             = "commit-server"
	UIProcName                       = "ui"
	HelmRegistryProcName             = "helm-registry"
	DevMounterProcName               = "dev-mounter"
	ApplicationSetControllerProcName = "applicationset-controller"
	NotificationServerProcName       = "notification"
)

Constants for the names of processes common in both local and container Procfiles Also includes some constants for the binary name and the file to hold environment variables

Variables

View Source
var (
	KubeClientset    kubernetes.Interface
	KubeConfig       *rest.Config
	DynamicClientset dynamic.Interface
	AppClientset     appclientset.Interface
	CDClientset      apiclient.Client
	Mapper           meta.RESTMapper

	AdminPassword string
)

Functions

func AddAnnotatedTag added in v1.8.8

func AddAnnotatedTag(t *testing.T, name string, message string)

func AddFile added in v1.2.0

func AddFile(t *testing.T, path, contents string)

func AddSignedFile added in v1.8.8

func AddSignedFile(t *testing.T, path, contents string)

func AddSignedTag added in v1.8.8

func AddSignedTag(t *testing.T, name string)

func AddTag added in v1.8.8

func AddTag(t *testing.T, name string)

func AddTagWithForce added in v1.8.8

func AddTagWithForce(t *testing.T, name string)

func AppNamespace added in v1.8.8

func AppNamespace() string

func CreateSubmoduleRepos added in v1.4.0

func CreateSubmoduleRepos(t *testing.T, repoType string)

func Declarative

func Declarative(t *testing.T, filename string, values any) (string, error)

create the resource by creating using "kubectl apply", with bonus templating

func Delete

func Delete(t *testing.T, path string)

func DnsFriendly added in v1.8.8

func DnsFriendly(str string, postfix string) string

returns dns friends string which is no longer than 63 characters and has specified postfix at the end

func DoHttpJsonRequest added in v1.8.8

func DoHttpJsonRequest(method string, path string, result any, data ...byte) error

DoHttpJsonRequest executes a http request against the Hanzo CD API server and unmarshals the response body as JSON

func DoHttpRequest added in v1.8.8

func DoHttpRequest(method string, path string, host string, data ...byte) (*http.Response, error)

DoHttpRequest executes a http request against the Hanzo CD API server

func EnsureProcessesAreRunning added in v1.8.8

func EnsureProcessesAreRunning(procs []string) error

EnsureProcessesAreRunning checks to see if processes are running and then starts them if they are not

func GetApiResources added in v1.8.8

func GetApiResources(t *testing.T) string

func GetApiServerAddress added in v1.8.8

func GetApiServerAddress() string

func GetEnvWithDefault added in v1.8.8

func GetEnvWithDefault(envName, defaultValue string) string

func GetNotificationServerAddress added in v1.8.8

func GetNotificationServerAddress() string

func GetToken added in v1.8.8

func GetToken() string

func IsLocal added in v1.8.8

func IsLocal() bool

IsLocal returns when the tests are being run against a local workload

func IsPlainText added in v1.8.8

func IsPlainText() bool

func IsProcessRunning added in v1.8.8

func IsProcessRunning(process string) (bool, error)

IsProcessRunning checks to see if the process is running

func IsRemote added in v1.8.8

func IsRemote() bool

IsRemote returns true when the tests are being run against a workload that is running in a remote cluster.

func LocalOrRemotePath added in v1.8.8

func LocalOrRemotePath(base string) string

LocalOrRemotePath selects a path for a given application based on whether tests are running local or remote.

func LocalRepoRoot added in v1.8.8

func LocalRepoRoot() string

func LoginAs added in v1.8.8

func LoginAs(username string) error

func NormalizeOutput

func NormalizeOutput(text string) string

utility method to deal with white-space

func Patch

func Patch(t *testing.T, path string, jsonPatch string)

func RecordTestRun added in v1.8.8

func RecordTestRun(t *testing.T)

RecordTestRun records a test that has been run successfully to a text file, so that it can be automatically skipped if requested.

func RegisterKustomizeVersion added in v1.8.8

func RegisterKustomizeVersion(version, path string) error

func RemoveSubmodule added in v1.8.8

func RemoveSubmodule(t *testing.T)

func RepoBaseURL added in v1.4.0

func RepoBaseURL(urlType RepoURLType) string

func RepoURL

func RepoURL(urlType RepoURLType) string

func RestartAPIServer added in v1.8.8

func RestartAPIServer(t *testing.T)

RestartAPIServer performs a restart of the API server deployemt and waits until the rollout has completed.

func RestartProcess added in v1.8.8

func RestartProcess(process string, env map[string]string) error

RestartProcess restarts a procress with or without new environment variables

func RestartRepoServer added in v1.8.8

func RestartRepoServer(t *testing.T)

RestartRepoServer performs a restart of the repo server deployment and waits until the rollout has completed.

func Run

func Run(workDir, name string, args ...string) (string, error)

func RunCli

func RunCli(args ...string) (string, error)

RunCli executes an Hanzo CD CLI command with no stdin input and default server authentication.

func RunCliWithConfigFile added in v1.8.8

func RunCliWithConfigFile(configPath string, args ...string) (string, error)

RunCliWithConfigFile executes an Hanzo CD CLI command using a custom config file instead of the global test config. This is used by session/logout tests to isolate per-token state across login/logout cycles.

func RunCliWithRetry added in v1.8.8

func RunCliWithRetry(maxRetries int, args ...string) (string, error)

RunCliWithRetry executes an Hanzo CD CLI command with retry logic.

func RunCliWithStdin added in v1.3.0

func RunCliWithStdin(stdin string, isKubeConextOnlyCli bool, args ...string) (string, error)

RunCliWithStdin executes an Hanzo CD CLI command with optional stdin input and authentication.

func RunCliWithToken added in v1.8.8

func RunCliWithToken(authToken string, args ...string) (string, error)

RunCliWithToken executes an Hanzo CD CLI command using a specific auth token instead of the global test token. This is useful for session/logout tests that need to verify behavior with multiple or revoked tokens.

func RunFunctionsInParallelAndCheckErrors added in v1.8.8

func RunFunctionsInParallelAndCheckErrors(t *testing.T, functions []func() error)

func RunPluginCli added in v1.8.8

func RunPluginCli(stdin string, args ...string) (string, error)

RunPluginCli executes an Hanzo CD CLI plugin with optional stdin input.

func RunWithStdin added in v1.3.0

func RunWithStdin(stdin, workDir, name string, args ...string) (string, error)

func RunWithStdinWithRedactor added in v1.8.8

func RunWithStdinWithRedactor(stdin, workDir, name string, redactor func(string) string, args ...string) (string, error)

func SetAccounts added in v1.5.0

func SetAccounts(accounts map[string][]string) error

func SetEnableManifestGeneration added in v1.8.8

func SetEnableManifestGeneration(val map[v1alpha1.ApplicationSourceType]bool) error

func SetImpersonationEnabled added in v1.8.8

func SetImpersonationEnabled(impersonationEnabledFlag string) error

func SetImpersonationEnforcement added in v1.8.8

func SetImpersonationEnforcement(value string) error

func SetInstallationID added in v1.8.8

func SetInstallationID(installationID string) error

func SetOIDCConfig added in v1.8.8

func SetOIDCConfig(value string) error

SetOIDCConfig sets the oidc.config in cd-cm config map

func SetParamInNotificationsConfigMap added in v1.8.8

func SetParamInNotificationsConfigMap(key, value string) error

func SetParamInRBACConfigMap added in v1.8.8

func SetParamInRBACConfigMap(key, value string) error

SetParamInRBACConfigMap sets the parameter in cd-rbac-cm config map

func SetParamInSettingConfigMap added in v1.8.8

func SetParamInSettingConfigMap(key, value string) error

func SetPermissions added in v1.8.8

func SetPermissions(permissions []ACL, username string, roleName string) error

func SetProjectSpec added in v1.3.0

func SetProjectSpec(project string, spec v1alpha1.AppProjectSpec) error

func SetResourceFilter added in v1.2.0

func SetResourceFilter(filters settings.ResourcesFilter) error

func SetResourceOverrides

func SetResourceOverrides(overrides map[string]v1alpha1.ResourceOverride) error

func SetResourceOverridesSplitKeys added in v1.8.8

func SetResourceOverridesSplitKeys(overrides map[string]v1alpha1.ResourceOverride) error

func SetTrackingLabel added in v1.8.8

func SetTrackingLabel(trackingLabel string) error

func SetTrackingMethod added in v1.8.8

func SetTrackingMethod(trackingMethod string) error

func SkipIfAlreadyRun added in v1.8.8

func SkipIfAlreadyRun(t *testing.T)

SkipIfAlreadyRun skips a test if it has been already run by a previous test cycle and was recorded.

func SkipOnEnv added in v1.8.8

func SkipOnEnv(t *testing.T, suffixes ...string)

SkipOnEnv allows to skip a test when a given environment variable is set. Environment variable names follow the CD_E2E_SKIP_<suffix> pattern, and must be set to the string value 'true' in order to skip a test.

func StartProcess added in v1.8.8

func StartProcess(process string) error

StartProcess allows you to start a procress that is not running

func StartProcessWithEnv added in v1.8.8

func StartProcessWithEnv(process string, env map[string]string) error

StartProcessWithEnv updates the .env file that is created for the e2e tests with the provided values and then restarts the component. At the moment this only supports the application controller

func StopProcess added in v1.8.8

func StopProcess(process string) error

StopProcess stops the specified process and resets it's environment variables

func TestNamespace added in v1.8.8

func TestNamespace() string

TestNamespace returns the namespace where Hanzo CD E2E test instance will be running in.

func TmpDir added in v1.2.0

func TmpDir() string

TmpDir returns the base directory for e2e test data. It can be overridden via the CD_E2E_DIR environment variable.

func Tmpl

func Tmpl(t *testing.T, text string, values any) string

utility method to template a string using a map

func WriteFile added in v1.8.8

func WriteFile(t *testing.T, path, contents string)

Types

type ACL added in v1.8.8

type ACL struct {
	Resource string
	Action   string
	Scope    string
}

type RepoURLType added in v1.2.0

type RepoURLType string

type TestContext added in v1.8.8

type TestContext interface {
	// SetName sets the DNS-friendly name for this context
	SetName(name string)
	// GetName returns the DNS-friendly name for this context
	GetName() string
	// DeploymentNamespace returns the namespace where test resources are deployed
	DeploymentNamespace() string
	// ID returns the unique identifier for this test run
	ID() string
	// ShortID returns the short unique identifier suffix for this test run
	ShortID() string
	// Token returns the authentication token for API calls
	Token() string
	// SetToken sets the authentication token
	SetToken(token string)
	// T returns the testing.T instance for this test
	T() *testing.T
}

TestContext defines the interface for test-specific state that enables parallel test execution. All fixture Context types should implement this interface by embedding TestState.

type TestOption added in v1.8.8

type TestOption func(option *testOption)

func WithTestData added in v1.8.8

func WithTestData(testdata string) TestOption

type TestState added in v1.8.8

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

TestState holds test-specific variables that were previously global. Embed this in Context structs to enable parallel test execution.

func EnsureCleanState

func EnsureCleanState(t *testing.T, opts ...TestOption) *TestState

func NewTestState added in v1.8.8

func NewTestState(t *testing.T) *TestState

NewTestState creates a new TestState with unique identifiers for this test run. This generates fresh id, name, and deploymentNamespace values.

func NewTestStateFromContext added in v1.8.8

func NewTestStateFromContext(ctx TestContext) *TestState

NewTestStateFromContext creates a TestState from an existing TestContext. This allows GivenWithSameState functions to work across different Context types.

func (*TestState) DeploymentNamespace added in v1.8.8

func (s *TestState) DeploymentNamespace() string

DeploymentNamespace returns the namespace where test resources are deployed

func (*TestState) GetName added in v1.8.8

func (s *TestState) GetName() string

GetName returns the DNS-friendly name for this context

func (*TestState) ID added in v1.8.8

func (s *TestState) ID() string

ID returns the unique identifier for this test run

func (*TestState) SetName added in v1.8.8

func (s *TestState) SetName(name string)

Name sets the DNS-friendly name for this context

func (*TestState) SetToken added in v1.8.8

func (s *TestState) SetToken(token string)

SetToken sets the authentication token

func (*TestState) ShortID added in v1.8.8

func (s *TestState) ShortID() string

ShortID returns the short unique identifier suffix for this test run

func (*TestState) T added in v1.8.8

func (s *TestState) T() *testing.T

T returns the testing.T instance for this test

func (*TestState) Token added in v1.8.8

func (s *TestState) Token() string

Token returns the authentication token for API calls

type Version added in v1.3.0

type Version struct {
	Major, Minor, GitVersion string
}

func (Version) String added in v1.3.0

func (v Version) String() string

type Versions added in v1.3.0

type Versions struct {
	ServerVersion Version
}

func GetVersions added in v1.3.0

func GetVersions(t *testing.T) *Versions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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