A machine-readable index of this documentation for AI agents is available at https://kubevela.io/llms.txt. Markdown versions of documentation pages are available by appending .md to their URLs.
Skip to main content
Version: Next

CLI and Go

Running definition tests: the vela def test command, its output and exit codes, and the Go suite that runs the same cases.

vela def test​

vela def test [PATH] [flags]

Runs the *_test.cue files at PATH, a file or a directory searched recursively. PATH defaults to the current directory.

FlagDescription
-v, --verboseList passing cases as well as failures.
--jsonPrint results as JSON. See JSON output.
--label-filterRun only cases whose labels match this Ginkgo label query, such as 'status && !slow'.
--focusRun only cases whose full text (<PATH> <file> <definition> / <case>) matches this regular expression. Repeatable.
--skipSkip cases whose full text matches this regular expression. Repeatable.
--focus-fileRun only cases in files matching this regular expression, optionally with lines: file:12, file:3,9 or file:1-20. Repeatable.
--check-pendingRun @pending cases too, and fail any that now pass, since their marker is stale.
--fail-on-pendingFail if any selected case is @pending.
--upgradeRun definitions through KubeVela's CUE upgrader, with every rewrite pass on, instead of testing them as written.
--fail-on-upgradeFail @upgrade cases that fail as written, instead of retrying them upgraded.
--envtest-assetsDirectory holding etcd and kube-apiserver for step and source cases. Defaults to KUBEBUILDER_ASSETS.
--crdsCRD file or directory to install for step and source cases. Defaults to the vela-core chart's, when one is found above the test files. Repeatable.

Render, status, policy and addon cases contact no cluster. Step and source cases run against a local API server with no controllers, started on first use and stopped on exit; install its binaries with setup-envtest (setup-envtest use -p path prints their directory).

Exit codes​

CodeMeaning
0Every selected case passed, or is pending or upgraded.
1A case failed, a test file failed to load, a pending case passed under --check-pending, a case was pending under --fail-on-pending, or the command itself failed.
128 + nInterrupted by signal n, as a shell reports it; the test server is stopped first.

JSON output​

--json prints an array with one object per case, and one per test file that failed to load:

[
{
"file": "web_test.cue",
"line": 21,
"definition": "web",
"test": "component-render",
"case": "runs one replica by default",
"labels": ["component", "render"],
"passed": true
}
]
FieldPresentDescription
file, linealways; line for casesWhere the case or file is.
definition, test, case, labelsfor casesThe definition's name, the function (component-render, workflowstep-exec, ...), the case's description, and its labels.
passedalwaysWhether the case passed.
failureswhen there are anyWhy it failed, or why the file failed to load.
loadfor a file that failed to loadtrue.
skippedfor a case the filters did not selecttrue.
pendingfor a @pending casetrue.
upgradedfor an @upgrade case that passed once upgradedtrue.
reasonwith pending or upgradedThe marker's reason.

Go: ginkgotest​

github.com/oam-dev/kubevela/pkg/definition/cuetest/ginkgotest runs the same cases from a Go suite.

FunctionDescription
DescribeDefinitions(path, opts...)Registers an ordered container for path, with a container per test file and a spec per case, labelled with the case's labels and located at the case. A @pending case is a pending spec, and an @upgrade case that passes once upgraded carries its reason as a report entry. Call it at package level.
WithEnvtestAssets(dir)The directory holding etcd and kube-apiserver, in place of KUBEBUILDER_ASSETS.
WithCRDs(paths...)CRD files or directories to install, in place of the vela-core chart's.
WithUpgrades()Run definitions through the CUE upgrader, with every rewrite pass on.
WithFailOnUpgrade()Fail @upgrade cases that fail as written, instead of retrying them upgraded.

The suite's Test function must set cuex.EnableExternalPackageForDefaultCompiler = false before RunSpecs: renders read CueX's compiler, which otherwise loads external packages from the kubeconfig's cluster. A path's cases run in order on one process; under ginkgo -p, separate paths run on separate processes. See Running tests in CI for a complete suite.