projecttest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// TestDefaultConfigsSubdir is the subdirectory name used for test default configs in the container.
	TestDefaultConfigsSubdir = "testdefaults"

	// TestDefaultConfigsIncludePath is the relative include path to use from a project's azldev.toml
	// to include the test default configs. This path is relative to the project directory.
	TestDefaultConfigsIncludePath = "../" + TestDefaultConfigsSubdir + "/defaults.toml"
)
View Source
const NoArch = "noarch"

NoArch is a constant representing the "noarch" architecture for RPMs.

Variables

This section is empty.

Functions

func NewDynamicTestProject

func NewDynamicTestProject(options ...DynamicTestProjectOption) *dynamicTestProject

NewDynamicTestProject dynamically constructs a new test project that can later be rendered to files and used in a test.

func NewTemplatedTestProject

func NewTemplatedTestProject(
	t *testing.T,
	templateDir string,
	options ...TemplatedTestProjectOption,
) *templatedTestProject

func TestDefaultConfigsDir

func TestDefaultConfigsDir() string

TestDefaultConfigsDir returns the absolute path to the scenario/testdata/defaultconfigs directory. This function uses runtime.Caller to resolve the path relative to this source file's location.

Types

type DynamicTestProjectOption

type DynamicTestProjectOption func(*dynamicTestProject)

TestProjectOption is a function that can be used to modify a TestProject in-place.

func AddComponent

func AddComponent(componentConfig *projectconfig.ComponentConfig) DynamicTestProjectOption

AddComponents adds (or updates) the configuration for a component to the project. The provided configuration value will remain under the ownership of the caller.

func AddFile added in v0.2.0

func AddFile(relativePath, content string) DynamicTestProjectOption

AddFile adds an arbitrary file to the project at the specified relative path. The path must be relative and must not escape the project directory.

func AddSpec

func AddSpec(spec *TestSpec) DynamicTestProjectOption

AddSpec adds (or updates) the contents of a spec file to the project.

func UseTestDefaultConfigs

func UseTestDefaultConfigs() DynamicTestProjectOption

UseTestDefaultConfigs configures the project to include the test default configs. This adds an include directive to the project's azldev.toml that references the test default configs (which must be copied into the container separately using WithTestDefaultConfigs on the ProjectTest).

func WithGitRepo added in v0.2.0

func WithGitRepo() DynamicTestProjectOption

WithGitRepo initializes the project directory as a git repository with an initial commit containing all project files. Required for commands that use synthetic history (e.g., [component render]).

func WithRenderedSpecsDir added in v0.2.0

func WithRenderedSpecsDir(dir string) DynamicTestProjectOption

WithRenderedSpecsDir sets the rendered-specs-dir project config field.

type ProjectTest

type ProjectTest struct {
	// contains filtered or unexported fields
}

ProjectTest represents a runnable, project-oriented test case.

func NewProjectTest

func NewProjectTest(project TestProject, commandArgs []string, options ...ProjectTestOption) *ProjectTest

NewProjectTest creates a new ProjectTest with the specified project and command arguments.

func (*ProjectTest) RunInContainer

func (p *ProjectTest) RunInContainer(t *testing.T) *ProjectTestResults

RunInContainer runs the project test in a container, returning results.

type ProjectTestOption

type ProjectTestOption func(*ProjectTest)

ProjectTestOption is a function that can be used to configure a ProjectTest.

func WithPreCommand added in v0.2.0

func WithPreCommand(args ...string) ProjectTestOption

WithPreCommand adds a command to run before the main test command. Args are shell-quoted for safety. Each invocation is prefixed with 'azldev -C project -v'.

func WithTestDefaultConfigs

func WithTestDefaultConfigs() ProjectTestOption

WithTestDefaultConfigs configures the project test to copy and use the test default configs. When enabled, the test default configs from scenario/testdata/defaultconfigs/ will be copied into the container and made available for the project to include.

type ProjectTestResults

type ProjectTestResults struct {
	// contains filtered or unexported fields
}

ProjectTestResults encapsulates the results of running a ProjectTest in a container.

func (*ProjectTestResults) GetInContainerProjectPath

func (r *ProjectTestResults) GetInContainerProjectPath(pathComponents ...string) string

GetInContainerProjectPath returns the path to the project directory inside the container.

func (*ProjectTestResults) GetJSONResult

func (r *ProjectTestResults) GetJSONResult() []map[string]any

GetJSONResult returns the parsed JSON output of the command-under-test's output.

func (*ProjectTestResults) GetProjectOutputPath

func (r *ProjectTestResults) GetProjectOutputPath(pathComponents ...string) string

GetProjectOutputPath returns the path to the project output directory on the host.

func (*ProjectTestResults) GetRawJSONBytes

func (r *ProjectTestResults) GetRawJSONBytes() []byte

GetRawJSONBytes returns the raw JSON bytes of the command-under-test's output.

type TemplatedTestProjectOption

type TemplatedTestProjectOption func(*templatedTestProject)

TemplatedTestProjectOption is a function that can be used to configure a [templatedTestProject].

func TemplatedUseTestDefaultConfigs

func TemplatedUseTestDefaultConfigs() TemplatedTestProjectOption

TemplatedUseTestDefaultConfigs configures the templated project to include the test default configs. This modifies the project's azldev.toml after copying to add an include directive that references the test default configs (which must be copied into the container separately using WithTestDefaultConfigs on the ProjectTest).

func TemplatedWithGitRepo added in v0.2.0

func TemplatedWithGitRepo() TemplatedTestProjectOption

TemplatedWithGitRepo initializes the project directory as a git repository with an initial commit containing all project files. Required for commands that use synthetic history (e.g., [component build], [component render]).

type TestProject

type TestProject interface {
	// Serialize writes the project to the given directory.
	Serialize(t *testing.T, projectDir string)
}

TestProject is implemented by types that can produce a serial azldev project directory.

type TestSpec

type TestSpec struct {
	// contains filtered or unexported fields
}

TestSpec represents an RPM spec being composed for testing purposes.

func NewSpec

func NewSpec(options ...TestSpecOption) *TestSpec

NewSpec creates a new TestSpec with the specified options.

func (*TestSpec) GetName

func (s *TestSpec) GetName() string

GetName returns the name of the component defined by the spec.

func (*TestSpec) GetRelease

func (s *TestSpec) GetRelease() string

GetRelease returns the release of the component defined by the spec.

func (*TestSpec) GetVersion

func (s *TestSpec) GetVersion() string

GetVersion returns the version of the component defined by the spec.

func (*TestSpec) Render

func (s *TestSpec) Render() string

Render generates the spec file content as a string.

type TestSpecOption

type TestSpecOption func(*TestSpec)

TestSpecOption is a function that can be used to modify a TestSpec in-place.

func WithBuildArch

func WithBuildArch(arch string) TestSpecOption

WithBuildArch sets the build architecture of the component defined by the spec.

func WithName

func WithName(name string) TestSpecOption

WithName sets the name of the component defined by the spec.

func WithRelease

func WithRelease(release string) TestSpecOption

WithRelease sets the release of the component defined by the spec.

func WithVersion

func WithVersion(version string) TestSpecOption

WithVersion sets the version of the component defined by the spec.

Jump to

Keyboard shortcuts

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