Documentation
¶
Index ¶
- Constants
- func BuildEnv(options StartOptions, envOptions EnvOptions) []string
- func CheckMockStatus(port int) error
- func DefaultDetachLogPath(port int) (string, error)
- func EnsureFileCacheDir() (string, error)
- func GetConfiguredVersion(engineType EngineType, override string, allowCached bool) string
- func GetConfiguredVersionOrResolve(engineType EngineType, override string, allowCached bool, resolveIfLatest bool) string
- func GetHighestVersion(engines []EngineMetadata) string
- func IsDockerEngine(engineType EngineType) bool
- func IsMockUp(port int) (success bool)
- func PopulateHealth(mock *ManagedMock)
- func RegisterEngine(engineType EngineType, ...)
- func RegisterLibrary(engineType EngineType, b func() EngineLibrary)
- func ResolveLatestToVersion(engineType EngineType, allowCached bool) (string, error)
- func SanitiseVersionOutput(s string) string
- func UsesEnvConfig(version string) bool
- func WaitForOp(desc string, timeoutDuration time.Duration, abortC chan bool, ...) (success bool, timedOut bool)
- func WaitForUrl(desc string, url string, abortC chan bool) (success bool, timedOut bool)
- func WaitUntilUp(port int, shutDownC chan bool) (success bool, timedOut bool)
- type DetachMode
- type EngineLibrary
- type EngineMetadata
- type EngineType
- func DeriveEngineTypeFromVersion(version string) EngineType
- func EnumerateLibraries() []EngineType
- func GetConfiguredType(override string) EngineType
- func GetConfiguredTypeWithDefault(override string, defaultType EngineType) EngineType
- func GetConfiguredTypeWithVersion(typeOverride string, versionOverride string) EngineType
- type EnvOptions
- type ManagedMock
- type MockEngine
- type MockHealth
- type Provider
- type PullPolicy
- type StartOptions
Constants ¶
const DefaultDebugPort = 8000
Variables ¶
This section is empty.
Functions ¶
func BuildEnv ¶
func BuildEnv(options StartOptions, envOptions EnvOptions) []string
func CheckMockStatus ¶
CheckMockStatus invokes the status endpoint on the specified port and checks it returns an HTTP 200 status.
func DefaultDetachLogPath ¶ added in v1.8.0
DefaultDetachLogPath returns the default log file path for a detached process-engine mock listening on the given port.
func EnsureFileCacheDir ¶
func GetConfiguredVersion ¶
func GetConfiguredVersion(engineType EngineType, override string, allowCached bool) string
func GetConfiguredVersionOrResolve ¶
func GetConfiguredVersionOrResolve(engineType EngineType, override string, allowCached bool, resolveIfLatest bool) string
func GetHighestVersion ¶
func GetHighestVersion(engines []EngineMetadata) string
func IsDockerEngine ¶ added in v1.8.0
func IsDockerEngine(engineType EngineType) bool
IsDockerEngine reports whether the engine type is one of the container-based docker variants.
func IsMockUp ¶
IsMockUp invokes the status endpoint on the specified port and returns a boolean indicating whether it is healthy.
func PopulateHealth ¶
func PopulateHealth(mock *ManagedMock)
func RegisterEngine ¶
func RegisterEngine(engineType EngineType, b func(configDir string, startOptions StartOptions) MockEngine)
func RegisterLibrary ¶
func RegisterLibrary(engineType EngineType, b func() EngineLibrary)
func ResolveLatestToVersion ¶
func ResolveLatestToVersion(engineType EngineType, allowCached bool) (string, error)
func SanitiseVersionOutput ¶
func UsesEnvConfig ¶ added in v1.7.0
UsesEnvConfig reports whether the given engine version expects its config directory and listen port via IMPOSTER_CONFIG_DIR and IMPOSTER_PORT env vars (5.x and later) rather than --configDir and --listenPort CLI flags (4.x and earlier). Unparseable versions (e.g. "dev") default to the env-var form.
func WaitForOp ¶
func WaitForOp(desc string, timeoutDuration time.Duration, abortC chan bool, operation func() bool) (success bool, timedOut bool)
WaitForOp polls operation until it succeeds, the timeout elapses, or an abort is received on abortC. On timeout it returns (false, true) rather than terminating the process, so the caller can stop any mock it started before exiting; an abort returns (false, false).
func WaitForUrl ¶
func WaitUntilUp ¶
WaitUntilUp blocks until the mock on the given port reports healthy. It returns success=true once healthy. If it returns success=false, timedOut distinguishes a healthcheck timeout (true) from an external abort via shutDownC, e.g. Ctrl+C (false), so callers can clean up a mock that never became healthy.
Types ¶
type DetachMode ¶ added in v1.8.0
type DetachMode int
DetachMode controls whether and how `up` backgrounds the mock.
const ( // DetachNone runs the mock in the foreground (default behaviour). DetachNone DetachMode = iota // DetachNow starts the mock and returns immediately without waiting // for it to become healthy. DetachNow // DetachHealthy starts the mock, waits for the healthcheck to pass, // then returns control to the caller. DetachHealthy )
type EngineLibrary ¶
type EngineLibrary interface {
CheckPrereqs() (bool, []string)
List() ([]EngineMetadata, error)
GetProvider(version string) Provider
// IsSealedDistro indicates whether a library represents a fixed distribution.
// Fixed distributions have a single version, so do not support version
// resolution or fetching engine binaries.
IsSealedDistro() bool
// ShouldEnsurePlugins indicates whether missing default plugins should be
// installed before starting the engine.
ShouldEnsurePlugins() bool
}
func GetLibrary ¶
func GetLibrary(engineType EngineType) EngineLibrary
type EngineMetadata ¶
type EngineMetadata struct {
EngineType EngineType
Version string
}
func (*EngineMetadata) Build ¶
func (e *EngineMetadata) Build(configDir string, startOptions StartOptions) MockEngine
type EngineType ¶
type EngineType string
const ( EngineTypeNone EngineType = "" EngineTypeAwsLambda EngineType = "awslambda" EngineTypeDockerCore EngineType = "docker" EngineTypeDockerAll EngineType = "docker-all" EngineTypeDockerDistroless EngineType = "docker-distroless" EngineTypeJvmSingleJar EngineType = "jvm" EngineTypeJvmUnpacked EngineType = "unpacked" EngineTypeNative EngineType = "native" )
func DeriveEngineTypeFromVersion ¶ added in v1.8.0
func DeriveEngineTypeFromVersion(version string) EngineType
DeriveEngineTypeFromVersion returns the engine type implied by an explicit engine version, or EngineTypeNone if no derivation can be made. Callers should fall back to their configured/default engine type when this returns EngineTypeNone.
Versions 5.x and later resolve to EngineTypeNative. Earlier versions, the "latest" alias, the empty string, and unparseable values all return EngineTypeNone so the default engine continues to apply. (Future: "latest" will be re-pointed at v5 and so will yield EngineTypeNative.)
func EnumerateLibraries ¶
func EnumerateLibraries() []EngineType
func GetConfiguredType ¶
func GetConfiguredType(override string) EngineType
func GetConfiguredTypeWithDefault ¶
func GetConfiguredTypeWithDefault(override string, defaultType EngineType) EngineType
func GetConfiguredTypeWithVersion ¶ added in v1.8.0
func GetConfiguredTypeWithVersion(typeOverride string, versionOverride string) EngineType
GetConfiguredTypeWithVersion is like GetConfiguredType but also takes an engine-version override so that a pinned version can imply an engine type when no explicit one is configured. CLI commands that expose a --version flag should pass its value as versionOverride.
type EnvOptions ¶
type ManagedMock ¶
type ManagedMock struct {
ID string
Name string
Port int
Health MockHealth
}
type MockEngine ¶
type MockEngine interface {
Start(wg *sync.WaitGroup) (success bool)
Stop(wg *sync.WaitGroup)
StopImmediately(wg *sync.WaitGroup)
Restart(wg *sync.WaitGroup)
ListAllManaged() ([]ManagedMock, error)
StopAllManaged() int
// StopManaged stops the single managed mock identified by id (the same
// value reported in ManagedMock.ID, i.e. the short container ID for
// docker or the PID for process engines). Returns (true, nil) if the
// mock was found and stopped; (false, nil) if no managed mock with
// that id exists in this engine; (false, err) if the engine could
// not be queried.
StopManaged(id string) (bool, error)
GetVersionString() (string, error)
// GetID returns an identifier for the running mock: the container ID
// for the docker engine, or the process PID for process engines.
// Returns an empty string if the mock has not been started.
GetID() string
}
func BuildEngine ¶
func BuildEngine(engineType EngineType, configDir string, startOptions StartOptions) MockEngine
BuildEngine is a convenience function that gets the library for the given engine type, obtains a provider for the version specified in the start options, then invokes the provider's builder function.
Note that the provider's Provide() function is not invoked explicitly, although it may be invoked implicitly from the builder function.
type MockHealth ¶
type MockHealth string
const ( MockHealthHealthy MockHealth = "healthy" MockHealthUnhealthy MockHealth = "unhealthy" MockHealthUnknown MockHealth = "unknown" )
type Provider ¶
type Provider interface {
Satisfied() bool
Provide(policy PullPolicy) error
GetEngineType() EngineType
Build(configDir string, startOptions StartOptions) MockEngine
// Bundle creates a single archive file containing the engine binary and
// configuration files. The archive is written to the specified destination.
// If the engine type is 'docker', destination should be a valid image name.
Bundle(configDir string, dest string) error
}
type PullPolicy ¶
type PullPolicy int
const ( PullSkip PullPolicy = iota PullAlways PullPolicy = iota PullIfNotPresent PullPolicy = iota )
type StartOptions ¶
type StartOptions struct {
Port int
Version string
PullPolicy PullPolicy
LogLevel string
ReplaceRunning bool
Deduplicate string
EnablePlugins bool
EnableFileCache bool
Environment []string
DirMounts []string
DebugMode bool
Detach DetachMode
// DetachLog is the resolved absolute path that a detached process
// engine writes stdout/stderr to. Unused by the docker engine.
DetachLog string
// DetachIdFile is the path the mock ID is written to (plaintext, no
// trailing newline) once a detached mock has started. Empty disables
// the behaviour.
DetachIdFile string
}
func (StartOptions) IsDetached ¶ added in v1.8.0
func (o StartOptions) IsDetached() bool
IsDetached reports whether the mock should be run in the background.