testutils

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateMinimalSandboxSpec added in v0.2.0

func CreateMinimalSandboxSpec(image string) *compute_v1alpha.SandboxSpec

CreateMinimalSandboxSpec creates a minimal sandbox spec for testing.

func CreateTestSandbox added in v0.2.0

CreateTestSandbox creates a sandbox entity for testing with minimal configuration.

func TestDebugLogger

func TestDebugLogger(t *testing.T) *slog.Logger

TestDebugLogger creates a test logger that outputs logs

func TestLogger

func TestLogger(t *testing.T) *slog.Logger

TestLogger creates a test logger that discards all output

Types

type EtcdEntityServer

type EtcdEntityServer struct {
	Store  *entity.EtcdStore
	Server *entityserver.EntityServer
	EAC    *entityserver_v1alpha.EntityAccessClient
	Client *apiserver.Client
	Prefix string
	// contains filtered or unexported fields
}

EtcdEntityServer provides an etcd-backed entity server for testing This enforces proper optimistic concurrency control unlike the in-memory version

func NewEtcdEntityServer

func NewEtcdEntityServer(t *testing.T) (*EtcdEntityServer, func())

NewEtcdEntityServer creates a new etcd-backed entity server for testing. It connects to etcd:2379 and uses a random prefix for isolation. Fails fast with a clear message if etcd is not reachable (i.e. outside dev env).

type InMemEntityServer

type InMemEntityServer struct {
	Store  *entity.MockStore
	Server *entityserver.EntityServer
	EAC    *entityserver_v1alpha.EntityAccessClient
	Client *apiserver.Client
}

InMemEntityServer provides an in-memory entity server for testing

func NewInMemEntityServer

func NewInMemEntityServer(t *testing.T) (*InMemEntityServer, func())

NewInMemEntityServer creates a new in-memory entity server for testing

func (*InMemEntityServer) AddEntity

func (s *InMemEntityServer) AddEntity(ent *entity.Entity)

AddEntity adds an entity to the mock store

func (*InMemEntityServer) GetEntity

func (s *InMemEntityServer) GetEntity(id entity.Id) *entity.Entity

GetEntity retrieves an entity from the mock store

type MockSandboxController added in v0.2.0

type MockSandboxController struct {
	Log *slog.Logger
	EAC *entityserver_v1alpha.EntityAccessClient

	// PollInterval controls how often the controller checks for pending sandboxes.
	// Defaults to 50ms if not set.
	PollInterval time.Duration

	// StartupDelay is the delay before transitioning a sandbox from PENDING to RUNNING.
	// Defaults to 0 (immediate transition).
	StartupDelay time.Duration

	// FailSandboxes is a set of sandbox IDs that should transition to DEAD instead of RUNNING.
	FailSandboxes map[entity.Id]bool

	// FailAll causes all sandboxes to transition to DEAD.
	FailAll bool

	// OnSandboxReady is called when a sandbox transitions to RUNNING.
	// Can be used for test synchronization.
	OnSandboxReady func(id entity.Id)

	// OnSandboxFailed is called when a sandbox transitions to DEAD.
	OnSandboxFailed func(id entity.Id)

	// AssignNetwork controls whether to assign a mock network address.
	// Defaults to true.
	AssignNetwork bool

	// NodeID is the mock node ID to assign to sandboxes.
	// Defaults to "node/mock-node".
	NodeID entity.Id
	// contains filtered or unexported fields
}

MockSandboxController simulates a sandbox controller for testing. It watches for PENDING sandboxes and transitions them to RUNNING (or DEAD if configured).

func NewMockSandboxController added in v0.2.0

func NewMockSandboxController(log *slog.Logger, eac *entityserver_v1alpha.EntityAccessClient) *MockSandboxController

NewMockSandboxController creates a new mock sandbox controller with default settings.

func (*MockSandboxController) MarkFailed added in v0.2.0

func (c *MockSandboxController) MarkFailed(id entity.Id)

MarkFailed adds a sandbox ID to the list of sandboxes that should fail.

func (*MockSandboxController) Reset added in v0.2.0

func (c *MockSandboxController) Reset()

Reset clears the processed sandbox tracking, allowing sandboxes to be processed again.

func (*MockSandboxController) Start added in v0.2.0

Start begins the mock sandbox controller in a background goroutine. Call Stop() to shut it down.

func (*MockSandboxController) Stop added in v0.2.0

func (c *MockSandboxController) Stop()

Stop shuts down the mock sandbox controller and waits for it to finish.

func (*MockSandboxController) WaitForSandbox added in v0.2.0

WaitForSandbox waits for a sandbox to reach a terminal state (RUNNING or DEAD). Returns the final status or an error if the context times out.

Jump to

Keyboard shortcuts

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