Documentation
¶
Overview ¶
Package apptest runs a product in its own tests as production runs it: on a data directory, where the framework seals what it keeps at rest, a transaction writes files and a rollback writes them back, a store's retention erases and folds what it overwrote, and a restart reads everything back — none of which a product kept in memory (app.InMemory) ever meets: the framework seals nothing in memory.
A suite keeps most of its tests in memory, fast and hermetic, and runs on disk those that are about what rests there:
func TestNothingPersonalRestsInClear(t *testing.T) {
disk := apptest.NewDisk(t)
app := start(t, disk) // the suite's own helper, in memory unless told otherwise
fileReport(t, app, "ann@example.com")
if files := disk.Holding(t, "ann@example.com"); len(files) > 0 {
t.Errorf("in clear on disk: %v", files)
}
}
A Disk is an AppOption: app.DataDir(disk.Dir), which wins over a app.InMemory given before it. Given to the product started again — once the first app stopped — it is the same data and the same secrets: a restart.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Disk ¶
type Disk struct {
// AppOption keeps an app's data in Dir.
app.AppOption
// Dir is the data directory, removed once the test and its subtests end.
Dir string
}
Disk is a data directory of a test's own, and the option that runs an app on it.
func NewDisk ¶
NewDisk returns a new data directory for t. The secrets the framework makes — its data-key and its index key, what the product generates — are kept beside the data, as production keeps them unless <PRODUCT>_SECRETS says otherwise, so an app started again on the same Disk opens what the first sealed.
It skips t where the platform keeps no data directory: the SDK's disk file system is Linux's, macOS's and the BSDs', and refuses Windows.
func (*Disk) Holding ¶
Holding returns the files of the data directory that hold one of words, byte for byte — slash-separated, relative to Dir, sorted —, the secrets the framework keeps there left out: what a test asserts is empty once the framework seals what the words were written into. An empty word matches nothing.