Documentation
¶
Index ¶
- func TestInstanceCloneStartStopDelete(t cicd.TestingT, cfg InstanceTestConfig)
- func TestInstanceDeleteFromSuspended(t cicd.TestingT, cfg InstanceTestConfig)
- func TestInstanceExec(t cicd.TestingT, cfg InstanceTestConfig)
- func TestInstanceLifecycle(t cicd.TestingT, cfg InstanceTestConfig)
- func TestInstanceStateErrors(t cicd.TestingT, cfg InstanceTestConfig)
- func TestInstanceSuspendResume(t cicd.TestingT, cfg InstanceTestConfig)
- func TestPoolAcquireExecRelease(t cicd.TestingT, cfg PoolTestConfig)
- func TestPoolClose(t cicd.TestingT, cfg PoolTestConfig)
- func TestPoolConcurrentAcquire(t cicd.TestingT, cfg PoolTestConfig)
- func TestPoolContextCancellation(t cicd.TestingT, cfg PoolTestConfig)
- type ExecCall
- type InstanceTestConfig
- type Mock
- func (m *Mock) Clone(ctx context.Context) error
- func (m *Mock) Delete(_ context.Context) error
- func (m *Mock) Exec(_ context.Context, _, _ io.Writer, cmd string, args ...string) error
- func (m *Mock) ExecCalls() []ExecCall
- func (m *Mock) ID() string
- func (m *Mock) Properties(_ context.Context) (vms.Properties, error)
- func (m *Mock) SetProperties(props vms.Properties)
- func (m *Mock) SetState(state vms.State)
- func (m *Mock) SetSuspendable(suspendable bool)
- func (m *Mock) Start(ctx context.Context, _, _ io.Writer) error
- func (m *Mock) State(_ context.Context) vms.State
- func (m *Mock) Stop(_ context.Context, _ time.Duration) (error, error)
- func (m *Mock) Suspend(_ context.Context) error
- func (m *Mock) Suspendable() bool
- type MockFactory
- type PoolTestConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TestInstanceCloneStartStopDelete ¶
func TestInstanceCloneStartStopDelete(t cicd.TestingT, cfg InstanceTestConfig)
TestInstanceCloneStartStopDelete verifies the standard Clone -> Start -> Stop -> Delete state transitions.
func TestInstanceDeleteFromSuspended ¶
func TestInstanceDeleteFromSuspended(t cicd.TestingT, cfg InstanceTestConfig)
TestInstanceDeleteFromSuspended verifies that an instance can be deleted directly from the Suspended state.
func TestInstanceExec ¶
func TestInstanceExec(t cicd.TestingT, cfg InstanceTestConfig)
TestInstanceExec verifies that a command can be executed inside a running VM.
func TestInstanceLifecycle ¶
func TestInstanceLifecycle(t cicd.TestingT, cfg InstanceTestConfig)
TestInstanceLifecycle is a detailed lifecycle test that walks a VM through its state machine. Initial → Clone → Stopped → Start → Running → Stop → Stopped → Stop (idempotent) → Start → Running → [Suspend → Suspended → Suspend (idempotent) → Start → Running →] Stop → Stopped → Delete → Deleted
func TestInstanceStateErrors ¶
func TestInstanceStateErrors(t cicd.TestingT, cfg InstanceTestConfig)
func TestInstanceSuspendResume ¶
func TestInstanceSuspendResume(t cicd.TestingT, cfg InstanceTestConfig)
TestInstanceSuspendResume verifies the Suspend and Resume (Start) transitions for suspendable VMs.
func TestPoolAcquireExecRelease ¶
func TestPoolAcquireExecRelease(t cicd.TestingT, cfg PoolTestConfig)
TestPoolAcquireExecRelease verifies the full acquire → exec → release → replenish cycle: releasing a VM triggers replenishment so the pool can serve another Acquire.
func TestPoolClose ¶
func TestPoolClose(t cicd.TestingT, cfg PoolTestConfig)
TestPoolClose verifies that Close prevents further Acquire calls.
func TestPoolConcurrentAcquire ¶
func TestPoolConcurrentAcquire(t cicd.TestingT, cfg PoolTestConfig)
TestPoolConcurrentAcquire verifies that poolSize goroutines can each acquire a VM concurrently without error, and that the pool replenishes after all are released.
func TestPoolContextCancellation ¶
func TestPoolContextCancellation(t cicd.TestingT, cfg PoolTestConfig)
TestPoolContextCancellation verifies that Acquire returns context.Canceled when the pool is empty and the context is cancelled.
Types ¶
type InstanceTestConfig ¶
type InstanceTestConfig struct {
// Constructor creates a new uninitialized vms.Instance for each test.
Constructor vmspool.Constructor
// Timeout caps individual operations. Defaults to 30 s.
Timeout time.Duration
// ExecCmd is a command that should succeed inside a running VM. If empty,
// the Exec subtest is skipped.
ExecCmd string
ExecArgs []string
ExecStdout string // Expected output from the exec.
ExecStderr string // Expected stderr output from the exec.
// RequireUnderlyingState is an optional helper for tests that need to verify
// the underlying state of the instance, e.g. by querying a cloud provider API.
// The function is expected to wait for the instance to reach a stable state
RequireUnderlyingState func(
ctx context.Context, inst vms.Instance, msg string, final vms.State, intermediate ...vms.State) error
}
InstanceTestConfig configures the test suite for an implementation of vms.Instance.
type Mock ¶
type Mock struct {
// CloneBlock, if non-nil, causes Clone to block until the channel is
// closed or the context is cancelled. Used by tests to pause a VM
// mid-creation so the test can manipulate pool state before proceeding.
CloneBlock chan struct{}
CloneErr error
StartErr error
StopRunErr error
StopErr error
StopState *vms.State
SuspendErr error
DeleteErr error
ExecErr error
// contains filtered or unexported fields
}
Mock represents a mock virtual machine instance for testing.
func (*Mock) Properties ¶
func (*Mock) SetProperties ¶
func (m *Mock) SetProperties(props vms.Properties)
func (*Mock) SetSuspendable ¶
func (*Mock) Suspendable ¶
type MockFactory ¶
type MockFactory struct {
// contains filtered or unexported fields
}
MockFactory creates and tracks Mock instances for pool and integration tests. Use Inject to pre-supply configured mocks; otherwise MockFactory.New creates plain NewMock instances on demand.
func NewMockFactory ¶
func NewMockFactory(suspendable bool) *MockFactory
NewMockFactory returns an empty MockFactory.
func (*MockFactory) Inject ¶
func (f *MockFactory) Inject(m *Mock)
Inject queues m to be returned by the next New call instead of a freshly allocated Mock. Useful for injecting pre-configured error states.
func (*MockFactory) Mocks ¶
func (f *MockFactory) Mocks() []*Mock
Mocks returns a snapshot of all Mock instances produced so far.
func (*MockFactory) New ¶
func (f *MockFactory) New() vms.Instance
type PoolTestConfig ¶
type PoolTestConfig struct {
// Constructor creates new VM instances. Required.
Constructor vmspool.Constructor
// PoolSize is the default pool size used across all tests. Defaults to 2.
// Some subtests intentionally use a size-1 pool for deterministic behavior.
PoolSize int
// ExecCmd is a command that should succeed inside an acquired VM. If empty
// the Exec subtest is skipped.
ExecCmd string
ExecArgs []string
ExecStdoutOutput string // Expected output from the exec.
ExecStderrOutput string // Expected stderr output from the exec.
StdoutRWC func(string) io.Writer // Optional factory
StderrRWC func(string) io.Writer // Optional factory for stderr RWC used by Exec; defaults to bytes.Buffer-based implementation.
// Timeout caps individual pool operations. Defaults to 30 s.
Timeout time.Duration
// StagingBehaviour determines the pool's staging behaviour. Defaults to
// StagingBehaviourRunning.
StagingBehaviour vmspool.StagingBehaviour
}
PoolTestConfig configures the pool integration test suite run by RunPoolTests.