test

package
v0.42.2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package test provides e2e tests for Cargoship

Index

Constants

This section is empty.

Variables

View Source
var NodesResource = schema.GroupVersionResource{Version: "v1", Resource: "nodes"}

NodesResource names the node resource for the dynamic client. The suite reads node names, labels and two spec/status fields, and the typed clientset would link every Kubernetes API group into the test binary for it.

View Source
var OutsideSource = regexp.MustCompile(`(?m)^\s*-?\s*source:\s*(\.\.[^\s]*)\s*$`)

OutsideSource matches a file source that climbs out of the definition's own directory. The generated manifests write one source per list entry, unquoted. It is exported because the suites assert on what it matched in the copy they built.

Functions

func CleanFiles

func CleanFiles(t *testing.T, paths ...string)

CleanFiles removes paths, failing the test on error rather than relying on .gitignore alone.

func ContainerSafeDefinition added in v0.35.0

func ContainerSafeDefinition(src, dst string) (string, error)

ContainerSafeDefinition copies the distro definition at src into a directory under dst and removes the settings in unsettableSysctls from the copy, returning the path to build the package from. The definitions under example/ are what cargoship ships, so the walks read them rather than carrying a fixture of their own, and edit the copy rather than the original.

The copy keeps the definition's path below example/ rather than flattening it to a basename. The k3s definitions reach three levels up for the files they share with every other k3s version -- killall.sh and the two systemd units in example/k3s/core -- so a flattened copy resolves "../../../k3s/core" somewhere above dst, where nothing exists. That used to cost three warnings and a package quietly missing all three files; staging failures are errors now, so it costs a failed build instead. See copyOutsideSources for the other half.

func ExampleDir added in v0.36.0

func ExampleDir() string

ExampleDir is the directory the shipped distro definitions live under. A suite outside this module joins its definition paths onto this rather than spelling "example" itself, so that one setting moves both the root and every path written against it.

func GetCLIName

func GetCLIName() string

GetCLIName looks at the OS and CPU architecture to determine which Cargoship binary needs to be run.

func RepoRoot

func RepoRoot() (string, error)

RepoRoot walks up from the working directory to the directory holding go.mod, so a suite can sit at any depth under test/e2e without hard-coding how far up the root is.

func SetupInMemoryRegistry

func SetupInMemoryRegistry(t *testing.T) string

SetupInMemoryRegistry starts a plain-HTTP, in-memory OCI registry on an auto-allocated localhost port and returns its address (host:port). Use it against the built cargoship binary with the "--plain-http" flag, e.g. as the destination for "cargoship publish"/"pull" in e2e tests, without needing a real registry or network access. The registry is torn down automatically via t.Cleanup.

func WaitForNodesReady

func WaitForNodesReady(ctx context.Context, cs dynamic.Interface, expectedCount int, timeout time.Duration) error

WaitForNodesReady polls the cluster until expectedCount nodes report Ready, or timeout elapses.

Types

type CargoE2ETest

type CargoE2ETest struct {
	CargoBinPath      string
	Arch              string
	ApplianceMode     bool
	ApplianceModeKeep bool
	// ClusterConfigPath is the absolute path to the generated Cluster inventory YAML
	// pointing at the bootloose-provisioned test cluster. Empty if no cluster was set up.
	ClusterConfigPath string
}

CargoE2ETest Struct holding common fields most of the tests will utilize.

func Bootstrap

func Bootstrap() (CargoE2ETest, string, error)

Bootstrap chdirs into the repo root and returns a CargoE2ETest pointed at the binary built for this platform, along with the root it moved into. Suites that drive the CLI call this from TestMain: they spell every path (example distros, config files, testdata) relative to the repo root, and the binary under test is looked up under build/.

func BootstrapInProcess

func BootstrapInProcess() (CargoE2ETest, string, error)

BootstrapInProcess does what Bootstrap does without requiring a built binary, for suites that call the packages directly instead of shelling out to the CLI. Those suites still need the chdir and the architecture, but nothing under build/, so they can run from a bare checkout. The returned CargoE2ETest has no CargoBinPath and its Cargoship helpers will not work.

func (*CargoE2ETest) CargoInDir

func (e2e *CargoE2ETest) CargoInDir(t *testing.T, dir string, args ...string) (_ string, _ string, err error)

CargoInDir executes a Cargoship command in specific directory.

The staging directory is handed over as DISTRO_TMP_DIR rather than --tmpdir: only the commands that stage package content register that flag, so passing it to every command fails argument parsing on the ones that do not (version, vault, ...). The environment variable is read by viper for all of them, and is ignored where nothing stages.

func (*CargoE2ETest) Cargoship

func (e2e *CargoE2ETest) Cargoship(t *testing.T, args ...string) (_ string, _ string, err error)

Cargoship executes a Cargoship command.

func (*CargoE2ETest) KubeClient

func (e2e *CargoE2ETest) KubeClient(t *testing.T) (dynamic.Interface, error)

KubeClient builds a Kubernetes client from the kubeconfig at $KUBECONFIG.

Directories

Path Synopsis
e2e
cluster
Package cluster holds the e2e tests that need a real multi-node cluster: the install command group, driven against containers provisioned by bootloose.
Package cluster holds the e2e tests that need a real multi-node cluster: the install command group, driven against containers provisioned by bootloose.
Package microvm brings a fleet of Enterprise Linux virtual machines up and down on the developer's own machine, under plain qemu, and renders a Cluster inventory pointing at them.
Package microvm brings a fleet of Enterprise Linux virtual machines up and down on the developer's own machine, under plain qemu, and renders a Cluster inventory pointing at them.

Jump to

Keyboard shortcuts

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