Documentation
¶
Index ¶
- Variables
- func FindRepoRoot() (string, error)
- func NewMockCommand(name string, flags map[string]string) *cobra.Command
- func NewMockCommandWithBool(name string, boolFlags map[string]bool) *cobra.Command
- func NewMockCommandWithMixed(name string, stringFlags map[string]string, boolFlags map[string]bool) *cobra.Command
- func ProvisionToolchain(logger *log.AtmosLogger, tools []Tool)
- type AtmosRunner
- type MockFSBuilder
- func (b *MockFSBuilder) Build() *filesystem.MockFileSystem
- func (b *MockFSBuilder) WithFile(path string, content []byte) *MockFSBuilder
- func (b *MockFSBuilder) WithFileError(path string, err error) *MockFSBuilder
- func (b *MockFSBuilder) WithMkdirAll(path string, perm os.FileMode) *MockFSBuilder
- func (b *MockFSBuilder) WithMkdirAllError(path string, perm os.FileMode, err error) *MockFSBuilder
- func (b *MockFSBuilder) WithRemoveAll(path string, err error) *MockFSBuilder
- func (b *MockFSBuilder) WithStat(path string, info os.FileInfo, err error) *MockFSBuilder
- func (b *MockFSBuilder) WithTempDir(path string) *MockFSBuilder
- func (b *MockFSBuilder) WithTempDirError(err error) *MockFSBuilder
- func (b *MockFSBuilder) WithWriteFile(path string, content []byte, perm os.FileMode) *MockFSBuilder
- func (b *MockFSBuilder) WithWriteFileError(path string, content []byte, perm os.FileMode, err error) *MockFSBuilder
- type SandboxEnvironment
- type Tool
Constants ¶
This section is empty.
Variables ¶
var DefaultTools = []Tool{
{Repo: "opentofu/opentofu", Version: "1.9.1", Binary: "tofu"},
{Repo: "hashicorp/terraform", Version: "1.9.7", Binary: "terraform"},
{Repo: "hashicorp/packer", Version: "1.14.2", Binary: "packer"},
{Repo: "helmfile/helmfile", Version: "v1.1.0", Binary: "helmfile"},
{Repo: "helm/helm", Version: "v3.19.2", Binary: "helm"},
}
DefaultTools lists the external binaries the CLI suite depends on. The pinned versions must match .github/workflows/test.yml so local and CI runs agree.
Functions ¶
func FindRepoRoot ¶ added in v1.196.0
FindRepoRoot finds the root of the git repository.
func NewMockCommand ¶ added in v1.195.0
NewMockCommand creates a mock Cobra command with the specified flags for testing. This helper simplifies test setup by providing a fluent interface for creating commands.
Example:
cmd := NewMockCommand("test", map[string]string{
"stack": "dev",
"format": "yaml",
})
func NewMockCommandWithBool ¶ added in v1.195.0
NewMockCommandWithBool creates a mock Cobra command with boolean flags.
func NewMockCommandWithMixed ¶ added in v1.195.0
func NewMockCommandWithMixed(name string, stringFlags map[string]string, boolFlags map[string]bool) *cobra.Command
NewMockCommandWithMixed creates a mock Cobra command with both string and boolean flags.
func ProvisionToolchain ¶
func ProvisionToolchain(logger *log.AtmosLogger, tools []Tool)
ProvisionToolchain installs any of the given tools that aren't already on PATH via the Atmos toolchain — dogfooding the toolchain instead of relying on host-installed binaries (brew, setup-* GitHub Actions, …) — and prepends their bin directories to the process PATH so test subprocesses resolve the pinned binaries.
It only provisions tools that are missing ("install as necessary"): in CI the binaries are supplied by setup-* actions, so nothing downloads there; locally (no host binaries) the toolchain installs them. Installation is idempotent and cached across runs.
It is best-effort — on failure (offline, GitHub rate limits) it logs a warning and returns, leaving per-test preconditions to skip the affected tests.
Set ATMOS_TEST_SKIP_TOOL_PROVISION=true to skip entirely and rely on whatever binaries are already on PATH.
Types ¶
type AtmosRunner ¶
type AtmosRunner struct {
// contains filtered or unexported fields
}
AtmosRunner manages running Atmos with optional coverage collection.
func NewAtmosRunner ¶
func NewAtmosRunner(coverDir string) *AtmosRunner
NewAtmosRunner creates a runner that always builds Atmos, with or without coverage instrumentation.
func (*AtmosRunner) BinaryPath ¶
func (r *AtmosRunner) BinaryPath() string
BinaryPath returns the path to the binary being used.
func (*AtmosRunner) Build ¶
func (r *AtmosRunner) Build() error
Build always builds Atmos, with or without coverage instrumentation.
func (*AtmosRunner) Cleanup ¶
func (r *AtmosRunner) Cleanup()
Cleanup removes temporary binary and its directory.
func (*AtmosRunner) Command ¶
func (r *AtmosRunner) Command(args ...string) *exec.Cmd
Command creates an exec.Cmd with GOCOVERDIR and PATH set for nested atmos calls.
func (*AtmosRunner) CommandContext ¶
CommandContext creates an exec.Cmd with context, GOCOVERDIR and PATH set for nested atmos calls.
type MockFSBuilder ¶ added in v1.195.0
type MockFSBuilder struct {
// contains filtered or unexported fields
}
MockFSBuilder provides a fluent interface for building mock filesystem expectations. This simplifies test setup by allowing method chaining for common filesystem operations.
Example:
mockFS := NewMockFS(ctrl).
WithTempDir("/tmp/test-12345").
WithFile("/tmp/test-12345/config.yaml", []byte("test: data")).
WithRemoveAll("/tmp/test-12345", nil).
Build()
func NewMockFS ¶ added in v1.195.0
func NewMockFS(ctrl *gomock.Controller) *MockFSBuilder
NewMockFS creates a new MockFSBuilder.
func (*MockFSBuilder) Build ¶ added in v1.195.0
func (b *MockFSBuilder) Build() *filesystem.MockFileSystem
Build returns the configured MockFileSystem.
func (*MockFSBuilder) WithFile ¶ added in v1.195.0
func (b *MockFSBuilder) WithFile(path string, content []byte) *MockFSBuilder
WithFile sets up an expectation for ReadFile to return the specified content.
func (*MockFSBuilder) WithFileError ¶ added in v1.195.0
func (b *MockFSBuilder) WithFileError(path string, err error) *MockFSBuilder
WithFileError sets up an expectation for ReadFile to return an error.
func (*MockFSBuilder) WithMkdirAll ¶ added in v1.195.0
func (b *MockFSBuilder) WithMkdirAll(path string, perm os.FileMode) *MockFSBuilder
WithMkdirAll sets up an expectation for MkdirAll to succeed.
func (*MockFSBuilder) WithMkdirAllError ¶ added in v1.195.0
func (b *MockFSBuilder) WithMkdirAllError(path string, perm os.FileMode, err error) *MockFSBuilder
WithMkdirAllError sets up an expectation for MkdirAll to return an error.
func (*MockFSBuilder) WithRemoveAll ¶ added in v1.195.0
func (b *MockFSBuilder) WithRemoveAll(path string, err error) *MockFSBuilder
WithRemoveAll sets up an expectation for RemoveAll to succeed or fail.
func (*MockFSBuilder) WithStat ¶ added in v1.195.0
func (b *MockFSBuilder) WithStat(path string, info os.FileInfo, err error) *MockFSBuilder
WithStat sets up an expectation for Stat to return the specified FileInfo.
func (*MockFSBuilder) WithTempDir ¶ added in v1.195.0
func (b *MockFSBuilder) WithTempDir(path string) *MockFSBuilder
WithTempDir sets up an expectation for MkdirTemp to return the specified path.
func (*MockFSBuilder) WithTempDirError ¶ added in v1.195.0
func (b *MockFSBuilder) WithTempDirError(err error) *MockFSBuilder
WithTempDirError sets up an expectation for MkdirTemp to return an error.
func (*MockFSBuilder) WithWriteFile ¶ added in v1.195.0
func (b *MockFSBuilder) WithWriteFile(path string, content []byte, perm os.FileMode) *MockFSBuilder
WithWriteFile sets up an expectation for WriteFile to succeed.
func (*MockFSBuilder) WithWriteFileError ¶ added in v1.195.0
func (b *MockFSBuilder) WithWriteFileError(path string, content []byte, perm os.FileMode, err error) *MockFSBuilder
WithWriteFileError sets up an expectation for WriteFile to return an error.
type SandboxEnvironment ¶
SandboxEnvironment holds the state for a sandboxed test.
func SetupSandbox ¶
func SetupSandbox(t *testing.T, workdir string) (*SandboxEnvironment, error)
SetupSandbox creates an isolated test environment with copied components.
func (*SandboxEnvironment) Cleanup ¶
func (s *SandboxEnvironment) Cleanup()
Cleanup removes the sandbox directory.
func (*SandboxEnvironment) GetEnvironmentVariables ¶
func (s *SandboxEnvironment) GetEnvironmentVariables() map[string]string
GetEnvironmentVariables returns environment variables for sandbox execution.
type Tool ¶
type Tool struct {
// Repo is the toolchain owner/repo spec used to install the tool.
Repo string
// Version is the pinned version. Keep in sync with .github/workflows/test.yml.
Version string
// Binary is the executable name to look for on PATH (e.g. opentofu installs `tofu`).
Binary string
}
Tool describes an external binary the CLI test suite shells out to, pinned to a specific version.