import "perkeep/pkg/test"
Overview ▹
Overview ▾
Package test provides common Perkeep test objects.
Index
- Variables
- func BrokenTest(t *testing.T)
- func DependencyErrorOrSkip(t *testing.T)
- func Diff(a, b []byte) string
- func MustRunCmd(t testing.TB, c *exec.Cmd) string
- func NewLogger(t *testing.T, prefix string, quietPhrases ...string) *log.Logger
- func RunCmd(c *exec.Cmd) (output string, err error)
- func TLog(t testing.TB) func()
- func WaitFor(condition func() bool, maxWait, checkInterval time.Duration) bool
- type Blob
- func RandomBlob(t *testing.T, size int64) *Blob
- func (tb *Blob) AssertMatches(t *testing.T, sb blob.SizedRef)
- func (tb *Blob) Blob() *blob.Blob
- func (tb *Blob) BlobRef() blob.Ref
- func (tb *Blob) BlobRefSlice() []blob.Ref
- func (tb *Blob) MustUpload(t *testing.T, ds blobserver.BlobReceiver)
- func (tb *Blob) Reader() io.Reader
- func (tb *Blob) Size() uint32
- func (tb *Blob) SizedRef() blob.SizedRef
- type Fetcher
- func (tf *Fetcher) AddBlob(b *Blob)
- func (tf *Fetcher) Fetch(ctx context.Context, ref blob.Ref) (file io.ReadCloser, size uint32, err error)
- func (tf *Fetcher) ReceiveBlob(ctx context.Context, br blob.Ref, source io.Reader) (blob.SizedRef, error)
- func (tf *Fetcher) SubFetch(ctx context.Context, ref blob.Ref, offset, length int64) (io.ReadCloser, error)
- type Loader
- func NewLoader() *Loader
- func (ld *Loader) AllHandlers() (map[string]string, map[string]interface{})
- func (ld *Loader) BaseURL() string
- func (ld *Loader) FindHandlerByType(handlerType string) (prefix string, handler interface{}, err error)
- func (ld *Loader) GetHandler(prefix string) (interface{}, error)
- func (ld *Loader) GetHandlerType(prefix string) string
- func (ld *Loader) GetStorage(prefix string) (blobserver.Storage, error)
- func (ld *Loader) MyPrefix() string
- func (ld *Loader) SetStorage(prefix string, s blobserver.Storage)
- type World
- func GetWorld(t *testing.T) *World
- func GetWorldMaybe(t *testing.T) *World
- func NewWorld() (*World, error)
- func WorldFromConfig(cfg string) (*World, error)
- func (w *World) Addr() string
- func (w *World) Build() error
- func (w *World) ClientIdentity() string
- func (w *World) Cmd(binary string, args ...string) *exec.Cmd
- func (w *World) CmdWithEnv(binary string, env []string, args ...string) *exec.Cmd
- func (w *World) Help() ([]byte, error)
- func (w *World) NewPermanode(t *testing.T) blob.Ref
- func (w *World) Ping() error
- func (w *World) PutFile(t *testing.T, name string) blob.Ref
- func (w *World) SearchHandlerPath() string
- func (w *World) SecretRingFile() string
- func (w *World) ServerBaseURL() string
- func (w *World) ServerBinary() string
- func (w *World) SourceRoot() string
- func (w *World) Start() error
- func (w *World) Stop()
Package files
blob.go diff.go doc.go fetcher.go loader.go test.go testdep.go wait.go world.go
Variables
var ClockOrigin = time.Unix(1322443956, 123456)
ClockOrigin is an arbitrary contemporary date that can be used as a starting time in tests. It is 2011-11-28 01:32:36.000123456 +0000 UTC.
func BrokenTest
func BrokenTest(t *testing.T)
BrokenTest marks the test as broken and calls t.Skip, unless the environment variable RUN_BROKEN_TESTS is set to 1 (or some other boolean true value).
func DependencyErrorOrSkip
func DependencyErrorOrSkip(t *testing.T)
DependencyErrorOrSkip is called when a test's dependency isn't found. It either skips the current test (if SKIP_DEP_TESTS is set), or calls t.Error with an error.
func Diff
func Diff(a, b []byte) string
Diff returns the unified diff (from running "diff -u") or returns an error string.
func MustRunCmd
func MustRunCmd(t testing.TB, c *exec.Cmd) string
MustRunCmd wraps RunCmd, failing t if RunCmd returns an error.
func NewLogger
func NewLogger(t *testing.T, prefix string, quietPhrases ...string) *log.Logger
NewLogger returns a logger that logs to t with the given prefix.
The optional quietPhrases are substrings to match in writes to determine whether those log messages are muted.
func RunCmd
func RunCmd(c *exec.Cmd) (output string, err error)
RunCmd runs c (which is assumed to be something short-lived, like a pk-put or pk-get command), capturing its stdout for return, and also capturing its stderr, just in the case of errors. If there's an error, the return error fully describes the command and all output.
func TLog
func TLog(t testing.TB) func()
TLog changes the log package's output to log to t and returns a function to reset it back to stderr.
func WaitFor
func WaitFor(condition func() bool, maxWait, checkInterval time.Duration) bool
WaitFor returns true if condition returns true before maxWait. It is checked immediately, and then every checkInterval.
type Blob
type Blob struct {
Contents string // the contents of the blob
}
Blob is a utility class for unit tests.
func RandomBlob
func RandomBlob(t *testing.T, size int64) *Blob
RandomBlob returns a random blob with the provided number of bytes.
func (*Blob) AssertMatches
func (tb *Blob) AssertMatches(t *testing.T, sb blob.SizedRef)
func (*Blob) Blob
func (tb *Blob) Blob() *blob.Blob
func (*Blob) BlobRef
func (tb *Blob) BlobRef() blob.Ref
func (*Blob) BlobRefSlice
func (tb *Blob) BlobRefSlice() []blob.Ref
func (*Blob) MustUpload
func (tb *Blob) MustUpload(t *testing.T, ds blobserver.BlobReceiver)
func (*Blob) Reader
func (tb *Blob) Reader() io.Reader
func (*Blob) Size
func (tb *Blob) Size() uint32
func (*Blob) SizedRef
func (tb *Blob) SizedRef() blob.SizedRef
type Fetcher
type Fetcher struct { memory.Storage // ReceiveErr optionally returns the error to return on receive. ReceiveErr error // FetchErr, if non-nil, specifies the error to return on the next fetch call. // If it returns nil, fetches proceed as normal. FetchErr func() error }
Fetcher is an in-memory implementation of the blobserver Storage interface. It started as just a fetcher and grew. It also includes other convenience methods for testing.
func (*Fetcher) AddBlob
func (tf *Fetcher) AddBlob(b *Blob)
func (*Fetcher) Fetch
func (tf *Fetcher) Fetch(ctx context.Context, ref blob.Ref) (file io.ReadCloser, size uint32, err error)
func (*Fetcher) ReceiveBlob
func (tf *Fetcher) ReceiveBlob(ctx context.Context, br blob.Ref, source io.Reader) (blob.SizedRef, error)
func (*Fetcher) SubFetch
func (tf *Fetcher) SubFetch(ctx context.Context, ref blob.Ref, offset, length int64) (io.ReadCloser, error)
type Loader
type Loader struct {
// contains filtered or unexported fields
}
func NewLoader
func NewLoader() *Loader
NewLoader
func (*Loader) AllHandlers
func (ld *Loader) AllHandlers() (map[string]string, map[string]interface{})
func (*Loader) BaseURL
func (ld *Loader) BaseURL() string
func (*Loader) FindHandlerByType
func (ld *Loader) FindHandlerByType(handlerType string) (prefix string, handler interface{}, err error)
func (*Loader) GetHandler
func (ld *Loader) GetHandler(prefix string) (interface{}, error)
func (*Loader) GetHandlerType
func (ld *Loader) GetHandlerType(prefix string) string
func (*Loader) GetStorage
func (ld *Loader) GetStorage(prefix string) (blobserver.Storage, error)
func (*Loader) MyPrefix
func (ld *Loader) MyPrefix() string
func (*Loader) SetStorage
func (ld *Loader) SetStorage(prefix string, s blobserver.Storage)
type World
type World struct {
// contains filtered or unexported fields
}
World defines an integration test world.
It's used to run the actual Perkeep binaries (perkeepd, pk-put, pk-get, pk, etc) together in large tests, including building them, finding them, and wiring them up in an isolated way.
func GetWorld
func GetWorld(t *testing.T) *World
GetWorld returns (creating if necessary) a test singleton world. It calls Fatal on the provided test if there are problems.
func GetWorldMaybe
func GetWorldMaybe(t *testing.T) *World
GetWorldMaybe returns the current World. It might be nil.
func NewWorld
func NewWorld() (*World, error)
NewWorld returns a new test world. It uses the GOPATH (explicit or implicit) to find the "perkeep.org" root.
func WorldFromConfig
func WorldFromConfig(cfg string) (*World, error)
WorldFromConfig returns a new test world based on the given configuration file. This cfg is the server config relative to pkg/test/testdata. It uses the GOPATH (explicit or implicit) to find the "perkeep.org" root.
func (*World) Addr
func (w *World) Addr() string
func (*World) Build
func (w *World) Build() error
Build builds the Perkeep binaries.
func (*World) ClientIdentity
func (w *World) ClientIdentity() string
ClientIdentity returns the GPG identity to use in World tests, suitable for setting in CAMLI_KEYID.
func (*World) Cmd
func (w *World) Cmd(binary string, args ...string) *exec.Cmd
func (*World) CmdWithEnv
func (w *World) CmdWithEnv(binary string, env []string, args ...string) *exec.Cmd
func (*World) Help
func (w *World) Help() ([]byte, error)
Help outputs the help of perkeepd from the World.
func (*World) NewPermanode
func (w *World) NewPermanode(t *testing.T) blob.Ref
func (*World) Ping
func (w *World) Ping() error
Ping returns an error if the world's perkeepd is not running.
func (*World) PutFile
func (w *World) PutFile(t *testing.T, name string) blob.Ref
func (*World) SearchHandlerPath
func (w *World) SearchHandlerPath() string
SearchHandlerPath returns the path to the search handler, with trailing slash.
func (*World) SecretRingFile
func (w *World) SecretRingFile() string
SecretRingFile returns the GnuPG secret ring, suitable for setting in CAMLI_SECRET_RING.
func (*World) ServerBaseURL
func (w *World) ServerBaseURL() string
func (*World) ServerBinary
func (w *World) ServerBinary() string
ServerBinary returns the location of the perkeepd binary running for this World.
func (*World) SourceRoot
func (w *World) SourceRoot() string
SourceRoot returns the root of the source tree.
func (*World) Start
func (w *World) Start() error
Start builds the Perkeep binaries and starts a server.
func (*World) Stop
func (w *World) Stop()
Subdirectories
Name | Synopsis | |
---|---|---|
.. | ||
dockertest | Package dockertest contains helper functions for setting up and tearing down docker containers to aid in testing. |