Documentation
¶
Overview ¶
Package mock implements VolumeBackend entirely in memory. It reproduces all business constraints (duplicate names, invalid size, forbidden transitions) without any external dependencies.
Index ¶
- Variables
- type MockBackend
- func (m *MockBackend) AttachVolume(_ context.Context, name string, nodeID string) error
- func (m *MockBackend) BackendName() string
- func (m *MockBackend) Close(_ context.Context) error
- func (m *MockBackend) CreateVolume(_ context.Context, name string, sizeMB int) (*storage.Volume, error)
- func (m *MockBackend) DeleteVolume(_ context.Context, name string) error
- func (m *MockBackend) DetachVolume(_ context.Context, name string) error
- func (m *MockBackend) GetVolume(_ context.Context, name string) (*storage.Volume, error)
- func (m *MockBackend) HealthCheck(_ context.Context) error
- func (m *MockBackend) ListVolumes(_ context.Context) ([]*storage.Volume, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrVolumeNotFound = errors.New("volume not found") ErrVolumeExists = errors.New("volume already exists") ErrInvalidSize = errors.New("size must be > 0 MB") ErrInvalidTransition = errors.New("invalid state transition") )
Sentinel errors — callers may use errors.Is() to distinguish them.
Functions ¶
This section is empty.
Types ¶
type MockBackend ¶
type MockBackend struct {
// contains filtered or unexported fields
}
MockBackend is an in-memory VolumeBackend. sync.RWMutex: RLock for reads, Lock for writes.
func (*MockBackend) AttachVolume ¶
AttachVolume sets NodeID and marks the volume as attached. Returns ErrInvalidTransition when the volume is not in the available state.
func (*MockBackend) BackendName ¶
func (m *MockBackend) BackendName() string
func (*MockBackend) CreateVolume ¶
func (m *MockBackend) CreateVolume(_ context.Context, name string, sizeMB int) (*storage.Volume, error)
CreateVolume validates input and stores the volume in the available state.
func (*MockBackend) DeleteVolume ¶
func (m *MockBackend) DeleteVolume(_ context.Context, name string) error
DeleteVolume removes the volume. Returns ErrInvalidTransition when attached.
func (*MockBackend) DetachVolume ¶
func (m *MockBackend) DetachVolume(_ context.Context, name string) error
DetachVolume clears NodeID and marks the volume as available. Returns ErrInvalidTransition when the volume is not attached.
func (*MockBackend) HealthCheck ¶
func (m *MockBackend) HealthCheck(_ context.Context) error