testutil

package
v0.0.0-...-0f4c570 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2018 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package testutil contains various utilities for testing Reflow functionality.

Index

Constants

This section is empty.

Variables

View Source
var PanicRepository reflow.Repository = &panicRepository{}

PanicRepository is an unimplemented repository. It panics on each call.

View Source
var Resources = reflow.Resources{"mem": 500 << 20, "cpu": 1, "disk": 10}

Resources is a convenient set of resources to use for testing.

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

func Exists(e *reflow.Eval, keys ...digest.Digest) bool

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 File

func File(contents string) reflow.File

File returns a file object representing the given contents.

func Files

func Files(files ...string) reflow.Fileset

Files returns a value comprising the given files with contents derived from their names.

func List

func List(values ...reflow.Fileset) reflow.Fileset

List constructs a list value.

func NewInmemoryAssoc

func NewInmemoryAssoc() assoc.Assoc

NewInmemoryAssoc returns a new assoc.Assoc that stores its mapping in memory.

func Value

func Value(e *reflow.Eval, key digest.Digest) reflow.Fileset

Value returns the fileset stored for the provided key in the cache configured in Eval e.

func WriteCache

func WriteCache(e *reflow.Eval, key digest.Digest, files ...string)

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) Delete

func (c *Cache) Delete(ctx context.Context, id digest.Digest) error

Delete removes the key id from the cache.

func (*Cache) Exists

func (c *Cache) Exists(f *reflow.Flow) bool

Exists tells whether a value has been stored for flow f.

func (*Cache) ExistsAll

func (c *Cache) ExistsAll(f *reflow.Flow) bool

ExistsAll tells whether a value has been stored for flow f, for all of its cache keys.

func (*Cache) Init

func (c *Cache) Init()

Init initializes (or re-initializes) a Cache.

func (*Cache) Lookup

func (c *Cache) Lookup(ctx context.Context, id digest.Digest) (reflow.Fileset, error)

Lookup returns the value stored at id, or else an errors.NotExist.

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.

func (*Cache) Transfer

func (c *Cache) Transfer(ctx context.Context, dst reflow.Repository, v reflow.Fileset) error

Transfer is not implemented in Cache.

func (*Cache) Value

func (c *Cache) Value(f *reflow.Flow) reflow.Fileset

Value returns the value stored for flow f.

func (*Cache) Write

func (c *Cache) Write(ctx context.Context, id digest.Digest, v reflow.Fileset, repo reflow.Repository) error

Write stores the value v at key id.

type EvalResult

type EvalResult struct {
	Val reflow.Fileset
	Err error
}

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) Error

func (e *Exec) Error(err error)

Error rendezvous the error err as the result of this testExec.

func (*Exec) ID

func (e *Exec) ID() digest.Digest

ID returns the exec's ID

func (*Exec) Inspect

func (e *Exec) Inspect(ctx context.Context) (reflow.ExecInspect, error)

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.

func (*Exec) Ok

func (e *Exec) Ok(res reflow.Result)

Ok rendezvous the value v as a successful result by this testExec.

func (*Exec) Promote

func (e *Exec) Promote(ctx context.Context) error

Promote is a no-op for the test exec.

func (*Exec) Result

func (e *Exec) Result(ctx context.Context) (reflow.Result, error)

Value rendezvous the result (value or error) of this exec.

func (*Exec) Shell

func (e *Exec) Shell(ctx context.Context) (io.ReadWriteCloser, error)

Shell is not implemented

func (*Exec) URI

func (e *Exec) URI() string

URI is not implemented

func (*Exec) Wait

func (e *Exec) Wait(ctx context.Context) error

Wait rendezvous this exec.

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) Equiv

func (e *Executor) Equiv(flows ...*reflow.Flow) bool

Equiv tells whether this executor contains precisely a set of flows.

func (*Executor) Error

func (e *Executor) Error(f *reflow.Flow, err error)

Error defines an erroneous result for the flow.

func (*Executor) Execs

func (e *Executor) Execs(ctx context.Context) ([]reflow.Exec, error)

Execs enumerates the execs managed by this executor.

func (*Executor) Get

func (e *Executor) Get(ctx context.Context, id digest.Digest) (reflow.Exec, error)

Get retrieves an exec.

func (*Executor) Init

func (e *Executor) Init()

Init initializes the test executor.

func (*Executor) Ok

func (e *Executor) Ok(f *reflow.Flow, res interface{})

Ok defines a successful result for a Flow.

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) Remove

func (e *Executor) Remove(ctx context.Context, id digest.Digest) error

Remove is not implemented.

func (*Executor) Repository

func (e *Executor) Repository() reflow.Repository

Repository returns this executor's repository.

func (*Executor) Resources

func (e *Executor) Resources() reflow.Resources

Resources returns this executor's total resources.

func (*Executor) Wait

func (e *Executor) Wait(f *reflow.Flow)

Wait blocks until a Flow is defined in the executor.

func (*Executor) WaitAny

func (e *Executor) WaitAny(flows ...*reflow.Flow) *reflow.Flow

WaitAny returns the first of flows to be defined.

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) Collect

Collect is not supported for the expect 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

Get implements the repository's Get call.

func (*ExpectRepository) Put

Put implements the repository's Put call.

func (*ExpectRepository) ReadFrom

func (r *ExpectRepository) ReadFrom(_ context.Context, id digest.Digest, u *url.URL) error

ReadFrom implements the repository's ReadFrom call.

func (*ExpectRepository) Stat

Stat always returns a NotExist error.

func (*ExpectRepository) URL

func (r *ExpectRepository) URL() *url.URL

URL returns the repository's URL.

func (*ExpectRepository) WriteTo

func (r *ExpectRepository) WriteTo(_ context.Context, id digest.Digest, u *url.URL) error

WriteTo implements the repository's WriteTo call.

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) Collect

func (r *InmemoryRepository) Collect(_ context.Context, live reflow.Liveset) error

Collect removes any object not in the liveset.

func (*InmemoryRepository) Delete

func (r *InmemoryRepository) Delete(_ context.Context, id digest.Digest)

Delete removes the key id from this repository.

func (*InmemoryRepository) Get

Get returns the blob named by id.

func (*InmemoryRepository) Put

Put installs the blob rd and returns its digest.

func (*InmemoryRepository) ReadFrom

func (r *InmemoryRepository) ReadFrom(_ context.Context, id digest.Digest, u *url.URL) error

ReadFrom is not supported.

func (*InmemoryRepository) Stat

Stat returns metadata for the blob named by id.

func (*InmemoryRepository) URL

func (r *InmemoryRepository) URL() *url.URL

URL returns a nil URL.

func (*InmemoryRepository) WriteTo

func (r *InmemoryRepository) WriteTo(_ context.Context, id digest.Digest, u *url.URL) error

WriteTo is not supported.

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) Delete

func (c *WaitCache) Delete(ctx context.Context, id digest.Digest) error

Delete is not implemented in WaitCache, and will panic.

func (*WaitCache) Hit

func (c *WaitCache) Hit(f *reflow.Flow, v reflow.Fileset)

Hit sets the value of flow f to v. Hit returns when the value has been consumed by the code under test.

func (*WaitCache) Init

func (c *WaitCache) Init()

Init (re-) initializes a WaitCache.

func (*WaitCache) Lookup

func (c *WaitCache) Lookup(ctx context.Context, id digest.Digest) (reflow.Fileset, error)

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

func (c *WaitCache) Miss(f *reflow.Flow)

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.

func (*WaitCache) Transfer

func (c *WaitCache) Transfer(ctx context.Context, dst reflow.Repository, v reflow.Fileset) error

Transfer always returns (immediate) success.

func (*WaitCache) Write

Write always returns (immediate) success.

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) Collect

Collect is not supported by WaitRepository.

func (*WaitRepository) Get

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) ReadFrom

func (w *WaitRepository) ReadFrom(_ context.Context, id digest.Digest, u *url.URL) error

ReadFrom is not supported by WaitRepository.

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.

func (*WaitRepository) WriteTo

func (w *WaitRepository) WriteTo(_ context.Context, id digest.Digest, u *url.URL) error

WriteTo is not supported by WaitRepository.

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) Init

func (t *WaitTransferer) Init()

Init initializes a WaitTransferer.

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.

Jump to

Keyboard shortcuts

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