testenv

package
v0.0.0-...-70e5bc8 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

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

View Source
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.

func New

func New(setup *Setup) (*Env, error)

New creates a new Env for testing.

func (*Env) Exit

func (e *Env) Exit() error

Exit indicates the end of the test environment. It must only be called once. If Setup.Cleanup exists it is called.

func (*Env) NewUser

func (e *Env) NewUser(userName upspin.UserName) (upspin.Config, error)

NewUser creates a new client for a user. The new user will not have a root created. Callers should use the client to make a root directory if necessary.

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 NewRunner

func NewRunner() *Runner

func (*Runner) AddUser

func (r *Runner) AddUser(cfg upspin.Config)

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

func (r *Runner) As(u upspin.UserName)

As instructs the Runner to perform subsequent actions as the specified user. It must have been first added with AddUser.

func (*Runner) Config

func (r *Runner) Config() upspin.Config

Config returns the Config for the current user.

func (*Runner) Delete

func (r *Runner) Delete(p upspin.PathName)

Delete performs a Delete request as the user.

func (*Runner) Diag

func (r *Runner) Diag() string

Diag returns a string containing the most recent saved error and the file and line at which the error occurred.

func (*Runner) DirLookup

func (r *Runner) DirLookup(p upspin.PathName)

DirLookup performs a Lookup request to the user's underlying DirServer and populates the Runner's Entry field with the result.

func (*Runner) DirWatch

func (r *Runner) DirWatch(p upspin.PathName, seq int64) chan struct{}

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

func (r *Runner) DirWhichAccess(p upspin.PathName)

DirWhichAccess performs a WhichAccess request to the user's underlying DirServer and populates the Runner's Entry field with the result.

func (*Runner) Err

func (r *Runner) Err() error

Err returns the error state and clears it.

func (*Runner) Failed

func (r *Runner) Failed() bool

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

func (r *Runner) FlushCache() error

FlushCache flushes a user's Store cache.

func (*Runner) Get

func (r *Runner) Get(p upspin.PathName)

Get performs a Get request as the user and populates the Runner's Data field with the result.

func (*Runner) GetDeleteEvent

func (r *Runner) GetDeleteEvent(p upspin.PathName) bool

GetDeleteEvent gets one event from the user's Event channel and expects it to be a deletion of the file.

func (*Runner) GetErrorEvent

func (r *Runner) GetErrorEvent(want error) bool

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

func (r *Runner) GetNEvents(n int) bool

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

func (r *Runner) Glob(pattern string)

Glob performs a Glob request as the user and populates the Runner's Entries field with the result.

func (*Runner) GotEntries

func (r *Runner) GotEntries(wantBlockData bool, ps ...upspin.PathName) bool

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

func (r *Runner) GotEntry(p upspin.PathName) bool

GotEntry reports whether the Entry has the given name and if not notes the discrepancy as the last error state.

func (*Runner) GotEntryWithSequence

func (r *Runner) GotEntryWithSequence(p upspin.PathName, seq int64) bool

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

func (r *Runner) GotEntryWithSequenceVersion(p upspin.PathName, seq int64) bool

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

func (r *Runner) GotEvent(p upspin.PathName, withBlocks bool) bool

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

func (r *Runner) GotIncompleteEntry(p upspin.PathName) bool

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

func (r *Runner) GotNilEntry() bool

GotNilEntry reports whether the Entry is nil and if not notes this fact as the last error state.

func (*Runner) MakeDirectory

func (r *Runner) MakeDirectory(p upspin.PathName)

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

func (r *Runner) Match(want error) bool

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.

func (*Runner) Put

func (r *Runner) Put(p upspin.PathName, data string)

Put performs a Put request as the user and populates the Runner's Entry field with the result.

func (r *Runner) PutLink(oldName, linkName upspin.PathName)

PutLink performs a PutLink request as the user and populates the Runner's Entry field with the result.

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.

Jump to

Keyboard shortcuts

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