Documentation
¶
Overview ¶
Package testenv provides a declarative environment for creating a complete Upspin test tree. See testenv_test.go for an example on how to use it.
Index ¶
- Constants
- type Env
- type Runner
- func (r *Runner) AddUser(cfg upspin.Config)
- func (r *Runner) As(u upspin.UserName)
- func (r *Runner) Config() upspin.Config
- func (r *Runner) Delete(p upspin.PathName)
- func (r *Runner) Diag() string
- func (r *Runner) DirLookup(p upspin.PathName)
- func (r *Runner) DirWatch(p upspin.PathName, seq int64) chan struct{}
- func (r *Runner) DirWhichAccess(p upspin.PathName)
- func (r *Runner) Err() error
- func (r *Runner) Failed() bool
- func (r *Runner) FlushCache() error
- func (r *Runner) Get(p upspin.PathName)
- func (r *Runner) GetDeleteEvent(p upspin.PathName) bool
- func (r *Runner) GetErrorEvent(want error) bool
- func (r *Runner) GetNEvents(n int) bool
- func (r *Runner) Glob(pattern string)
- func (r *Runner) GotEntries(wantBlockData bool, ps ...upspin.PathName) bool
- func (r *Runner) GotEntry(p upspin.PathName) bool
- func (r *Runner) GotEntryWithSequence(p upspin.PathName, seq int64) bool
- func (r *Runner) GotEntryWithSequenceVersion(p upspin.PathName, seq int64) bool
- func (r *Runner) GotEvent(p upspin.PathName, withBlocks bool) bool
- func (r *Runner) GotIncompleteEntry(p upspin.PathName) bool
- func (r *Runner) GotNilEntry() bool
- func (r *Runner) MakeDirectory(p upspin.PathName)
- func (r *Runner) Match(want error) bool
- func (r *Runner) Put(p upspin.PathName, data string)
- func (r *Runner) PutLink(oldName, linkName upspin.PathName)
- type Setup
Constants ¶
const ( TestKeyServer = "key.test.upspin.io:443" TestStoreServer = "store.test.upspin.io:443" TestDirServer = "dir.test.upspin.io:443" TestServerName = "dir-server@upspin.io" )
The servers that "remote" tests will work against.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Env ¶
type Env struct { // Client is the client tests should use for reaching the newly-created Tree. Client upspin.Client // Config is the configuration used when creating the client. Config upspin.Config // Setup contains the original setup options. Setup *Setup // contains filtered or unexported fields }
Env is the test environment. It contains a client which is the main piece that tests should use.
type Runner ¶
type Runner struct { // Entry holds the result of the most recent Put, DirLookup or // MakeDirectory operation. Entry *upspin.DirEntry // Entries holds the result of the most recent Glob operation. Entries []*upspin.DirEntry // Data holds the result of the most recent Get operation. Data string // Events holds the result of the most recent GetEvents operation. Events []upspin.Event // contains filtered or unexported fields }
Runner is a helper for writing tests that interact with Upspin trees. It can perform actions as multiple users in tandem. It reduces error handling boilerplate by tracking error state and skipping all actions between where an error occurs and where it is checked.
r := testenv.NewRunner() r.AddUser(config) r.As(username) r.Put("user@host/foo", "content") r.Get("user@host/foo") if r.Failed() { t.Fatal(r.Diag()) }
func (*Runner) AddUser ¶
AddUser adds the user in the given config to the Runner's internal state, and creates a client for use as that user. If a client already exists for that user, it is replaced with a new one.
func (*Runner) As ¶
As instructs the Runner to perform subsequent actions as the specified user. It must have been first added with AddUser.
func (*Runner) Diag ¶
Diag returns a string containing the most recent saved error and the file and line at which the error occurred.
func (*Runner) DirLookup ¶
DirLookup performs a Lookup request to the user's underlying DirServer and populates the Runner's Entry field with the result.
func (*Runner) DirWatch ¶
DirWatch performs a Watch request to the user's underlying DirServer and populates the Runner's Events channel with the DirServer's returned Event channel. It returns the done channel for this watcher, if successful.
func (*Runner) DirWhichAccess ¶
DirWhichAccess performs a WhichAccess request to the user's underlying DirServer and populates the Runner's Entry field with the result.
func (*Runner) Failed ¶
Failed reports whether the error state is non-nil, saves the error for use by the Diag method, and clears the error state.
func (*Runner) FlushCache ¶
FlushCache flushes a user's Store cache.
func (*Runner) Get ¶
Get performs a Get request as the user and populates the Runner's Data field with the result.
func (*Runner) GetDeleteEvent ¶
GetDeleteEvent gets one event from the user's Event channel and expects it to be a deletion of the file.
func (*Runner) GetErrorEvent ¶
GetErrorEvent gets one event from the user's Event channel and expects it to contain an error. If not, it records the discrepancy in the last error state.
func (*Runner) GetNEvents ¶
GetNEvents receives n events from the event channel of the calling user. If it cannot fulfill the request it sets the last error state.
func (*Runner) Glob ¶
Glob performs a Glob request as the user and populates the Runner's Entries field with the result.
func (*Runner) GotEntries ¶
GotEntries reports whether the names of the Entries match the provided list (in order). It also checks that the presence of block data in those entries matches the boolean, except it tolerates Access and Group files having blocks even if wantBlockData is false. If not, it notes the discrepancy as the last error state.
func (*Runner) GotEntry ¶
GotEntry reports whether the Entry has the given name and if not notes the discrepancy as the last error state.
func (*Runner) GotEntryWithSequence ¶
GotEntryWithSequence reports whether the Entry has the given name and sequence number and if not notes the discrepancy as the last error state.
func (*Runner) GotEntryWithSequenceVersion ¶
GotEntryWithSequenceVersion reports whether the Entry has the given name and sequence version number and if not notes the discrepancy as the last error state.
func (*Runner) GotEvent ¶
GotEvent reports whether some Event we received has the given name and presence of blocks. It notes any discrepancy as the last error state.
func (*Runner) GotIncompleteEntry ¶
GotIncompleteEntry reports whether the Entry has attribute Incomplete and does not have populated Blocks and Packdata fields. If not, it notes the discrepancy as the last error state.
func (*Runner) GotNilEntry ¶
GotNilEntry reports whether the Entry is nil and if not notes this fact as the last error state.
func (*Runner) MakeDirectory ¶
MakeDirectory creates a directory by issuing a Put request as the user and populates the Runner's Entry field with the result.
func (*Runner) Match ¶
Match checks whether the error state matches the given error and if not it notes the discrepancy as the last error state; otherwise it clears the error.
type Setup ¶
type Setup struct { // OwnerName is the name of the user that runs the tests. OwnerName upspin.UserName // Kind is what kind of servers to use, "inprocess", "server", or "remote". Kind string // UpBox specifies whether to use upbox to run dirserver, // storeserver, and keyserver processes separate to the test process. // If false, the test server instances are run inside the test process. UpBox bool // Cache specifies whether to run a cacheserver for the owner. // This option applies only when UpBox is true. Cache bool // Packing is the desired packing for the tree. Packing upspin.Packing // Verbose indicates whether we should print verbose debug messages. Verbose bool // Cleanup, if present, is run at Exit to clean up any test state necessary. // It may return an error, which is returned by Exit. Cleanup func(e *Env) error }
Setup is a configuration structure that contains a directory tree and other optional flags.