testutils

package
v0.0.0-...-3776344 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadTestBlueprint

func LoadTestBlueprint(t *testing.T, yamlContent string) *schema.Blueprint

LoadTestBlueprint loads a blueprint from a YAML string, failing the test on error.

func RequireEnv

func RequireEnv(t *testing.T, envVar string) string

RequireEnv skips the test if the given environment variable is not set or the endpoint it points to is not reachable. Returns the value if present and reachable.

Types

type ExecSQLCall

type ExecSQLCall struct {
	DatabaseName string
	SQL          string
}

ExecSQLCall records a single ExecSQL invocation.

type MockDeployEngine

type MockDeployEngine struct {
	CreateBlueprintValidationResult *manage.BlueprintValidation
	CreateBlueprintValidationErr    error

	GetBlueprintValidationResult *manage.BlueprintValidation
	GetBlueprintValidationErr    error

	// StreamBlueprintValidationEventsFn allows full control over the streaming behaviour.
	// If set, it is called directly; otherwise the default implementation
	// sends StubValidationEvents to the streamTo channel and then closes it.
	StreamBlueprintValidationEventsFn func(ctx context.Context, validationID string, streamTo chan<- types.BlueprintValidationEvent, errChan chan<- error) error
	StreamBlueprintValidationErr      error
	StubValidationEvents              []types.BlueprintValidationEvent

	CreateChangesetResult *manage.Changeset
	CreateChangesetErr    error

	GetChangesetResult *manage.Changeset
	GetChangesetErr    error

	StreamChangeStagingEventsFn func(ctx context.Context, changesetID string, streamTo chan<- types.ChangeStagingEvent, errChan chan<- error) error
	StreamChangeStagingErr      error

	CreateBlueprintInstanceResult *state.InstanceState
	CreateBlueprintInstanceErr    error

	UpdateBlueprintInstanceResult *state.InstanceState
	UpdateBlueprintInstanceErr    error

	GetBlueprintInstanceResult *state.InstanceState
	GetBlueprintInstanceErr    error

	GetBlueprintInstanceExportsResult map[string]*state.ExportState
	GetBlueprintInstanceExportsErr    error

	DestroyBlueprintInstanceResult *state.InstanceState
	DestroyBlueprintInstanceErr    error

	StreamBlueprintInstanceEventsFn func(ctx context.Context, instanceID string, streamTo chan<- types.BlueprintInstanceEvent, errChan chan<- error) error
	StreamBlueprintInstanceErr      error
}

MockDeployEngine is a test double for engine.DeployEngine. Set the fields to control return values and inject errors.

func (*MockDeployEngine) CleanupBlueprintValidations

func (m *MockDeployEngine) CleanupBlueprintValidations(_ context.Context) error

func (*MockDeployEngine) CleanupChangesets

func (m *MockDeployEngine) CleanupChangesets(_ context.Context) error

func (*MockDeployEngine) CleanupEvents

func (m *MockDeployEngine) CleanupEvents(_ context.Context) error

func (*MockDeployEngine) CreateBlueprintInstance

func (*MockDeployEngine) CreateChangeset

func (*MockDeployEngine) DestroyBlueprintInstance

func (*MockDeployEngine) GetBlueprintInstance

func (m *MockDeployEngine) GetBlueprintInstance(_ context.Context, _ string) (*state.InstanceState, error)

func (*MockDeployEngine) GetBlueprintInstanceExports

func (m *MockDeployEngine) GetBlueprintInstanceExports(_ context.Context, _ string) (map[string]*state.ExportState, error)

func (*MockDeployEngine) GetBlueprintValidation

func (m *MockDeployEngine) GetBlueprintValidation(_ context.Context, _ string) (*manage.BlueprintValidation, error)

func (*MockDeployEngine) GetChangeset

func (m *MockDeployEngine) GetChangeset(_ context.Context, _ string) (*manage.Changeset, error)

func (*MockDeployEngine) StreamBlueprintInstanceEvents

func (m *MockDeployEngine) StreamBlueprintInstanceEvents(
	ctx context.Context,
	instanceID string,
	streamTo chan<- types.BlueprintInstanceEvent,
	errChan chan<- error,
) error

func (*MockDeployEngine) StreamBlueprintValidationEvents

func (m *MockDeployEngine) StreamBlueprintValidationEvents(
	ctx context.Context,
	validationID string,
	streamTo chan<- types.BlueprintValidationEvent,
	errChan chan<- error,
) error

func (*MockDeployEngine) StreamChangeStagingEvents

func (m *MockDeployEngine) StreamChangeStagingEvents(
	ctx context.Context,
	changesetID string,
	streamTo chan<- types.ChangeStagingEvent,
	errChan chan<- error,
) error

func (*MockDeployEngine) UpdateBlueprintInstance

type MockDockerManager

type MockDockerManager struct {
	CheckAvailabilityFn func(ctx context.Context) error
	EnsureImageFn       func(ctx context.Context, image string, progress chan<- docker.ImagePullProgress) error
	CreateAndStartFn    func(ctx context.Context, config *docker.ContainerConfig) (string, error)
	StreamLogsFn        func(ctx context.Context, containerID string) (io.ReadCloser, error)
	StreamLogsOptsFn    func(ctx context.Context, containerID string, opts docker.LogStreamOptions) (io.ReadCloser, error)
	RestartContainerFn  func(ctx context.Context, containerID string) error
	StopFn              func(ctx context.Context, containerID string) error
	IsRunningFn         func(ctx context.Context, containerID string) (bool, error)
	CleanupStaleFn      func(ctx context.Context, containerName string) error

	// Call records for assertions.
	StopCalls         []string
	CleanupStaleCalls []string
}

MockDockerManager is a test double for docker.RuntimeContainerManager. Set the function fields to control behaviour; unset fields return nil/zero.

func (*MockDockerManager) CheckAvailability

func (m *MockDockerManager) CheckAvailability(ctx context.Context) error

func (*MockDockerManager) CleanupStale

func (m *MockDockerManager) CleanupStale(ctx context.Context, containerName string) error

func (*MockDockerManager) CreateAndStart

func (m *MockDockerManager) CreateAndStart(ctx context.Context, config *docker.ContainerConfig) (string, error)

func (*MockDockerManager) EnsureImage

func (m *MockDockerManager) EnsureImage(ctx context.Context, image string, progress chan<- docker.ImagePullProgress) error

func (*MockDockerManager) IsRunning

func (m *MockDockerManager) IsRunning(ctx context.Context, containerID string) (bool, error)

func (*MockDockerManager) RestartContainer

func (m *MockDockerManager) RestartContainer(ctx context.Context, containerID string) error

func (*MockDockerManager) Stop

func (m *MockDockerManager) Stop(ctx context.Context, containerID string) error

func (*MockDockerManager) StreamLogs

func (m *MockDockerManager) StreamLogs(ctx context.Context, containerID string) (io.ReadCloser, error)

func (*MockDockerManager) StreamLogsWithOptions

func (m *MockDockerManager) StreamLogsWithOptions(ctx context.Context, containerID string, opts docker.LogStreamOptions) (io.ReadCloser, error)

type MockNoSQLSeeder

type MockNoSQLSeeder struct {
	PutItemCalls []PutItemCall
	PutItemErr   error
}

MockNoSQLSeeder records all PutItem calls for assertion.

func (*MockNoSQLSeeder) PutItem

func (m *MockNoSQLSeeder) PutItem(_ context.Context, tableName string, itemJSON []byte) error

type MockSQLSeeder

type MockSQLSeeder struct {
	ExecSQLCalls []ExecSQLCall
	ExecSQLErr   error
}

MockSQLSeeder records all ExecSQL calls for assertion.

func (*MockSQLSeeder) ExecSQL

func (m *MockSQLSeeder) ExecSQL(_ context.Context, databaseName string, sql string) error

type MockStorageUploader

type MockStorageUploader struct {
	UploadCalls []UploadCall
	UploadErr   error
}

MockStorageUploader records all Upload calls for assertion.

func (*MockStorageUploader) Upload

func (m *MockStorageUploader) Upload(_ context.Context, bucketName string, objectKey string, data []byte) error

type PutItemCall

type PutItemCall struct {
	TableName string
	ItemJSON  []byte
}

PutItemCall records a single PutItem invocation.

type UploadCall

type UploadCall struct {
	BucketName string
	ObjectKey  string
	Data       []byte
}

UploadCall records a single Upload invocation.

Jump to

Keyboard shortcuts

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