Documentation
¶
Overview ¶
Package storetest is the conformance suite of objectstore.ObjectStore: the contract of a store as executable cases. A store implementation passes when Run passes on it.
An implementation gives Run a Factory. The factory returns the store under test together with a Backend, the handle through which the suite arranges content and faults behind the store (puts a file, deletes it, makes the next reads fail, hangs them). A fault that a backend cannot arrange (a permission error on an emulator that has no permissions, say) is declared in Fixture.Unsupported with its reason: the cases that need it are then reported as unsupported for that backend, never skipped silently. Run returns a Report of what ran and what did not, and logs it.
Index ¶
- Constants
- Variables
- func AssertGet(t *testing.T, want *WantGet, obj objectstore.Object, err error)
- func CaseNames() []string
- func Check(name string, fixture Fixture) ([]string, bool)
- func CheckWaivers(waivers Waivers, fixture Fixture) []string
- func CheckWithin(name string, fixture Fixture, bound time.Duration) ([]string, bool)
- func ExpectedRan(unsupported map[string]string) []string
- func ListAll(t *testing.T, store objectstore.Lister, prefix string, limit int) []string
- type Answer
- type Backend
- type Capability
- type Factory
- type Fault
- type Fixture
- type Hang
- type Report
- type TB
- type Waivers
- type WantGet
Constants ¶
const ( // CaseContentAddressedETag is the name of the case that the ETag is a function of the bytes. CaseContentAddressedETag = "etag-is-content-addressed" // ReasonCloudETag is the reason the cloud stores give for waiving CapContentAddressedETag. ReasonCloudETag = "the ETag is a generation or a version of the blob: the same bytes give another one" )
The case and the reason of what the cloud stores (Google Cloud Storage, Azure Blob Storage) do not offer.
const ( // CaseVersionID is the case that reads an older version of an object. CaseVersionID = "version-id-reads-an-older-version" // CaseKeyRefusal is the case that a key that is not a clean relative path is refused. CaseKeyRefusal = "unclean-keys-are-refused" // CaseBodyCancel is the case that cancels a Get while it reads the body. CaseBodyCancel = "cancel-while-reading-the-body" )
The names of the cases that the backends of the stores waive for a reason of their own: a test of a backend names them in the cases it leaves out.
Variables ¶
var ErrUnsupported = errors.New("storetest: the backend cannot arrange this")
ErrUnsupported is what a backend returns for an operation it cannot arrange. A case that needs it is waived through its capability, so a suite run never reaches it.
Functions ¶
func Check ¶
Check runs the named case against fixture and returns what it reported as failed, and whether it ran (it does not when the name is not a case, or when the case needs a capability the fixture declares unsupported). It exists so that a test can show that the suite catches a broken store: the case runs on a goroutine of its own, with a recording TB.
func CheckWaivers ¶
CheckWaivers makes the check of the waivers that Run makes for every case, and returns what it reported as failed: nothing when the fixture declares exactly the waivers the test of the store states, each with a reason. Like Check it exists so that a test can show that the suite catches a store that drops a guarantee unannounced.
func CheckWithin ¶
CheckWithin is Check with a shorter bound for the events a case waits for. A store that is expected to fail by never answering (it ignores its context) then fails in about the bound and not in ten seconds. A store that is expected to pass needs the default bound: a short one can fail it on a busy machine.
func ExpectedRan ¶
ExpectedRan returns the names of the cases that a backend which waives the cases of unsupported (case name to the reason) has to run: every case but the waived ones. A test of a backend compares it with Report.Ran.
Types ¶
type Backend ¶
type Backend interface {
// Put creates or replaces the object atomically: a read sees the old content or the new one.
Put(key string, content []byte) error
// Overwrite replaces the content as an in-place rewrite that is as hard to notice as the backend allows: where
// the backend has a size, a modification time or an inode, they are the same as before when the new content
// has the same length. It is not atomic.
Overwrite(key string, content []byte) error
// Delete removes the object.
Delete(key string) error
// Fail makes the reads of key fail with fault until it is called again for the key (FaultNone clears it).
Fail(key string, fault Fault) error
// Hang makes the reads of key block until their context ends or the hang is released ([CapHang]).
Hang(key string) (*Hang, error)
// HangBody makes the reads of key answer, and then stall while the body is read, until their context ends or
// the hang is released ([CapHangBody]). The object has to be larger than the part that is let through.
HangBody(key string) (*Hang, error)
// PutVersion writes a new version of the object and returns its version id ([CapVersions]). An id returned
// earlier keeps naming the content it was written with.
PutVersion(key string, content []byte) (string, error)
}
Backend is what the suite uses to arrange the state behind the store. The methods return errors instead of failing a test, so that they can be called from goroutines.
type Capability ¶
type Capability string
Capability is something a backend may not be able to arrange, or a store may not offer. A case that needs a capability that the fixture declares unsupported is reported as unsupported, and Run only accepts the declaration when the caller waived the same capability with the same reason.
const ( // CapDeny is [FaultDenied]: a store whose reads are refused (403, a permission error, a link out of the root). CapDeny Capability = "deny" // CapTransient is [FaultTransient]: a read that fails with an error that may pass by itself. CapTransient Capability = "transient" // CapThrottle is [FaultThrottled]: a read the backend throttles (429, SlowDown). CapThrottle Capability = "throttle" // CapHang is [Backend.Hang]: a read that does not answer until its context ends. CapHang Capability = "hang" // CapHangBody is [Backend.HangBody]: a read whose answer started and whose body then stalls. CapHangBody Capability = "hang-body" // CapVersions is [Backend.PutVersion]: the object keeps versions and a read can name one. CapVersions Capability = "versions" // CapVersionCheck is that a read naming a version that does not exist fails with [objectstore.ErrNotFound]. An // emulator that has no versions ignores the version id and answers with the current object. CapVersionCheck Capability = "version-check" // CapKeyValidation is that the store refuses a key that is not a clean relative path, as a file store does. // The keys of an object store are opaque and it has nothing to refuse. CapKeyValidation Capability = "key-validation" // CapContentAddressedETag is that the ETag is a function of the bytes: the same bytes always give the same // ETag. A store whose ETag is a row version, a commit SHA or a generation number does not have it, and is // still correct: the reader needs only that the ETag describes the bytes returned, differs when they differ, // and is answered with "not modified" while the object is unchanged. CapContentAddressedETag Capability = "content-addressed-etag" // CapNestedKeys is that an object "a" and an object "a/b" can exist together, as in an object store. CapNestedKeys Capability = "nested-keys" // CapReservedNameChars is that keys can contain characters that some file systems reserve in names (a // question mark, a colon). Windows file names cannot. CapReservedNameChars Capability = "reserved-name-chars" )
The capabilities. A store that has all of them waives none.
type Factory ¶
Factory returns a fresh, empty fixture: no object of another case is visible. It is called once per case.
type Fault ¶
type Fault int
Fault is a failure a backend arranges for the reads of a key.
const ( FaultNone Fault = iota // FaultDenied makes the reads fail the way a refused access does: reason denied, not retryable. FaultDenied // FaultTransient makes the reads fail with an error that may pass: reason error, retryable. FaultTransient // FaultThrottled makes the reads fail with a throttling answer: reason error, retryable, throttled. FaultThrottled )
The faults. FaultNone clears the fault of a key.
type Fixture ¶
type Fixture struct {
// Store is the implementation under test.
Store objectstore.ObjectStore
// Backend arranges its state. Content put through it must be what Store reads.
Backend Backend
// Unsupported lists the capabilities the backend cannot arrange, with the reason.
Unsupported Waivers
}
Fixture is one store under test with its backend.
type Hang ¶
type Hang struct {
// contains filtered or unexported fields
}
Hang is a key whose reads do not answer until their context ends (or until Hang.Release). A backend makes one with NewHang and calls Hang.Block from the read of the key.
func (*Hang) Active ¶
Active is the number of reads that are hanging now. A read that returned is not counted any more.
func (*Hang) Block ¶
Block holds the calling read: it returns the error of ctx when the context ends first, and nil when the hang is released. A backend calls it before it answers the read (or, for Backend.HangBody, while the body is read).
func (*Hang) Entered ¶
func (h *Hang) Entered() <-chan struct{}
Entered gets one value for every read that started to hang.
func (*Hang) Left ¶
func (h *Hang) Left() <-chan struct{}
Left is a wake-up signal for the reads that stopped hanging, not a count: the buffer holds a bounded number of values, and a departure that finds it full is not signalled, and a value may be stale. Read Hang.Active after every value, and when waiting for no hanging read, check it again instead of waiting for one value per departure.
type Report ¶
type Report struct {
// Unsupported maps the name of a case to why it did not run.
Unsupported map[string]string
// Backend is the name given to [Run].
Backend string
// Ran is the sorted names of the cases that ran.
Ran []string
}
Report tells which cases ran for a backend and which are unsupported (with the reasons).
func Run ¶
Run runs every case against the stores the factory makes, as parallel subtests of t named after backend, and returns what ran and what was unsupported. The report is also logged.
waivers are what the store does not offer. Every case checks that the fixture declares exactly them: a store that starts waiving a capability fails until its test says so too.
Every case also checks that it left no goroutine behind (see the package documentation), and so does the run as a whole.
type TB ¶
TB is what the cases need of a test: the subset of testing.TB that testify uses, and the context. A testing.T pointer is one; Check gives the cases a recording one, so that a test can prove that a case fails.
type Waivers ¶
type Waivers map[Capability]string
Waivers are the capabilities a store does not offer, with the reason, as the test of the store states them. Run fails when the fixture declares anything else, so a store cannot drop a guarantee without the test saying so.
func CloudWaivers ¶
func CloudWaivers() Waivers
CloudWaivers is what the cloud stores do not offer: a content-addressed ETag.
func NewWaivers ¶
func NewWaivers() Waivers
NewWaivers returns no waivers: a store that offers everything. Add to them with Waivers.With.