Documentation
¶
Overview ¶
Package memstore is an in-memory backend.HeaderStore (and backend.Backend) for tests. It keeps the header, its ".prev" backup, and stored objects in maps instead of talking to rclone, so the safe-write protocol and any code that mutates the header can be tested without storage or network.
It is held to the same contract as the real backend by the shared conformance suite in internal/backend/backendtest, so a test that passes against this fake means the same thing it would against rclone.
Index ¶
- type Option
- type Store
- func (s *Store) BackupHeader(_ context.Context) error
- func (s *Store) CorruptNextPut(fn func([]byte) []byte)
- func (s *Store) Delete(_ context.Context, key string) error
- func (s *Store) FailPutAfter(n int, err error)
- func (s *Store) Get(_ context.Context, key string) ([]byte, error)
- func (s *Store) GetHeader(_ context.Context) ([]byte, error)
- func (s *Store) Header() []byte
- func (s *Store) List(_ context.Context, prefix string) ([]string, error)
- func (s *Store) Prev() []byte
- func (s *Store) Put(_ context.Context, key string, data []byte) error
- func (s *Store) PutHeader(_ context.Context, raw []byte) error
- func (s *Store) PutHeaderCount() int
- func (s *Store) RestoreHeaderBackup(_ context.Context) error
- func (s *Store) SetHeader(raw []byte)
- func (s *Store) SwapHeader(ctx context.Context, base, updated []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is an in-memory HeaderStore and Backend. The zero value is not usable; construct one with New. A Store is not safe for concurrent use; tests drive it from a single goroutine.
func (*Store) BackupHeader ¶
BackupHeader copies the header to ".prev". The safe-write protocol calls it only when a header exists, so a nil header here is a race, not the virgin case, and is an error (matching the real backends): the write fails closed rather than overwrite without a recoverable copy.
func (*Store) CorruptNextPut ¶
CorruptNextPut arms a one-shot transform applied to the bytes the next PutHeader stores, so a test can simulate a bad write (truncation, a flipped byte) and assert the safe-write protocol detects it on read-back.
func (*Store) FailPutAfter ¶
FailPutAfter makes the (n+1)th object Put return err once (simulating a crash mid-rotation); earlier and later Puts succeed.
func (*Store) PutHeader ¶
PutHeader stores the header. If a corruption hook is armed (CorruptNextPut), it is applied to the bytes actually stored and then disarmed, simulating a write that lands different bytes than intended so read-back verification has something to catch.
func (*Store) PutHeaderCount ¶
PutHeaderCount reports how many times PutHeader has been called.
func (*Store) RestoreHeaderBackup ¶
RestoreHeaderBackup copies ".prev" back over the header, or returns ErrNotFound when there is no backup.
func (*Store) SwapHeader ¶ added in v0.8.0
SwapHeader is a true compare-and-swap: the compare and the store happen in one step with nothing interleaving (the Store is single-goroutine by contract), so code tested against this fake sees the strongest semantics the interface allows. The store goes through PutHeader so corruption hooks and the put counter keep working.