testutil

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package testutil provides test utilities for staging package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HintedMockStore

type HintedMockStore struct {
	*MockStore

	UnstageEntryWithHintErr error
	UnstageTagWithHintErr   error
	UnstageAllWithHintErr   error
	LastHint                string // Records the last hint used
}

HintedMockStore extends MockStore with HintedUnstager support.

func NewHintedMockStore

func NewHintedMockStore() *HintedMockStore

NewHintedMockStore creates a new HintedMockStore with initialized maps.

func (*HintedMockStore) UnstageAllWithHint

func (m *HintedMockStore) UnstageAllWithHint(ctx context.Context, service staging.Service, hint string) error

UnstageAllWithHint removes all staged changes with an operation hint.

func (*HintedMockStore) UnstageEntryWithHint

func (m *HintedMockStore) UnstageEntryWithHint(ctx context.Context, service staging.Service, name string, hint string) error

UnstageEntryWithHint removes a staged entry with an operation hint.

func (*HintedMockStore) UnstageTagWithHint

func (m *HintedMockStore) UnstageTagWithHint(ctx context.Context, service staging.Service, name string, hint string) error

UnstageTagWithHint removes staged tag changes with an operation hint.

type MockStore

type MockStore struct {

	// Error injection for testing error paths
	GetEntryErr     error
	GetTagErr       error
	StageEntryErr   error
	StageTagErr     error
	UnstageTagErr   error
	UnstageEntryErr error
	UnstageAllErr   error
	ListEntriesErr  error
	ListTagsErr     error
	DrainErr        error
	WriteStateErr   error
	PingErr         error
	StartErr        error

	// DrainCallCount tracks the number of Drain calls
	DrainCallCount int
	// DrainErrOnCall specifies which call number (1-indexed) should return DrainErr
	// If 0, DrainErr applies to all calls. If >0, DrainErr only applies to that call number.
	DrainErrOnCall int
	// contains filtered or unexported fields
}

MockStore implements store.ReadWriteOperator for testing. It stores state in memory and can be configured to return errors.

func NewMockStore

func NewMockStore() *MockStore

NewMockStore creates a new MockStore with initialized maps.

func (*MockStore) AddEntry

func (m *MockStore) AddEntry(service staging.Service, name string, entry staging.Entry)

AddEntry is a helper to add entries directly for testing.

func (*MockStore) AddTag

func (m *MockStore) AddTag(service staging.Service, name string, tag staging.TagEntry)

AddTag is a helper to add tag entries directly for testing.

func (*MockStore) Drain

func (m *MockStore) Drain(_ context.Context, service staging.Service, keep bool) (*staging.State, error)

Drain retrieves the entire state from storage. If service is empty, returns all services; otherwise filters to the specified service. If keep is false, the source storage is cleared after reading.

func (*MockStore) GetEntry

func (m *MockStore) GetEntry(_ context.Context, service staging.Service, name string) (*staging.Entry, error)

GetEntry retrieves a staged entry.

func (*MockStore) GetTag

func (m *MockStore) GetTag(_ context.Context, service staging.Service, name string) (*staging.TagEntry, error)

GetTag retrieves staged tag changes.

func (*MockStore) ListEntries

func (m *MockStore) ListEntries(_ context.Context, service staging.Service) (map[staging.Service]map[string]staging.Entry, error)

ListEntries returns all staged entries for a service.

func (*MockStore) ListTags

func (m *MockStore) ListTags(_ context.Context, service staging.Service) (map[staging.Service]map[string]staging.TagEntry, error)

ListTags returns all staged tag changes for a service.

func (*MockStore) Ping added in v0.7.2

func (m *MockStore) Ping(_ context.Context) error

Ping checks if the agent daemon is running.

func (*MockStore) StageEntry

func (m *MockStore) StageEntry(_ context.Context, service staging.Service, name string, entry staging.Entry) error

StageEntry adds or updates a staged entry change.

func (*MockStore) StageTag

func (m *MockStore) StageTag(_ context.Context, service staging.Service, name string, tag staging.TagEntry) error

StageTag adds or updates staged tag changes.

func (*MockStore) Start added in v0.7.2

func (m *MockStore) Start(_ context.Context) error

Start ensures the agent daemon is running, starting it if necessary.

func (*MockStore) UnstageAll

func (m *MockStore) UnstageAll(_ context.Context, service staging.Service) error

UnstageAll removes all staged changes for a service.

func (*MockStore) UnstageEntry

func (m *MockStore) UnstageEntry(_ context.Context, service staging.Service, name string) error

UnstageEntry removes a staged entry change.

func (*MockStore) UnstageTag

func (m *MockStore) UnstageTag(_ context.Context, service staging.Service, name string) error

UnstageTag removes staged tag changes.

func (*MockStore) WriteState

func (m *MockStore) WriteState(_ context.Context, service staging.Service, state *staging.State) error

WriteState writes the entire state to storage. If service is empty, writes all services; otherwise writes only the specified service.

Jump to

Keyboard shortcuts

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