Documentation
¶
Overview ¶
Package cachetest is the contract suite every cache store passes.
A Store is an interface with six methods, and the difference between two implementations of it is meant to be invisible from the call site: the same application, wired to the in-process ArrayStore in a test and to the RESP store in production, must behave the same way. Nothing about the Go type system enforces that. This package does.
It is here and not in the store's own repository because there is one contract, not one per backend: a suite copied into each adapter drifts, and the copy that drifts is the one that stops noticing that a miss returns the backend's own not-found error instead of cache.ErrNotFound.
An adapter runs it in one test:
func TestStoreContract(t *testing.T) {
cachetest.Run(t, func(t *testing.T) cache.Store {
return newStoreAgainstAServerStartedForThisTest(t)
})
}
The factory takes the *testing.T so an adapter can skip when its server is not available, and is called once per subtest so no subtest can be affected by what another one left behind.
It is named for net/http/httptest: a package whose name ends in "test" is a package that imports testing, and every consumer of this one is a test.
Package cachetest is the contract suite every Store passes.
It is what makes one behaviour test serve every backend: a Store built over memory, over the filesystem, over a table or over RESP is handed to the same suite, and a store that passes it can be dropped into a Repository without the Repository knowing which one it got.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.