Documentation
¶
Overview ¶
Package components defines component types, definitions, registries, and running component instances used by the test framework.
Index ¶
- Constants
- func AliasFor(d *Definition, ordinal, replicas int) (string, error)
- func Assemble(inj *ConfigInjection, repoRoot string, blockOverlay string, vars Vars) ([]byte, error)
- func EnvFileContent(env map[string]string) []byte
- func Label(name string, ordinal, replicas int) string
- func Merge(base string, overlays ...string) ([]byte, error)
- func MergeTrees(base map[string]any, overlays ...map[string]any) (map[string]any, error)
- func MergeWithVars(vars Vars, base string, overlays ...string) ([]byte, error)
- type ComposeSpec
- type ConfigFormat
- type ConfigInjection
- type ConfigProfile
- type CoverageService
- type DBContract
- type DBType
- type DSN
- type Definition
- func (d *Definition) Endpoint(name string) (Endpoint, bool)
- func (d *Definition) ExternalEndpointNames() []string
- func (d *Definition) IsCompose() bool
- func (d *Definition) IsExternal() bool
- func (d *Definition) Product() string
- func (d *Definition) ResolveDBType(explicit, blockDefault DBType) (DBType, error)
- func (d *Definition) String() string
- func (d *Definition) Validate() error
- func (d *Definition) WithConfigVersion(version string) (*Definition, error)
- func (d *Definition) WithImageVersion(version string) *Definition
- func (d *Definition) WithReleaseVersion(version string) (*Definition, error)
- func (d *Definition) WithStagedFiles(overrides map[string]string) (*Definition, error)
- type Endpoint
- type ExternalEndpoint
- type ExternalSpec
- type FileMount
- type HealthCheck
- type ImageBuild
- type ImageRef
- type Instance
- func (i *Instance) Alias() string
- func (i *Instance) Definition() *Definition
- func (i *Instance) EndpointNames() []string
- func (i *Instance) Host() string
- func (i *Instance) InternalURL(endpoint string) (string, error)
- func (i *Instance) Label() string
- func (i *Instance) MappedPort(endpoint string) (int, error)
- func (i *Instance) Name() string
- func (i *Instance) Ordinal() int
- func (i *Instance) RefreshPorts(mapped map[int]int)
- func (i *Instance) URL(endpoint string) (string, error)
- type Registry
- type ResourceLimits
- type Set
- type Vars
- type WiringSpec
Constants ¶
const VarBlock = "BLOCK"
VarBlock is the overlay variable name for the current block.
Variables ¶
This section is empty.
Functions ¶
func AliasFor ¶
func AliasFor(d *Definition, ordinal, replicas int) (string, error)
AliasFor returns the network alias for a component instance.
func Assemble ¶
func Assemble(inj *ConfigInjection, repoRoot string, blockOverlay string, vars Vars) ([]byte, error)
Assemble merges a component's base, shared, and block overlays.
func EnvFileContent ¶
EnvFileContent renders environment entries for a Compose env file.
func MergeTrees ¶
MergeTrees deep-merges maps in order without modifying the inputs.
Types ¶
type ComposeSpec ¶
type ComposeSpec struct {
// ComposeFile is the repo-relative compose file. Its services are this component's
// internals.
ComposeFile string
// ComposeOverrideFiles are repo-relative Compose files merged after ComposeFile.
// They contain only component-specific overrides.
ComposeOverrideFiles []string
// StagedFiles maps repository-relative source files to their names beside the
// staged Compose file.
StagedFiles map[string]string
// GeneratedFiles maps framework-generated file names to their contents.
GeneratedFiles map[string][]byte
// PrimaryService is the compose service whose ports back this component's
// Endpoints. Everything a test addresses must be on this service.
PrimaryService string
// Services lists the services whose logs are collected.
Services []string
// Env contains variables passed to Compose for interpolation.
Env map[string]string
// CoverageServices lists services and artifact formats collected after shutdown.
CoverageServices []CoverageService
// BootAttempts caps how many times the runtime retries a failed boot of this stack,
// tearing down and relaunching with a fresh stack each time. Zero or one means no
// retry, matching the default for every compose component that does not set this.
BootAttempts int
}
ComposeSpec describes a component backed by a Compose stack.
func (*ComposeSpec) StagingName ¶
func (c *ComposeSpec) StagingName() string
StagingName returns the file name the compose file is staged under.
func (*ComposeSpec) StagingNames ¶
func (c *ComposeSpec) StagingNames() []string
StagingNames returns the staged base Compose file followed by its overrides.
func (*ComposeSpec) WithGenerated ¶
func (c *ComposeSpec) WithGenerated(files map[string][]byte) *ComposeSpec
WithGenerated returns a copy of the spec with generated files added.
type ConfigFormat ¶
type ConfigFormat string
ConfigFormat is the syntax of a component's configuration file.
const TOML ConfigFormat = "toml"
TOML identifies TOML component configuration.
type ConfigInjection ¶
type ConfigInjection struct {
// BaseConfigPath is the product's shipped config, relative to the repo root.
BaseConfigPath string
// root. Optional.
SharedOverlayPath string
// ExtraOverlays are optional overlays merged after the shared overlay and before the
// block-specific overlay.
ExtraOverlays []string
// ContainerPath is where the merged file lands in the container.
ContainerPath string
// Format is the merge syntax.
Format ConfigFormat
// Versioned contains exact released-version configuration profiles. When a
// component using versioned profiles is assigned an image version, it must
// select one of these profiles instead of using the source-tree defaults.
Versioned map[string]ConfigProfile
}
ConfigInjection describes how a component configuration is assembled and delivered.
func (*ConfigInjection) ForVersion ¶
func (inj *ConfigInjection) ForVersion(version string) (*ConfigInjection, error)
ForVersion returns the configuration injection for version. A component that declares versioned profiles must select one for every explicitly requested version.
type ConfigProfile ¶
type ConfigProfile struct {
BaseConfigPath string
}
ConfigProfile replaces the base and shared configuration layers for a released image. Extra and block-specific overlays retain their usual precedence.
type CoverageService ¶
type CoverageService struct {
Name string
// OutputName optionally identifies the coverage output directory. Empty uses Name.
OutputName string
Types []string
}
CoverageService identifies a service that writes coverage artifacts.
type DBContract ¶
type DBContract struct {
// Supported lists the database engines supported by the component.
Supported []DBType
// Schema maps database engines to the ordered DDL files applied by the framework.
Schema map[DBType][]string
// SelfMigrates lists engines whose schema is applied by the component.
SelfMigrates []DBType
SharesStoreWith string
// Env maps a resolved DSN to component environment variables.
Env func(DSN) map[string]string
}
DBContract declares a component's database requirements.
func (*DBContract) Owns ¶
func (c *DBContract) Owns() bool
Owns reports whether this contract provisions its own store rather than borrowing another component's.
func (*DBContract) SchemaFor ¶
func (c *DBContract) SchemaFor(t DBType) ([]string, bool)
SchemaFor returns the DDL the framework must apply for t, and whether it must apply any at all. A component that migrates itself, or shares another's store, returns false — provisioning it anyway would double-apply the schema.
func (*DBContract) Supports ¶
func (c *DBContract) Supports(t DBType) bool
Supports reports whether t is an engine this component can run against.
type DBType ¶
type DBType string
DBType is a database engine a component can be backed by.
type DSN ¶
type DSN struct {
Type DBType
// Host and Port identify the database on the component network.
Host string
Port int
Database string
User string
Password string
SSLMode string
// FilePath is set only for embedded engines, where there is no host/port.
FilePath string
}
DSN contains the resolved coordinates of a logical runtime.
type Definition ¶
type Definition struct {
// Name is the identifier a suite file references. Unique within a registry.
Name string
// Image is what to run, for a single-container component.
Image ImageRef
// Compose backs this component with a multi-container stack instead of a single
// image, while still presenting it as ONE component to a suite file. Mutually
// exclusive with Image.
Compose *ComposeSpec
// External describes a component hosted outside the test process. It is mutually
// exclusive with Image and Compose.
External *ExternalSpec
// Alias is the component's DNS name on its network.
Alias string
// AliasIsFixed prevents the alias from being suffixed for replicas.
AliasIsFixed bool
// Endpoints are the component's addressable ports.
Endpoints []Endpoint
// Health is the application-level readiness gate. Nil disables this gate.
Health *HealthCheck
// VersionedHealth replaces Health for released image versions whose readiness
// contract differs from the source-build contract.
VersionedHealth map[string]HealthCheck
// Config describes configuration assembly, if the component has any.
Config *ConfigInjection
// DB is the storage contract, if the component has storage.
DB *DBContract
// Wiring decodes and validates component-specific block configuration.
Wiring WiringSpec
// ApplyWiring returns the definition a block's decoded wiring selects, for wiring that
// changes what the component runs. It must not modify def. Nil leaves the definition
// as registered.
ApplyWiring func(def *Definition, wiring any) (*Definition, error)
// Env is static environment applied to every instance, before DSN and wiring.
Env map[string]string
// Files are copied in before start.
Files []FileMount
// Cmd overrides the image's command.
Cmd []string
// Provisions returns environment values for dependent components after this component
// becomes ready.
Provisions func(ctx context.Context, inst *Instance, dependent string) (map[string]string, error)
// DependsOn lists components that must be ready before this one starts.
DependsOn []string
// Limits caps this container's host resources.
Limits ResourceLimits
Shared bool
// SourceProduct names the product whose source build supplies this component's image,
// for a component that runs another product's image under its own name. Empty means
// the product named Name.
SourceProduct string
}
Definition describes a component and its lifecycle contracts.
func (*Definition) Endpoint ¶
func (d *Definition) Endpoint(name string) (Endpoint, bool)
Endpoint returns the named endpoint.
func (*Definition) ExternalEndpointNames ¶
func (d *Definition) ExternalEndpointNames() []string
ExternalEndpointNames returns the names declared by an external component.
func (*Definition) IsCompose ¶
func (d *Definition) IsCompose() bool
IsCompose reports whether this component is backed by a compose stack rather than a single container.
func (*Definition) IsExternal ¶
func (d *Definition) IsExternal() bool
IsExternal reports whether the component is hosted outside the test process.
func (*Definition) Product ¶
func (d *Definition) Product() string
Product returns the product whose source build supplies this component's image.
func (*Definition) ResolveDBType ¶
func (d *Definition) ResolveDBType(explicit, blockDefault DBType) (DBType, error)
ResolveDBType selects a supported database engine.
func (*Definition) String ¶
func (d *Definition) String() string
String renders the definition for error messages.
func (*Definition) Validate ¶
func (d *Definition) Validate() error
Validate checks a definition's local invariants.
func (*Definition) WithConfigVersion ¶
func (d *Definition) WithConfigVersion(version string) (*Definition, error)
WithConfigVersion returns a copy configured for the supplied released image version.
func (*Definition) WithImageVersion ¶
func (d *Definition) WithImageVersion(version string) *Definition
WithImageVersion returns a copy whose image references use version.
func (*Definition) WithReleaseVersion ¶
func (d *Definition) WithReleaseVersion(version string) (*Definition, error)
WithReleaseVersion returns a copy whose image, configuration, and readiness contracts match the supplied released image version.
func (*Definition) WithStagedFiles ¶
func (d *Definition) WithStagedFiles(overrides map[string]string) (*Definition, error)
WithStagedFiles returns a copy with block-scoped sources for declared staged files.
type Endpoint ¶
type Endpoint struct {
// Name identifies the endpoint.
Name string
// Port is the in-container port.
Port int
// Scheme is "http", "https", "grpc", "tcp", …
Scheme string
// PathPrefix is prepended to paths built against this endpoint, for a component
// that serves its API under a fixed prefix.
PathPrefix string
// AwaitListening includes the port in container-level readiness checks.
AwaitListening bool
// Service names the Compose service that provides this endpoint. Empty uses the
// primary service.
Service string
}
Endpoint describes an addressable port on a component.
type ExternalEndpoint ¶
type ExternalEndpoint struct {
// Name identifies the endpoint.
Name string
}
ExternalEndpoint names an endpoint published by an external component. Its URL is resolved when the component is booted, rather than from container ports.
type ExternalSpec ¶
type ExternalSpec struct {
// Endpoints are the named addresses exposed by the component.
Endpoints []ExternalEndpoint
// RequiredParameters are runtime parameters that must be supplied before Resolve runs.
RequiredParameters []string
// Resolve constructs endpoint URLs from the repository root and runtime parameters.
Resolve func(repoRoot string, parameters map[string]string) (map[string]string, error)
}
ExternalSpec describes a component that is reachable outside the test process. External components have no image, container, network, or database lifecycle.
type FileMount ¶
type FileMount struct {
// HostPath is relative to the repository root. Exactly one of HostPath and Content is set.
HostPath string
// Content is the file's bytes, for a file the framework generates instead of reading.
Content []byte
// ContainerPath is the absolute destination.
ContainerPath string
// Mode is the file mode to set on the copy.
Mode int64
}
FileMount describes a file copied into a container before startup.
type HealthCheck ¶
type HealthCheck struct {
// Endpoint names the Endpoint to probe.
Endpoint string
// Service names the Compose service to probe. Empty uses the primary service.
Service string
// Path is appended to the endpoint's base URL.
Path string
// ExpectStatus is the status that means ready. Usually 200.
ExpectStatus int
// Timeout bounds the whole poll.
Timeout time.Duration
// Interval is the gap between probes.
Interval time.Duration
}
HealthCheck describes an application-level readiness probe.
type ImageBuild ¶
ImageBuild describes building an image from the repository.
type ImageRef ¶
type ImageRef struct {
// Ref is the default image, tag included.
Ref string
// ByArch overrides Ref for a GOARCH value ("arm64", "amd64").
ByArch map[string]string
// Build, when set, means the image is built from the repo rather than pulled.
// The path is relative to the repository root.
Build *ImageBuild
}
ImageRef identifies a container image and optional architecture-specific images.
func (ImageRef) WithVersion ¶
WithVersion returns a copy with the image tag replaced by version.
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance represents one running component instance.
func NewExternalInstance ¶
func NewExternalInstance(def *Definition, ordinal, replicas int, urls map[string]string) (*Instance, error)
NewExternalInstance creates an instance whose endpoints are complete external URLs.
func NewInstance ¶
func NewInstance(def *Definition, ordinal, replicas int, host string, mapped map[int]int) (*Instance, error)
NewInstance creates an instance from resolved runtime values.
func (*Instance) Definition ¶
func (i *Instance) Definition() *Definition
Definition returns the instance definition.
func (*Instance) EndpointNames ¶
EndpointNames returns all endpoint names addressable on this instance.
func (*Instance) InternalURL ¶
InternalURL returns the network URL for an endpoint.
func (*Instance) MappedPort ¶
MappedPort returns the mapped host port for an endpoint.
func (*Instance) RefreshPorts ¶
RefreshPorts replaces the instance's mapped host ports.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry stores component definitions by name.
func (*Registry) Lookup ¶
func (r *Registry) Lookup(name string) (*Definition, bool)
Lookup returns the named definition.
func (*Registry) MustRegister ¶
func (r *Registry) MustRegister(defs ...*Definition) *Registry
MustRegister registers definitions and panics on failure.
func (*Registry) Names ¶
Names returns every registered name, sorted, for error messages and --list.
func (*Registry) Register ¶
func (r *Registry) Register(d *Definition) error
Register validates and adds a definition.
type ResourceLimits ¶
ResourceLimits specifies per-container CPU and memory limits.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set stores component instances by name.
type WiringSpec ¶
type WiringSpec interface {
// Decode parses a wiring node into the component's wiring type.
Decode(node *yaml.Node) (any, error)
}
WiringSpec decodes component-specific block configuration.
func TypedWiring ¶
func TypedWiring[T any]() WiringSpec
TypedWiring creates a strict WiringSpec for type T.