utils

package
v0.0.0-...-968e523 Latest Latest
Warning

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

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

Documentation

Overview

nolint:gosec

Index

Constants

View Source
const ArgoCDClientKey envfuncs.ContextKey = "argocd_client"
View Source
const KargoCLIKey envfuncs.ContextKey = "kargo_cli"
View Source
const KargoCLIWatchKey envfuncs.ContextKey = "kargo_watch"
View Source
const TestDataKey envfuncs.ContextKey = "test_data"
View Source
const TestDataPath = "testdata"

Variables

View Source
var (
	TestEnv env.Environment
)
View Source
var TestFeatures []features.Feature

Functions

func ArgoCDCreateHandler

func ArgoCDCreateHandler() decoder.HandlerFunc

func ArgoCDDeleteHandler

func ArgoCDDeleteHandler() decoder.HandlerFunc

func CreateRemoteBranch

func CreateRemoteBranch(ctx context.Context, repoURL, token, branch, fromBranch string) error

CreateRemoteBranch creates branch in the GitHub repository, pointing it at the current head of fromBranch, using the go-github API. Branch ref management is not covered by the gitprovider abstraction, and the e2e suites target a GitHub fork, so this uses go-github directly.

func GetFreight

func GetFreight(ctx context.Context, project, freightID string) (*generated.Freight, error)

func InitEnv

func InitEnv(m *testing.M)

func KargoCreateHandler

func KargoCreateHandler() decoder.HandlerFunc

func KargoDeleteHandler

func KargoDeleteHandler() decoder.HandlerFunc

func MergePullRequest

func MergePullRequest(
	ctx context.Context,
	repoURL, token string,
	prNumber int,
	timeout time.Duration,
) error

MergePullRequest merges the numbered pull request in the given GitHub repository using token for authentication. It retries while the provider reports the pull request as not yet mergeable (mergeability still computing or a transient head change), up to timeout. It is intended to unblock git-wait-for-pr promotion steps, which otherwise never complete in an unattended run.

func MutateAsUnstructured

func MutateAsUnstructured(obj k8s.Object, mutateFunc func(obj runtime.Unstructured) error) error

func MutateAsUnstructuredOptionFor

func MutateAsUnstructuredOptionFor(
	kind, name string,
	mutateFunc func(obj runtime.Unstructured) error,
) decoder.DecodeOption

func MutateOptionFor

func MutateOptionFor(kind, name string, mutateFunc func(obj k8s.Object) error) decoder.DecodeOption

func NewSetupArgoCDFixtures

func NewSetupArgoCDFixtures(options ...decoder.DecodeOption) features.Func

func NewSetupKargoFixtures

func NewSetupKargoFixtures(options ...decoder.DecodeOption) features.Func

func NewTeardownArgoCDFixtures

func NewTeardownArgoCDFixtures(options ...decoder.DecodeOption) features.Func

func NewTeardownKargoFixtures

func NewTeardownKargoFixtures(options ...decoder.DecodeOption) features.Func

func PromoteAndWaitForPhase

func PromoteAndWaitForPhase(
	ctx context.Context,
	t *testing.T,
	project, stage, freightName string,
	phase kargoapi.PromotionPhase,
	timeout time.Duration,
) (*kargoapi.Promotion, error)

PromoteAndWaitForPhase starts a promotion of freightName to stage and waits until the promotion reaches phase, which may be a running or a terminal phase. It asserts the observed phase equals phase.

func PromoteWithPRMerge

func PromoteWithPRMerge(
	ctx context.Context,
	t *testing.T,
	project, stage, freightName string,
	repoURL, token, prStepAlias string,
	timeout time.Duration,
) (*kargoapi.Promotion, error)

PromoteWithPRMerge promotes freightName to a stage whose promotion opens a pull request and blocks on git-wait-for-pr. It waits for the promotion to be Running, reads the pull request number recorded by the git-open-pr step (identified by prStepAlias), merges that pull request via the GitHub API using token, then waits for the promotion to succeed.

func PromotionStepOutput

func PromotionStepOutput(promotion *kargoapi.Promotion, stepAlias, key string) (string, bool)

PromotionStepOutput returns the string value stored by the step with the given alias under key in the promotion's shared state (i.e. the value a step referenced as outputs[stepAlias].key).

func RefreshStage

func RefreshStage(
	ctx context.Context,
	_ *testing.T,
	project, stage string,
) error

func RequireArgoCDCLI

func RequireArgoCDCLI(ctx context.Context, t *testing.T, _ *envconf.Config) context.Context

func RequireContextValue

func RequireContextValue(key envfuncs.ContextKey) features.Func

func RequireEnvValue

func RequireEnvValue(path []string) features.Func

func RequireKargoCli

func RequireKargoCli(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context

func SetupArgoCDFixtures

func SetupArgoCDFixtures(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context

func SetupArgoCDFixturesWithOptions

func SetupArgoCDFixturesWithOptions(
	ctx context.Context,
	t *testing.T,
	_ *envconf.Config,
	options ...decoder.DecodeOption,
) context.Context

func SetupArgoCDFixturesWithRepoURL

func SetupArgoCDFixturesWithRepoURL(appSetName string) features.Func

SetupArgoCDFixturesWithRepoURL returns a features.Func that sets up the Argo CD fixtures with the named ApplicationSet's source repoURL substituted for the demo GitOps repository URL configured in the test environment. This mirrors the repo substitution applied to Kargo fixtures.

func SetupArgocdClient

func SetupArgocdClient(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context

func SetupKargoApiClient

func SetupKargoApiClient(ctx context.Context, t *testing.T, _ *envconf.Config) context.Context

func SetupKargoClients

func SetupKargoClients(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context

func SetupKargoFixtures

func SetupKargoFixtures(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context

func SetupKargoFixturesWithOptions

func SetupKargoFixturesWithOptions(
	ctx context.Context,
	t *testing.T,
	_ *envconf.Config,
	options ...decoder.DecodeOption,
) context.Context

func SetupKargoWatchClient

func SetupKargoWatchClient(ctx context.Context, t *testing.T, _ *envconf.Config) context.Context

func SkipIfNoEnvValue

func SkipIfNoEnvValue(path []string) features.Func

func StartPromotion

func StartPromotion(
	ctx context.Context,
	t *testing.T,
	project, stage, freightName string,
	timeout time.Duration,
) string

StartPromotion issues a promote request for freightName to stage and returns the name of the created Promotion.

A Stage transiently rejects a promotion with 400 Bad Request while the freight is still being qualified in an upstream stage, so the request is retried on 400 until it is accepted or timeout elapses. Any other error is fatal immediately.

func TeardownArgoCDFixtures

func TeardownArgoCDFixtures(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context

func TeardownArgoCDFixturesWithOptions

func TeardownArgoCDFixturesWithOptions(
	ctx context.Context,
	t *testing.T,
	_ *envconf.Config,
	options ...decoder.DecodeOption,
) context.Context

func TeardownKargoFixtures

func TeardownKargoFixtures(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context

func TeardownKargoFixturesWithOptions

func TeardownKargoFixturesWithOptions(
	ctx context.Context,
	t *testing.T,
	_ *envconf.Config,
	options ...decoder.DecodeOption,
) context.Context

func TestData

func TestData(testData fs.FS) features.Func

func TryPromoteToStage

func TryPromoteToStage(
	ctx context.Context,
	project, stage, freightName string,
) (int, error)

TryPromoteToStage issues a single promote request for freightName to stage without retrying, returning the HTTP status code and error. It is used to assert whether a promotion is currently permitted (e.g. before a required soak time has elapsed), where an unavailable freight yields 400 Bad Request.

func UpdateApplicationSetRepoURL

func UpdateApplicationSetRepoURL(name, repoURL string) decoder.DecodeOption

UpdateApplicationSetRepoURL returns a DecodeOption that rewrites the repoURL of the source(s) in the named ApplicationSet's Application template. This lets tests point Argo CD Applications at a fork of the demo GitOps repository, mirroring the repo substitution applied to Kargo fixtures via UpdateWarehouseGitRepoURL.

func UpdateApplicationSetTargetRevision

func UpdateApplicationSetTargetRevision(name, targetRevision string) decoder.DecodeOption

UpdateApplicationSetTargetRevision returns a DecodeOption that rewrites the targetRevision of the source(s) in the named ApplicationSet's Application template. This lets tests point Argo CD Applications at a branch created dynamically per test run.

func UpdateGitCredentialsSecret

func UpdateGitCredentialsSecret(name, repoURL, username, password string) decoder.DecodeOption

UpdateGitCredentialsSecret returns a DecodeOption that rewrites the repoURL, username and password of the named git credentials Secret. Core types decode into their typed representation, so this operates on a *corev1.Secret.

func UpdatePromotionTasksVar

func UpdatePromotionTasksVar(name, key, val string) decoder.DecodeOption

func UpdateStagePromotionVar

func UpdateStagePromotionVar(stageName, key, val string) decoder.DecodeOption

UpdateStagePromotionVar returns a DecodeOption that rewrites the value of the promotion variable named key in the named Stage's promotionTemplate. An empty stageName matches every Stage.

func UpdateWarehouseGitRepoURL

func UpdateWarehouseGitRepoURL(name, repoURL string) decoder.DecodeOption

func WaitForFreight

func WaitForFreight(
	ctx context.Context,
	project, freightID string,
	timeout time.Duration, filter func(*kargoapi.Freight) bool,
) (*kargoapi.Freight, error)

func WaitForFreightToBeVerified

func WaitForFreightToBeVerified(
	ctx context.Context,
	t *testing.T,
	project, freightID, stage string,
	timeout time.Duration,
) *kargoapi.Freight

func WaitForLatestFreight

func WaitForLatestFreight(ctx context.Context, project, origin string, timeout time.Duration) (string, error)

func WaitForPromotionPhase

func WaitForPromotionPhase(
	ctx context.Context,
	t *testing.T,
	project, name string,
	phase kargoapi.PromotionPhase,
	timeout time.Duration,
) (*kargoapi.Promotion, error)

WaitForPromotionPhase watches the named promotion until it reaches phase or any terminal phase, whichever comes first, then asserts the observed phase equals phase. Passing a terminal phase makes it wait for completion.

func WaitForPullRequestID

func WaitForPullRequestID(
	ctx context.Context,
	t *testing.T,
	project, name, stepAlias string,
	timeout time.Duration,
) int

WaitForPullRequestID watches the named promotion until the git-open-pr step with the given alias records a pull request id (its pr.id output), returning it. It fails the test if the promotion reaches a terminal phase first or the timeout elapses.

func WaitForStageVerified

func WaitForStageVerified(
	ctx context.Context,
	t *testing.T,
	project, stage string,
	timeout time.Duration,
) *kargoapi.Stage

WaitForStageVerified watches the named Stage until its most recent Freight selection has been verified successfully, returning the Stage. It fails the test if verification reaches a terminal, non-successful phase or the timeout elapses.

Types

type ArgocdE2EClient

type ArgocdE2EClient struct {
	Path       string
	ConfigFile string
	T          *testing.T
}

func (ArgocdE2EClient) Create

func (client ArgocdE2EClient) Create(obj k8s.Object) error

func (ArgocdE2EClient) CreateAppSet

func (client ArgocdE2EClient) CreateAppSet(obj runtime.Unstructured) error

func (ArgocdE2EClient) CreateResource

func (client ArgocdE2EClient) CreateResource(obj runtime.Unstructured, resourceType string, args ...string) error

func (ArgocdE2EClient) Delete

func (client ArgocdE2EClient) Delete(kind, name string) error

func (ArgocdE2EClient) DeleteResource

func (client ArgocdE2EClient) DeleteResource(resourceType, name string) error

type GitCreds

type GitCreds struct {
	RepoURL  string
	Username string
	Password string
}

GitCreds holds the git credentials substituted into git-driven suite fixtures.

func RequireGitCreds

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

RequireGitCreds returns credentials for the demo GitOps repository fork, sourced from the test environment (kargo_demo_gitops_repo + git_pat). The username is derived from the repository owner; GitHub authenticates via the PAT regardless of the username. It fails the test if either value is missing.

Jump to

Keyboard shortcuts

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