Documentation
¶
Overview ¶
Package test provides e2e tests for Cargoship
Index ¶
- Variables
- func CleanFiles(t *testing.T, paths ...string)
- func ContainerSafeDefinition(src, dst string) (string, error)
- func GetCLIName() string
- func RepoRoot() (string, error)
- func SetupInMemoryRegistry(t *testing.T) string
- func WaitForNodesReady(ctx context.Context, cs dynamic.Interface, expectedCount int, ...) error
- type CargoE2ETest
Constants ¶
This section is empty.
Variables ¶
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.
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 ¶
CleanFiles removes paths, failing the test on error rather than relying on .gitignore alone.
func ContainerSafeDefinition ¶ added in v0.35.0
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 GetCLIName ¶
func GetCLIName() string
GetCLIName looks at the OS and CPU architecture to determine which Cargoship binary needs to be run.
func RepoRoot ¶
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 ¶
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.
Types ¶
type CargoE2ETest ¶
type CargoE2ETest struct {
CargoBinPath string
Arch string
ApplianceMode bool
ApplianceModeKeep bool
// ClusterConfigPath is the absolute path to the generated ZarfCluster 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) KubeClient ¶
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. |
|
tofu
Package tofu drives the OpenTofu provider against a real cluster.
|
Package tofu drives the OpenTofu provider against a real cluster. |