memstore

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Store)

Option configures a Store.

func Versioned

func Versioned() Option

Versioned marks the fake as keeping native object versions, mirroring a remote like B2. As on the real backend, BackupHeader and RestoreHeaderBackup then treat the ".prev" copy as redundant.

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 New

func New(opts ...Option) *Store

New returns an empty Store (no header, no blobs).

func (*Store) AfterNextList added in v0.3.0

func (s *Store) AfterNextList(fn func())

AfterNextList runs fn once, right after the next List captures its keys, so a test can inject an object the in-flight operation will not see.

func (*Store) BackupHeader

func (s *Store) BackupHeader(_ context.Context) error

BackupHeader copies the header to ".prev", a no-op when versioned or when no header exists, matching RcloneStorage.

func (*Store) BeforeNextPut added in v0.3.0

func (s *Store) BeforeNextPut(fn func())

BeforeNextPut runs fn once, right before the next Put stores, so a test can interleave a racing operation just ahead of a write.

func (*Store) CorruptNextBlobPut added in v0.3.0

func (s *Store) CorruptNextBlobPut(fn func([]byte) []byte)

CorruptNextBlobPut mangles the bytes the next Put stores, so a test can assert a compaction detects a botched snapshot write on read-back.

func (*Store) CorruptNextPut

func (s *Store) CorruptNextPut(fn func([]byte) []byte)

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) Delete added in v0.3.0

func (s *Store) Delete(_ context.Context, key string) error

func (*Store) FailDeleteAfter added in v0.3.0

func (s *Store) FailDeleteAfter(n int, err error)

FailDeleteAfter makes the (n+1)th Delete return err once (simulating a crash after a compaction's snapshot is written but before it finishes deleting).

func (*Store) FailPutAfter

func (s *Store) FailPutAfter(n int, err error)

FailPutAfter makes the (n+1)th object Put return err once (simulating a crash mid-rotation); earlier and later Puts succeed.

func (*Store) Get

func (s *Store) Get(_ context.Context, key string) ([]byte, error)

func (*Store) GetHeader

func (s *Store) GetHeader(_ context.Context) ([]byte, error)

func (*Store) Header

func (s *Store) Header() []byte

Header returns the currently stored header bytes (nil if none).

func (*Store) List

func (s *Store) List(_ context.Context, prefix string) ([]string, error)

func (*Store) Prev

func (s *Store) Prev() []byte

Prev returns the currently stored ".prev" backup bytes (nil if none).

func (*Store) Put

func (s *Store) Put(_ context.Context, key string, data []byte) error

func (*Store) PutHeader

func (s *Store) PutHeader(_ context.Context, raw []byte) error

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

func (s *Store) PutHeaderCount() int

PutHeaderCount reports how many times PutHeader has been called.

func (*Store) RestoreHeaderBackup

func (s *Store) RestoreHeaderBackup(_ context.Context) error

RestoreHeaderBackup copies ".prev" back over the header, or returns ErrNotFound when there is no backup (including when versioned).

func (*Store) SetHeader

func (s *Store) SetHeader(raw []byte)

SetHeader seeds the header directly, bypassing PutHeader, for test setup.

Jump to

Keyboard shortcuts

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