Documentation ¶
Overview ¶
Package testutil contains various utilities for testing Reflow functionality.
Index ¶
- Variables
- func EvalAsync(ctx context.Context, e *reflow.Eval) <-chan EvalResult
- func Exists(e *reflow.Eval, keys ...digest.Digest) bool
- func File(contents string) reflow.File
- func Files(files ...string) reflow.Fileset
- func List(values ...reflow.Fileset) reflow.Fileset
- func NewInmemoryAssoc() assoc.Assoc
- func Value(e *reflow.Eval, key digest.Digest) reflow.Fileset
- func WriteCache(e *reflow.Eval, key digest.Digest, files ...string)
- func WriteFiles(r reflow.Repository, files ...string) reflow.Fileset
- type Cache
- func (c *Cache) Delete(ctx context.Context, id digest.Digest) error
- func (c *Cache) Exists(f *reflow.Flow) bool
- func (c *Cache) ExistsAll(f *reflow.Flow) bool
- func (c *Cache) Init()
- func (c *Cache) Lookup(ctx context.Context, id digest.Digest) (reflow.Fileset, error)
- func (c *Cache) NeedTransfer(ctx context.Context, dst reflow.Repository, v reflow.Fileset) ([]reflow.File, error)
- func (c *Cache) Repository() reflow.Repository
- func (c *Cache) Transfer(ctx context.Context, dst reflow.Repository, v reflow.Fileset) error
- func (c *Cache) Value(f *reflow.Flow) reflow.Fileset
- func (c *Cache) Write(ctx context.Context, id digest.Digest, v reflow.Fileset, ...) error
- type EvalResult
- type Exec
- func (e *Exec) Error(err error)
- func (e *Exec) ID() digest.Digest
- func (e *Exec) Inspect(ctx context.Context) (reflow.ExecInspect, error)
- func (e *Exec) Logs(ctx context.Context, stdout bool, stderr bool, follow bool) (io.ReadCloser, error)
- func (e *Exec) Ok(res reflow.Result)
- func (e *Exec) Promote(ctx context.Context) error
- func (e *Exec) Result(ctx context.Context) (reflow.Result, error)
- func (e *Exec) Shell(ctx context.Context) (io.ReadWriteCloser, error)
- func (e *Exec) URI() string
- func (e *Exec) Wait(ctx context.Context) error
- type ExecResult
- type Executor
- func (e *Executor) Equiv(flows ...*reflow.Flow) bool
- func (e *Executor) Error(f *reflow.Flow, err error)
- func (e *Executor) Execs(ctx context.Context) ([]reflow.Exec, error)
- func (e *Executor) Get(ctx context.Context, id digest.Digest) (reflow.Exec, error)
- func (e *Executor) Init()
- func (e *Executor) Ok(f *reflow.Flow, res interface{})
- func (e *Executor) Put(ctx context.Context, id digest.Digest, config reflow.ExecConfig) (reflow.Exec, error)
- func (e *Executor) Remove(ctx context.Context, id digest.Digest) error
- func (e *Executor) Repository() reflow.Repository
- func (e *Executor) Resources() reflow.Resources
- func (e *Executor) Wait(f *reflow.Flow)
- func (e *Executor) WaitAny(flows ...*reflow.Flow) *reflow.Flow
- type ExpectRepository
- func (*ExpectRepository) Collect(context.Context, reflow.Liveset) error
- func (r *ExpectRepository) Complete() error
- func (r *ExpectRepository) Expect(call RepositoryCall)
- func (r *ExpectRepository) Get(_ context.Context, id digest.Digest) (io.ReadCloser, error)
- func (r *ExpectRepository) Put(_ context.Context, body io.Reader) (digest.Digest, error)
- func (r *ExpectRepository) ReadFrom(_ context.Context, id digest.Digest, u *url.URL) error
- func (r *ExpectRepository) Stat(_ context.Context, id digest.Digest) (reflow.File, error)
- func (r *ExpectRepository) URL() *url.URL
- func (r *ExpectRepository) WriteTo(_ context.Context, id digest.Digest, u *url.URL) error
- type InmemoryRepository
- func (r *InmemoryRepository) Collect(_ context.Context, live reflow.Liveset) error
- func (r *InmemoryRepository) Delete(_ context.Context, id digest.Digest)
- func (r *InmemoryRepository) Get(_ context.Context, id digest.Digest) (io.ReadCloser, error)
- func (r *InmemoryRepository) Put(_ context.Context, rd io.Reader) (digest.Digest, error)
- func (r *InmemoryRepository) ReadFrom(_ context.Context, id digest.Digest, u *url.URL) error
- func (r *InmemoryRepository) Stat(_ context.Context, id digest.Digest) (reflow.File, error)
- func (r *InmemoryRepository) URL() *url.URL
- func (r *InmemoryRepository) WriteTo(_ context.Context, id digest.Digest, u *url.URL) error
- type RepositoryCall
- type RepositoryCallKind
- type WaitCache
- func (c *WaitCache) Delete(ctx context.Context, id digest.Digest) error
- func (c *WaitCache) Hit(f *reflow.Flow, v reflow.Fileset)
- func (c *WaitCache) Init()
- func (c *WaitCache) Lookup(ctx context.Context, id digest.Digest) (reflow.Fileset, error)
- func (c *WaitCache) Miss(f *reflow.Flow)
- func (c *WaitCache) NeedTransfer(ctx context.Context, dst reflow.Repository, v reflow.Fileset) ([]reflow.File, error)
- func (*WaitCache) Repository() reflow.Repository
- func (c *WaitCache) Transfer(ctx context.Context, dst reflow.Repository, v reflow.Fileset) error
- func (c *WaitCache) Write(ctx context.Context, id digest.Digest, v reflow.Fileset, ...) error
- type WaitRepository
- func (w *WaitRepository) Call(kind RepositoryCallKind, digest digest.Digest) chan RepositoryCall
- func (w *WaitRepository) Collect(context.Context, reflow.Liveset) error
- func (w *WaitRepository) Get(ctx context.Context, id digest.Digest) (io.ReadCloser, error)
- func (w *WaitRepository) Put(ctx context.Context, r io.Reader) (digest.Digest, error)
- func (w *WaitRepository) ReadFrom(_ context.Context, id digest.Digest, u *url.URL) error
- func (w *WaitRepository) Stat(ctx context.Context, id digest.Digest) (reflow.File, error)
- func (w *WaitRepository) URL() *url.URL
- func (w *WaitRepository) WriteTo(_ context.Context, id digest.Digest, u *url.URL) error
- type WaitTransferer
- func (t *WaitTransferer) Err(err error, dst, src reflow.Repository, files ...reflow.File)
- func (t *WaitTransferer) Init()
- func (t *WaitTransferer) NeedTransfer(ctx context.Context, dst reflow.Repository, files ...reflow.File) ([]reflow.File, error)
- func (t *WaitTransferer) Ok(dst, src reflow.Repository, files ...reflow.File)
- func (t *WaitTransferer) Transfer(ctx context.Context, dst, src reflow.Repository, files ...reflow.File) error
Constants ¶
This section is empty.
Variables ¶
var PanicRepository reflow.Repository = &panicRepository{}
PanicRepository is an unimplemented repository. It panics on each call.
var Resources = reflow.Resources{"mem": 500 << 20, "cpu": 1, "disk": 10}
Resources is a convenient set of resources to use for testing.
var Transferer reflow.Transferer = &transferer{}
Transferer is a simple transferer for testing; it does not apply any limits or other policies.
Functions ¶
func EvalAsync ¶
func EvalAsync(ctx context.Context, e *reflow.Eval) <-chan EvalResult
EvalAsync evaluates Flow f on Eval e asynchronously. It also ensures that any background tasks are completed before reporting completion. EvalAsync expects that e's toplevel flow returns a Fileset.
func Exists ¶
Exists tells whether a value has been cached for the provided keys. Exists checks whether all the objects are present in the Eval's repository.
func Files ¶
Files returns a value comprising the given files with contents derived from their names.
func NewInmemoryAssoc ¶
NewInmemoryAssoc returns a new assoc.Assoc that stores its mapping in memory.
func Value ¶
Value returns the fileset stored for the provided key in the cache configured in Eval e.
func WriteCache ¶
WriteCache writes the provided files into the eval's repository and registers a Fileset cache assoc.
func WriteFiles ¶
func WriteFiles(r reflow.Repository, files ...string) reflow.Fileset
WriteFiles writes the provided files into the repository r and returns a Fileset as in Files.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a Reflow cache that stores values (but not objects) in memory. It implements assoc.Assoc.
func (*Cache) ExistsAll ¶
ExistsAll tells whether a value has been stored for flow f, for all of its cache keys.
func (*Cache) NeedTransfer ¶
func (c *Cache) NeedTransfer(ctx context.Context, dst reflow.Repository, v reflow.Fileset) ([]reflow.File, error)
NeedTransfer returns the file objects in v that are missing from repository dst.
func (*Cache) Repository ¶
func (c *Cache) Repository() reflow.Repository
Repository is not implemented.
type EvalResult ¶
EvalResult stores the result of an asynchronous evaluation.
type Exec ¶
type Exec struct {
// contains filtered or unexported fields
}
Exec is the Exec type used by testExecutor. They permit the caller to rendezvous on results.
func (*Exec) Inspect ¶
Inspect rendezvous the result of this exec and returns the inspection output.
func (*Exec) Logs ¶
func (e *Exec) Logs(ctx context.Context, stdout bool, stderr bool, follow bool) (io.ReadCloser, error)
Logs is not implemented.
type ExecResult ¶
type ExecResult struct { Result reflow.Result Inspect reflow.ExecInspect }
ExecResult stores the result of a completed exec.
type Executor ¶
type Executor struct { Have reflow.Resources Repo reflow.Repository // contains filtered or unexported fields }
Executor implements Executor for testing purposes. It allows the caller to await creation of Execs, to introspect execs in the exeutor, and to set exec results.
func (*Executor) Put ¶
func (e *Executor) Put(ctx context.Context, id digest.Digest, config reflow.ExecConfig) (reflow.Exec, error)
Put defines a new exec (idempotently).
func (*Executor) Repository ¶
func (e *Executor) Repository() reflow.Repository
Repository returns this executor's repository.
type ExpectRepository ¶
type ExpectRepository struct { *testing.T // the testing instance to use RepoURL *url.URL // the repository URL // contains filtered or unexported fields }
ExpectRepository is a Repository implementation used for testing; it takes a script of expected calls and replies. Violations are reported to the testing.T instance.
func NewExpectRepository ¶
func NewExpectRepository(t *testing.T, rawurl string) *ExpectRepository
NewExpectRepository creates a new testing repository.
func (*ExpectRepository) Complete ¶
func (r *ExpectRepository) Complete() error
Complete should be called when testing is finished; it verifies that the entire script has been exhausted.
func (*ExpectRepository) Expect ¶
func (r *ExpectRepository) Expect(call RepositoryCall)
Expect adds a call to the repository's script.
func (*ExpectRepository) Get ¶
func (r *ExpectRepository) Get(_ context.Context, id digest.Digest) (io.ReadCloser, error)
Get implements the repository's Get call.
func (*ExpectRepository) URL ¶
func (r *ExpectRepository) URL() *url.URL
URL returns the repository's URL.
type InmemoryRepository ¶
type InmemoryRepository struct {
// contains filtered or unexported fields
}
InmemoryRepository is an in-memory repository used for testing.
func NewInmemoryRepository ¶
func NewInmemoryRepository() *InmemoryRepository
NewInmemoryRepository returns a new repository that stores objects in memory.
func (*InmemoryRepository) Delete ¶
func (r *InmemoryRepository) Delete(_ context.Context, id digest.Digest)
Delete removes the key id from this repository.
func (*InmemoryRepository) Get ¶
func (r *InmemoryRepository) Get(_ context.Context, id digest.Digest) (io.ReadCloser, error)
Get returns the blob named by id.
type RepositoryCall ¶
type RepositoryCall struct { Kind RepositoryCallKind ArgID digest.Digest ArgURL url.URL ArgBytes []byte ArgReadError error ReplyID digest.Digest ReplyFile reflow.File ReplyErr error ReplyReadCloser io.ReadCloser }
RepositoryCall describes a single call to a Repository: its expected arguments, and a reply. Repository calls are used with an ExpectRepository.
type RepositoryCallKind ¶
type RepositoryCallKind int
RepositoryCallKind indicates the type of repository call.
const ( RepositoryGet RepositoryCallKind = iota RepositoryPut RepositoryStat RepositoryWriteTo RepositoryReadFrom )
The concrete types of repository calls.
func (RepositoryCallKind) String ¶
func (i RepositoryCallKind) String() string
type WaitCache ¶
type WaitCache struct {
// contains filtered or unexported fields
}
WaitCache implements a reflow.Cache used for testing. WaitCaches rendezvous callers, acting as a concurrency control mechanism for tests.
func (*WaitCache) Hit ¶
Hit sets the value of flow f to v. Hit returns when the value has been consumed by the code under test.
func (*WaitCache) Lookup ¶
Lookup implements cache lookups. Lookup returns when the value for id has been set (through Hit or Miss) or when the context is done.
func (*WaitCache) Miss ¶
Miss sets the value of flow f to a cache miss. Miss returns when it has been consumed by the code under test.
func (*WaitCache) NeedTransfer ¶
func (c *WaitCache) NeedTransfer(ctx context.Context, dst reflow.Repository, v reflow.Fileset) ([]reflow.File, error)
NeedTransfer returns the file objects in v that are missing from repository dst.
func (*WaitCache) Repository ¶
func (*WaitCache) Repository() reflow.Repository
Repository is not implemented.
type WaitRepository ¶
type WaitRepository struct {
// contains filtered or unexported fields
}
WaitRepository is a repository implementation for testing that lets the caller rendeszvous calls so that concurrency can be controlled.
func NewWaitRepository ¶
func NewWaitRepository(rawurl string) *WaitRepository
NewWaitRepository creates a new WaitRespository with the provided URL. If the URL is invalid, NewWaitRepository will panic.
func (*WaitRepository) Call ¶
func (w *WaitRepository) Call(kind RepositoryCallKind, digest digest.Digest) chan RepositoryCall
Call rendeszvous with another caller. The returned channel is used to reply to the call.
func (*WaitRepository) Get ¶
func (w *WaitRepository) Get(ctx context.Context, id digest.Digest) (io.ReadCloser, error)
Get waits for another caller to rendeszvous and then returns the caller's reply.
func (*WaitRepository) Put ¶
Put reads the contents of r, waits for another caller to rendeszvous and then returns the caller's reply.
func (*WaitRepository) Stat ¶
Stat waits for another caller to rendeszvous and then returns the caller's reply.
func (*WaitRepository) URL ¶
func (w *WaitRepository) URL() *url.URL
URL returns the repository's URL.
type WaitTransferer ¶
type WaitTransferer struct {
// contains filtered or unexported fields
}
WaitTransferer is a transfer manager for testing. It lets the test code rendezvous with the caller. In this way, Transferer provides both a "mock" transfer manager implementation and also permits concurrency control for the tester.
func (*WaitTransferer) Err ¶
func (t *WaitTransferer) Err(err error, dst, src reflow.Repository, files ...reflow.File)
Err rendezvous the call named by the destination repository, source repository and fileset with failure.
func (*WaitTransferer) NeedTransfer ¶
func (t *WaitTransferer) NeedTransfer(ctx context.Context, dst reflow.Repository, files ...reflow.File) ([]reflow.File, error)
NeedTransfer returns all the missing objects in the destination repository. The test transferer assumes they are all missing.
func (*WaitTransferer) Ok ¶
func (t *WaitTransferer) Ok(dst, src reflow.Repository, files ...reflow.File)
Ok rendezvous the call named by the destination repository, source repository and fileset with succcess.
func (*WaitTransferer) Transfer ¶
func (t *WaitTransferer) Transfer(ctx context.Context, dst, src reflow.Repository, files ...reflow.File) error
Transfer waits for the tester to rendezvous, returning its result.