admintest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package admintest holds an in-memory segmentadmin.Store with failure injection, for tests of the code that writes segments (the import and the commands of the CLI) that must not need a server.

Index

Constants

This section is empty.

Variables

View Source
var ErrCrossSlot = errors.New("CROSSSLOT keys in request don't hash to the same slot")

ErrCrossSlot is the failure of a swap whose keys are not in one cluster slot.

View Source
var ErrInjected = errors.New("injected failure")

ErrInjected is the failure that Fake.Fail returns.

View Source
var ErrLostReply = errors.New("the reply was lost")

ErrLostReply is the failure of a call that was applied and whose reply was lost.

View Source
var ErrReadFailed = errors.New("the connection broke")

ErrReadFailed is the failure that an Objects body gives after the bytes that Objects.BreakAfter allows.

Functions

This section is empty.

Types

type Fake

type Fake struct {
	// contains filtered or unexported fields
}

Fake is an in-memory store. It is safe for concurrent use. It records every call as "<OP> <key>" (never a member).

func New

func New() *Fake

New returns an empty store.

func (*Fake) AfterCall

func (f *Fake) AfterCall(op string, fn func())

AfterCall runs fn once the call of an operation ("SWAP", "EDIT") has been applied and answered, without the lock of the fake held: it may use the fake, or cancel a context.

func (*Fake) Calls

func (f *Fake) Calls() []string

Calls returns the calls so far, in order.

func (*Fake) Claim

func (f *Fake) Claim(ctx context.Context, lock, last, stale, tmp, token string) (bool, error)

Claim implements segmentadmin.Store: it removes the stale key and records the last one only for the lock holder.

func (*Fake) Close

func (*Fake) Close()

Close does nothing.

func (*Fake) Commit

Commit implements segmentadmin.Store: the conditional swap, in one step as the script does it.

func (*Fake) CountKeys

func (f *Fake) CountKeys(ctx context.Context, prefix string, limit int) (int, bool, error)

CountKeys implements segmentadmin.Store.

func (*Fake) Delete

func (f *Fake) Delete(keys ...string)

Delete removes keys without a command and without a record, as an expiry would.

func (*Fake) EditSet

func (f *Fake) EditSet(ctx context.Context, lock, key string, members []string, remove bool) (int64, bool, error)

EditSet implements segmentadmin.Store: refused while the import lock exists.

func (*Fake) Fail

func (f *Fake) Fail(op string, nth int)

Fail makes the nth next call of an operation ("SADD", "SWAP", "UNLINK", "SET" ...) fail with ErrInjected; n is 1 for the next call.

func (*Fake) FailFrom

func (f *Fake) FailFrom(op string, nth int)

FailFrom makes every call of an operation from the nth on fail with ErrInjected, as a store that stays down does.

func (*Fake) KeyTTL

func (f *Fake) KeyTTL(ctx context.Context, key string) (bool, time.Duration, error)

KeyTTL implements segmentadmin.Store.

func (*Fake) Keys

func (f *Fake) Keys() []string

Keys returns the sorted names of every key.

func (*Fake) Lock

func (f *Fake) Lock(ctx context.Context, key, token string, ttl time.Duration) (bool, error)

Lock implements segmentadmin.Store: idempotent by the token, as the script is.

func (*Fake) LoseReply

func (f *Fake) LoseReply(op string, nth int, always bool)

LoseReply makes the nth call of an operation ("SADD" of a batch, "SWAP", "EDIT") apply and then fail with ErrLostReply, as a call whose reply never came back. With always, every call from the nth on does.

func (*Fake) Members

func (f *Fake) Members(key string) []string

Members returns the sorted members of a set.

func (*Fake) Ping

func (f *Fake) Ping(ctx context.Context) error

Ping implements segmentadmin.Store.

func (*Fake) Put

func (f *Fake) Put(key, value string)

Put sets a string key without a command and without a record: another run that took a lock, say.

func (*Fake) SAdd

func (f *Fake) SAdd(ctx context.Context, key string, members []string, ttl time.Duration) (int64, error)

SAdd implements segmentadmin.Store.

func (*Fake) SCard

func (f *Fake) SCard(ctx context.Context, key string) (int64, error)

SCard implements segmentadmin.Store.

func (*Fake) SRem

func (f *Fake) SRem(ctx context.Context, key string, members []string) (int64, error)

SRem implements segmentadmin.Store.

func (*Fake) SetKeys

func (f *Fake) SetKeys(ctx context.Context, keys []string) (int64, error)

SetKeys implements segmentadmin.Store.

func (*Fake) SetValue

func (f *Fake) SetValue(ctx context.Context, key, value string) error

SetValue implements segmentadmin.Store.

func (*Fake) StageAdd

func (f *Fake) StageAdd(
	ctx context.Context, lock, tmp, token string, members []string, ttl time.Duration, first bool,
) (int64, segmentadmin.StageResult, error)

StageAdd implements segmentadmin.Store: the batch is written only while the lock holds the token, and only the first batch may create the temporary key.

func (*Fake) TTLOf

func (f *Fake) TTLOf(key string) time.Duration

TTLOf returns the expiry that was set on a key, zero for none.

func (f *Fake) Unlink(ctx context.Context, keys ...string) (int64, bool, error)

Unlink implements segmentadmin.Store.

func (*Fake) Unlock

func (f *Fake) Unlock(ctx context.Context, lock, last, committed, token string) error

Unlock implements segmentadmin.Store: the compare and delete.

func (*Fake) Value

func (f *Fake) Value(ctx context.Context, key string) (string, bool, error)

Value implements segmentadmin.Store.

func (f *Fake) WithoutUnlink()

WithoutUnlink makes UNLINK an unknown command, as on a server that predates it.

type Objects

type Objects struct {
	// contains filtered or unexported fields
}

Objects is an in-memory bucket that implements segmentadmin.ObjectAPI. It is safe for concurrent use. The ETag of an object is the hash of its bytes.

func NewObjects

func NewObjects(pageSize int) *Objects

NewObjects returns an empty bucket whose listing pages hold pageSize objects (3 when zero).

func (*Objects) BreakAfter

func (o *Objects) BreakAfter(key string, n int)

BreakAfter makes the GET of key fail with ErrReadFailed after n bytes of its body.

func (*Objects) Calls

func (o *Objects) Calls() []string

Calls returns the calls so far ("HEAD key", "LIST prefix", "GET key").

func (*Objects) FailHeads

func (o *Objects) FailHeads(n int)

FailHeads makes the next n HEAD and LIST calls fail with ErrReadFailed.

func (*Objects) Get

func (o *Objects) Get(ctx context.Context, key, etag string) (segmentadmin.Object, error)

Get implements segmentadmin.ObjectAPI.

func (*Objects) Head

func (o *Objects) Head(ctx context.Context, key string) (segmentadmin.ObjectInfo, error)

Head implements segmentadmin.ObjectAPI.

func (*Objects) List

func (o *Objects) List(ctx context.Context, prefix, token string) (segmentadmin.ObjectPage, error)

List implements segmentadmin.ObjectAPI. The token is the last key of the previous page.

func (*Objects) OnGet

func (o *Objects) OnGet(fn func(key string))

OnGet sets a function that runs at the start of every GET, before the object is read (a test replaces an object there).

func (*Objects) Put

func (o *Objects) Put(key string, data []byte, gzip bool)

Put stores an object. With gzip, the object is served with Content-Encoding gzip (the bytes are the caller's).

func (*Objects) Remove

func (o *Objects) Remove(key string)

Remove deletes an object.

func (*Objects) WithoutETag

func (o *Objects) WithoutETag(key string)

WithoutETag makes the store answer an object with an empty ETag, as some S3 compatible stores do.

Jump to

Keyboard shortcuts

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