v.io: v.io/x/ref/test/testutil Index | Files | Directories

package testutil

import "v.io/x/ref/test/testutil"

Package testutil implements utilities for unit and integration tests.

Index

Package Files

dispatcher.go doc.go glob.go no_race.go rand.go retryfor.go rpc.go security.go util.go vtest.go

Constants

const RaceEnabled = false
const (
    SeedEnv = "V23_RNG_SEED"
)

func CallAndRecover Uses

func CallAndRecover(f func()) (result interface{})

CallAndRecover calls the function f and returns the result of recover(). This minimizes the scope of the deferred recover, to ensure f is actually the function that paniced.

func FileTreeEqual Uses

func FileTreeEqual(aRoot, bRoot string, opts FileTreeOpts) (bool, error)

FileTreeEqual returns true if the filesystem trees rooted at aRoot and bRoot are the same. Use opts to control how matching is performed.

func FormatLogLine Uses

func FormatLogLine(depth int, format string, args ...interface{}) string

FormatLogLine will prepend the file and line number of the caller at the specificied depth (as per runtime.Caller) to the supplied format and args and return a formatted string. It is useful when implementing functions that factor out error handling and reporting in tests.

func GlobName Uses

func GlobName(ctx *context.T, name, pattern string) ([]string, []naming.GlobError, error)

GlobName calls __Glob on the given object with the given pattern and returns a sorted list of matching object names, or an error.

func InitRandGenerator Uses

func InitRandGenerator(logger loggingFunc)

InitRandGenerator creates an instance of Random in the public variable Rand and prints out the seed use when creating the number number generator using the supplied logging function.

func LeafDispatcher Uses

func LeafDispatcher(obj interface{}, auth security.Authorizer) rpc.Dispatcher

LeafDispatcher returns a dispatcher for a single object obj, using ReflectInvokerOrDie to invoke methods. Lookup only succeeds on the empty suffix. The provided auth is returned for successful lookups.

func NewPrincipal Uses

func NewPrincipal(blessingNames ...string) security.Principal

NewPrincipal creates a new security.Principal.

It is a convenience wrapper over utility functions available in the v.io/x/ref/lib/security package.

If the set of blessingNames provided is non-empty, it creates self-signed blessings for each of those names and marks all of them as the default and shareable with all peers on the principal's blessing store.

Errors are truly rare events and since this is a utility intended only for unittests, NewPrincipal will panic on any errors.

func RandomBytes Uses

func RandomBytes(size int) []byte

RandomBytes generates the given number of random bytes using the public variable Rand.

func RandomInt Uses

func RandomInt() int

RandomInt returns a non-negative pseudo-random int using the public variable Rand.

func RandomInt63 Uses

func RandomInt63() int64

RandomInt63 returns a non-negative 63-bit pseudo-random integer as an int64 using the public variable Rand.

func RandomIntn Uses

func RandomIntn(n int) int

RandomIntn returns a non-negative pseudo-random int in the range [0, n) using the public variable Rand.

func RetryFor Uses

func RetryFor(timeout time.Duration, fn func() error) error

RetryFor calls fn repeatedly, with a brief delay after each invocation, until either (1) fn returns something other than TryAgain or (2) the specified timeout is reached. RetryFor returns nil, TimeoutError, or the non-TryAgain error returned by fn.

func TryAgain Uses

func TryAgain(err error) error

TryAgain should be returned by the function provided to RetryFor to indicate that the function should be retried. If the function returns a non-TryAgain error, RetryFor will exit.

func WaitForProxyEndpoints Uses

func WaitForProxyEndpoints(s rpc.Server, proxyName string) rpc.ServerStatus

WaitForProxyEndpoints blocks until the server's proxied endpoints appear in status.Endpoints, and returns the resulting server status.

func WaitForServerPublished Uses

func WaitForServerPublished(s rpc.Server) rpc.ServerStatus

WaitForServerPublished blocks until all published mounts/unmounts have reached their desired state, and returns the resulting server status.

type FileTreeOpts Uses

type FileTreeOpts struct {
    // Debug is written to with additional information describing trees that are
    // not equal.
    Debug io.Writer

    // The pathname of regular files must match File{A,B} if they are provided,
    // otherwise the file is filtered out.  Similarly the pathname of directories
    // must match Dir{A,B} if they are provided.  {File,Dir}A matches pathnames
    // found under aRoot, while {File,Dir}B matches under bRoot.
    FileA, DirA *regexp.Regexp
    FileB, DirB *regexp.Regexp
}

FileTreeOpts contains options controlling how FileTreeEqual is performed.

type IDProvider Uses

type IDProvider struct {
    // contains filtered or unexported fields
}

IDProvider is a convenience type to act as an "identity provider", i.e., it provides other principals with a blessing whose root certificate is signed by the IDProvider.

Typical usage:

p1, p2 := NewPrincipal(), NewPrincipal()
idp := NewIDProvider("xyz")
idp.Bless(p1, "alpha")
idp.Bless(p2, "beta")

Now, p1 and p2 will present "xyz/alpha" and "xyz/beta" as their blessing names and when communicating with each other, p1 and p2 will recognize these names as they both trust the root certificate (that of the IDProvider)

func IDProviderFromPrincipal Uses

func IDProviderFromPrincipal(p security.Principal) *IDProvider

IDProviderFromPrincipal creates and IDProvider for the given principal. It will bless other principals with extensions of its default blessing.

func NewIDProvider Uses

func NewIDProvider(name string) *IDProvider

NewIDProvider creates an IDProvider that will bless other principals with extensions of 'name'.

NewIDProvider panics on any errors.

func (*IDProvider) Bless Uses

func (idp *IDProvider) Bless(who security.Principal, extension string, caveats ...security.Caveat) error

Bless sets up the provided principal to use blessings from idp as its default. It is shorthand for:

b, _ := idp.NewBlessings(who, extension, caveats...)
who.BlessingStore().SetDefault(b)
who.BlessingStore().Set(b, security.AllPrincipals)
security.AddToRoots(who, b)

func (*IDProvider) NewBlessings Uses

func (idp *IDProvider) NewBlessings(p security.Principal, extension string, caveats ...security.Caveat) (security.Blessings, error)

NewBlessings returns Blessings that extend the identity provider's blessing with 'extension' and binds it to 'p.PublicKey'.

Unlike Bless, it does not modify p's BlessingStore or set of recognized root certificates.

func (*IDProvider) PublicKey Uses

func (idp *IDProvider) PublicKey() security.PublicKey

PublicKey returns the public key of the identity provider.

type Random Uses

type Random struct {
    // contains filtered or unexported fields
}

Random is a concurrent-access friendly source of randomness.

var (
    Rand *Random
)

An instance of Random initialized by the InitRandomGenerator function.

func NewRandGenerator Uses

func NewRandGenerator(logger loggingFunc) *Random

NewRandGenerator creates a new pseudo-random number generator; the seed may be supplied by V23_RNG_SEED to allow for reproducing a previous sequence, and is printed using the supplied logging function.

func (*Random) RandomBytes Uses

func (r *Random) RandomBytes(size int) []byte

RandomBytes generates the given number of random bytes.

func (*Random) RandomInt Uses

func (r *Random) RandomInt() int

RandomInt returns a non-negative pseudo-random int.

func (*Random) RandomInt63 Uses

func (r *Random) RandomInt63() int64

RandomInt63 returns a non-negative 63-bit pseudo-random integer as an int64.

func (*Random) RandomIntn Uses

func (r *Random) RandomIntn(n int) int

RandomIntn returns a non-negative pseudo-random int in the range [0, n).

type TimeoutError Uses

type TimeoutError struct {
    // Timeout is the user-specified timeout.
    Timeout time.Duration
    // LastErr is the most recent TryAgain error returned by the user-provided
    // function.
    LastErr error
}

TimeoutError is returned by RetryFor when the specified timeout is reached.

func (*TimeoutError) Error Uses

func (e *TimeoutError) Error() string

Directories

PathSynopsis
testsshagent

Package testutil imports 20 packages (graph) and is imported by 15 packages. Updated 2020-10-24. Refresh now. Tools for package owners.