test

package
v0.8.29 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: Apache-2.0, MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// When this environ var is set to a value and running tests with -v flag,
	// then TestIpniRunner output is logged.
	EnvTestIpniRunnerOutput = "TEST_IPNI_RUNNER_OUTPUT"

	IndexerReadyMatch    = "Indexer is ready"
	ProviderHasPeerMatch = "connected to peer successfully"
	ProviderReadyMatch   = "admin http server listening"
	DhstoreReady         = "Store opened."
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Execution

type Execution struct {
	Name     string
	Args     []string
	Watchers []StdoutWatcher
}

func NewExecution

func NewExecution(name string, args ...string) Execution

func (Execution) String

func (p Execution) String() string

func (Execution) WithWatcher

func (p Execution) WithWatcher(watcher StdoutWatcher) Execution

type StdoutWatcher

type StdoutWatcher struct {
	Match  string
	Signal chan struct{}
}

StdoutWatcher is a helper for watching the stdout of a command for a specific string. It is used by TestIpniRunner to watch for specific output from the commands. The Signal channel will be sent on when the match string is found.

func NewStdoutWatcher

func NewStdoutWatcher(match string) StdoutWatcher

type TestIpniRunner

type TestIpniRunner struct {
	Ctx context.Context
	Dir string
	Env []string
	// contains filtered or unexported fields
}

TestIpniRunner is a helper for running the indexer and other commands. TestIpniRunner is not specifically tied to the indexer, but is designed to be used to manage multiple processes in a test; and is therefore useful for testing the indexer, the dhstore, and providers, all in a temporary directory and with a test environment.

func NewTestIpniRunner

func NewTestIpniRunner(t *testing.T, ctx context.Context, dir string) *TestIpniRunner

NewTestIpniRunner creates a new TestIpniRunner for the given test, context, and temporary directory. It also takes a list of StdoutWatchers, which will be used to watch for specific output from the commands.

func (*TestIpniRunner) Run

func (tr *TestIpniRunner) Run(name string, args ...string) []byte

Run runs a command and returns its output. This is useful for executing synchronous commands within the temporary environment.

func (*TestIpniRunner) Start

func (tr *TestIpniRunner) Start(ex Execution) *exec.Cmd

Start starts a command and returns the command. This is useful for executing asynchronous commands within the temporary environment. It will watch the command's stdout for the given match string, and send on a watcher's channel when/if found.

func (*TestIpniRunner) Stop

func (tr *TestIpniRunner) Stop(cmd *exec.Cmd, timeout time.Duration)

Stop stops a command. It sends SIGINT, and if that doesn't work, SIGKILL.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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