utiltest

package
v0.0.0-...-ba1c585 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2017 License: BSD-3-Clause Imports: 54 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RedirectEnv    = "DEVICE_MANAGER_DONT_REDIRECT_STDOUT_STDERR"
	TestEnvVarName = "V23_RANDOM_ENV_VALUE"
	NoPairingToken = ""
)
View Source
const MockApplicationRepoName = "ar"
View Source
const MockBinaryRepoName = "br"
View Source
const (
	TestFlagName = "random_test_flag"
)

Variables

View Source
var App = gosh.RegisterFunc("App", appFunc)

App is a test application. It pings the invoking device manager with state information.

View Source
var DeviceManager = gosh.RegisterFunc("DeviceManager", deviceManagerFunc)

DeviceManager sets up a device manager server. It accepts the name to publish the server under as an argument. Additional arguments can optionally specify device manager config settings.

View Source
var DeviceManagerV10 = gosh.RegisterFunc("DeviceManagerV10", func(publishName string, args ...string) error {
	versioning.CurrentVersion = versioning.Version{10, 0}
	return deviceManagerFunc(publishName, args...)
})

This is the same as DeviceManager above, except that it has a different major version number.

View Source
var ErrOperationFailed = verror.Register(pkgPath+".OperationFailed", verror.NoRetry, "")
View Source
var ExecScript = gosh.RegisterFunc("ExecScript", func(script string) error {
	osenv := []string{RedirectEnv + "=1"}
	if os.Getenv("PAUSE_BEFORE_STOP") == "1" {
		osenv = append(osenv, "PAUSE_BEFORE_STOP=1")
	}
	cmd := goexec.Cmd{
		Path:   script,
		Env:    osenv,
		Stdin:  os.Stdin,
		Stderr: os.Stderr,
		Stdout: os.Stdout,
	}
	return cmd.Run()
})

ExecScript launches the script passed as argument.

View Source
var HangingApp = gosh.RegisterFunc("HangingApp", func(publishName string) error {
	err := appFunc(publishName)
	time.Sleep(24 * time.Hour)
	return err
})

HangingApp is the same as App, except that it does not exit properly after being stopped.

Functions

func AppStub

func AppStub(nameComponents ...string) device.ApplicationClientMethods

func Cat

func Cat(ctx *context.T, name, file string) (string, error)

Cat is an RPC invoked from the test harness process to the application process.

func ClaimDevice

func ClaimDevice(t *testing.T, ctx *context.T, claimableName, deviceName, extension, pairingToken string)

func ClaimDeviceExpectError

func ClaimDeviceExpectError(t *testing.T, ctx *context.T, name, extension, pairingToken string, errID verror.ID)

func CompareAssociations

func CompareAssociations(t *testing.T, got, expected []device.Association)

func CreatePrincipal

func CreatePrincipal(t *testing.T, sh *v23test.Shell) string

CreatePrincipal sets up a principal in a temporary directory (to be cleaned up by the shell at the end) and returns that directory.

func CtxWithNewPrincipal

func CtxWithNewPrincipal(t *testing.T, ctx *context.T, idp *testutil.IDProvider, extension string) *context.T

func Debug

func Debug(t *testing.T, ctx *context.T, nameComponents ...string) string

func DeleteApp

func DeleteApp(t *testing.T, ctx *context.T, appID, instanceID string)

func DeviceManagerCmd

func DeviceManagerCmd(sh *v23test.Shell, f *gosh.Func, args ...interface{}) *v23test.Cmd

func DeviceStub

func DeviceStub(name string) device.DeviceClientMethods

func EnvelopeFromShell

func EnvelopeFromShell(sh *v23test.Shell, vars, flags []string, f *gosh.Func, title string, retries int, window time.Duration, args ...interface{}) application.Envelope

func GenerateRestarter

func GenerateRestarter(t *testing.T, root string) string

GenerateRestarter creates a simple script that acts as the restarter for tests. It blackholes arguments meant for the restarter.

func GenerateSuidHelperScript

func GenerateSuidHelperScript(t *testing.T, root string) string

GenerateSuidHelperScript builds a script to execute the test target as a suidhelper instance and returns the path to the script.

func GetPid

func GetPid(t *testing.T, ctx *context.T, appID, instanceID string) int

func InstallApp

func InstallApp(t *testing.T, ctx *context.T, opt ...interface{}) string

func InstallAppExpectError

func InstallAppExpectError(t *testing.T, ctx *context.T, expectedError verror.ID, opt ...interface{})

func KillApp

func KillApp(t *testing.T, ctx *context.T, appID, instanceID string)

func KillDevice

func KillDevice(t *testing.T, ctx *context.T, name string)

func LaunchApp

func LaunchApp(t *testing.T, ctx *context.T, appID string) string

func LaunchAppExpectError

func LaunchAppExpectError(t *testing.T, ctx *context.T, appID string, expectedError verror.ID)

func LaunchAppImpl

func LaunchAppImpl(t *testing.T, ctx *context.T, appID, grant string) (string, error)

func NewGlobTestRegexHelper

func NewGlobTestRegexHelper(appName string) *globTestRegexHelper

func NewInstanceImpl

func NewInstanceImpl(t *testing.T, ctx *context.T, appID, grant string) (string, error)

func Ocfg

func Ocfg(opt []interface{}) device.Config

func Opkg

func Opkg(opt []interface{}) application.Packages

func PollingWait

func PollingWait(t *testing.T, pid int)

PollingWait polls a given process to make sure that it has exited before continuing or fails with a time-out.

func Resolve

func Resolve(f Fatalist, ctx *context.T, name string, expectReplicas int, retry bool) []string

Resolve looks up the given name in the mounttable.

func ResolveExpectNotFound

func ResolveExpectNotFound(f Fatalist, ctx *context.T, name string, retry bool)

ResolveExpectNotFound verifies that the given name is not in the mounttable.

func RevertApp

func RevertApp(t *testing.T, ctx *context.T, appID string)

func RevertAppExpectError

func RevertAppExpectError(t *testing.T, ctx *context.T, appID string, expectedError verror.ID)

func RevertDevice

func RevertDevice(t *testing.T, ctx *context.T, name string)

func RevertDeviceExpectError

func RevertDeviceExpectError(t *testing.T, ctx *context.T, name string, errID verror.ID)

func RunApp

func RunApp(t *testing.T, ctx *context.T, appID, instanceID string)

func RunAppExpectError

func RunAppExpectError(t *testing.T, ctx *context.T, appID, instanceID string, expectedError verror.ID)

func SetNamespaceRootsForUnclaimedDevice

func SetNamespaceRootsForUnclaimedDevice(ctx *context.T) (*context.T, error)

func ShutdownDevice

func ShutdownDevice(t *testing.T, ctx *context.T, name string)

func SignedEnvelopeFromShell

func SignedEnvelopeFromShell(ctx *context.T, sh *v23test.Shell, vars, flags []string, f *gosh.Func, title string, retries int, window time.Duration, args ...interface{}) (application.Envelope, error)

func StartApplicationRepository

func StartApplicationRepository(ctx *context.T) (*application.Envelope, func())

StartApplicationRepository sets up a server running the application repository. It returns a pointer to the envelope that the repository returns to clients (so that it can be changed). It also returns a cleanup function.

func StartBinaryRepository

func StartBinaryRepository(ctx *context.T) func()

StartBinaryRepository sets up a server running the binary repository and returns a cleanup function.

func StartMockRepos

func StartMockRepos(t *testing.T, ctx *context.T) (*application.Envelope, func())

func StartRealBinaryRepository

func StartRealBinaryRepository(t *testing.T, ctx *context.T, von string) func()

func StartupHelper

func StartupHelper(t *testing.T) (func(), *context.T, *v23test.Shell, *application.Envelope, string, string, *testutil.IDProvider)

TODO(rjkroege): This helper is generally useful. Use it to reduce boilerplate across all device manager tests.

func StatsStub

func StatsStub(nameComponents ...string) stats.StatsClientMethods

func Status

func Status(t *testing.T, ctx *context.T, nameComponents ...string) device.Status

func TerminateApp

func TerminateApp(t *testing.T, ctx *context.T, appID, instanceID string)

func TestMainImpl

func TestMainImpl(m *testing.M)

func TestSuidHelperImpl

func TestSuidHelperImpl(t *testing.T)

TestSuidHelper is testing boilerplate for suidhelper that does not create a runtime because the suidhelper is not a Vanadium application.

func UninstallApp

func UninstallApp(t *testing.T, ctx *context.T, appID string)

func UpdateApp

func UpdateApp(t *testing.T, ctx *context.T, appID string)

func UpdateAppExpectError

func UpdateAppExpectError(t *testing.T, ctx *context.T, appID string, expectedError verror.ID)

func UpdateDevice

func UpdateDevice(t *testing.T, ctx *context.T, name string)

func UpdateDeviceExpectError

func UpdateDeviceExpectError(t *testing.T, ctx *context.T, name string, errID verror.ID)

func UpdateInstance

func UpdateInstance(t *testing.T, ctx *context.T, appID, instanceID string)

func UpdateInstanceExpectError

func UpdateInstanceExpectError(t *testing.T, ctx *context.T, appID, instanceID string, expectedError verror.ID)

func UserName

func UserName(t *testing.T) string

func VerifyDeviceState

func VerifyDeviceState(t *testing.T, ctx *context.T, want device.InstanceState, name string) string

func VerifyFailGlob

func VerifyFailGlob(t *testing.T, ctx *context.T, testcases []GlobTestVector)

VerifyFailGlob verifies that for each GlobTestVector instance that the pattern returns no matches.

func VerifyGlob

func VerifyGlob(t *testing.T, ctx *context.T, appName string, testcases []GlobTestVector, res *globTestRegexHelper)

VerifyGlob verifies that for each GlobTestVector instance that the pattern returns the expected matches.

func VerifyLog

func VerifyLog(t *testing.T, ctx *context.T, nameComponents ...string)

VerifyLog calls Size() on a selection of log file objects to demonstrate that the log files are accessible and have been written by the application.

func VerifyNoRunningProcesses

func VerifyNoRunningProcesses(t *testing.T)

func VerifyPProfCmdLine

func VerifyPProfCmdLine(t *testing.T, ctx *context.T, appName string, nameComponents ...string)

VerifyPProfCmdLine calls CmdLine() on the pprof object to validate that it the proxy correctly accessess pprof names.

func VerifyState

func VerifyState(t *testing.T, ctx *context.T, want interface{}, nameComponents ...string) string

func VerifyStatsValues

func VerifyStatsValues(t *testing.T, ctx *context.T, nameComponents ...string)

VerifyStatsValues call Value() on some of the stats objects to prove that they are correctly being proxied to the device manager.

func WaitForMount

func WaitForMount(f Fatalist, ctx *context.T, name string, server rpc.Server)

WaitForMount waits (with a reasonable timeout) for the given server's endpoint to be mounted under the given name. Since ctx.WithNewServer and ctx.WithNewDispatchingServer publish the names asynchronously, use WaitForMount if you need a guarantee that the publish has happened.

func WaitForState

func WaitForState(t *testing.T, ctx *context.T, want interface{}, nameComponents ...string)

Types

type Fatalist

type Fatalist interface {
	Fatal(args ...interface{})
	Fatalf(format string, args ...interface{})
}

type GlobTestVector

type GlobTestVector struct {
	Name, Pattern string
	Expected      []string
}

type PingArgs

type PingArgs struct {
	Username, FlagValue, EnvValue,
	DefaultPeerBlessings, PubBlessingPrefixes, InstanceName string
	Pid int
}

type PingServer

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

func SetupPingServer

func SetupPingServer(t *testing.T, ctx *context.T) (PingServer, func())

SetupPingServer creates a server listening for a ping from a child app; it returns a channel on which the app's ping message is returned, and a cleanup function.

func (PingServer) Ping

func (p PingServer) Ping(_ *context.T, _ rpc.ServerCall, arg PingArgs) error

func (PingServer) VerifyPingArgs

func (p PingServer) VerifyPingArgs(t *testing.T, username, flagValue, envValue string) PingArgs

func (PingServer) WaitForPingArgs

func (p PingServer) WaitForPingArgs(t *testing.T) PingArgs

Jump to

Keyboard shortcuts

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