mock

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: MIT Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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 New

func New() *MockBackend

New creates a new in-memory backend.

func (*MockBackend) AttachVolume

func (m *MockBackend) AttachVolume(_ context.Context, name string, nodeID string) error

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) Close

func (m *MockBackend) Close(_ context.Context) error

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) GetVolume

func (m *MockBackend) GetVolume(_ context.Context, name string) (*storage.Volume, error)

func (*MockBackend) HealthCheck

func (m *MockBackend) HealthCheck(_ context.Context) error

func (*MockBackend) ListVolumes

func (m *MockBackend) ListVolumes(_ context.Context) ([]*storage.Volume, error)

Jump to

Keyboard shortcuts

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