harness

package
v0.18.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: Apache-2.0, MIT, Apache-2.0, + 1 more Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RunFuncStart = (*exec.Cmd).Start

Functions

func EnableDebugLogging

func EnableDebugLogging()

TODO: use zaptest.NewLogger(t) instead

func WaitForFile

func WaitForFile(path string, timeout time.Duration) error

Types

type Buffer

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

Buffer is a thread-safe byte buffer.

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

func (*Buffer) Lines

func (b *Buffer) Lines() []string

func (*Buffer) String

func (b *Buffer) String() string

func (*Buffer) Trimmed

func (b *Buffer) Trimmed() string

Trimmed returns the bytes as a string, with leading and trailing whitespace removed.

func (*Buffer) Write

func (b *Buffer) Write(p []byte) (n int, err error)

type CmdOpt

type CmdOpt func(*exec.Cmd)

func RunWithEnv

func RunWithEnv(env map[string]string) CmdOpt

func RunWithPath

func RunWithPath(path string) CmdOpt

func RunWithStdin

func RunWithStdin(reader io.Reader) CmdOpt

func RunWithStdinStr

func RunWithStdinStr(s string) CmdOpt

type Harness

type Harness struct {
	Dir       string
	IPFSBin   string
	Runner    *Runner
	NodesRoot string
	Nodes     Nodes
}

Harness tracks state for a test, such as temp dirs and IFPS nodes, and cleans them up after the test.

func New

func New(options ...func(h *Harness)) *Harness

func NewT

func NewT(t *testing.T, options ...func(h *Harness)) *Harness

NewT constructs a harness that cleans up after the given test is done.

func (*Harness) Cleanup

func (h *Harness) Cleanup()

func (*Harness) Mkdirs

func (h *Harness) Mkdirs(paths ...string)

func (*Harness) NewNode

func (h *Harness) NewNode() *Node

func (*Harness) NewNodes

func (h *Harness) NewNodes(count int) Nodes

func (*Harness) Sh

func (h *Harness) Sh(expr string) RunResult

func (*Harness) TempFile

func (h *Harness) TempFile() *os.File

TempFile creates a new unique temp file.

func (*Harness) WriteFile

func (h *Harness) WriteFile(filename, contents string)

WriteFile writes a file given a filename and its contents. The filename should be a relative path.

func (*Harness) WriteToTemp

func (h *Harness) WriteToTemp(contents string) string

WriteToTemp writes the given contents to a guaranteed-unique temp file, returning its path.

type Node

type Node struct {
	ID  int
	Dir string

	APIListenAddr multiaddr.Multiaddr
	SwarmAddr     multiaddr.Multiaddr
	EnableMDNS    bool

	IPFSBin string
	Runner  *Runner
	// contains filtered or unexported fields
}

Node is a single Kubo node. Each node has its own config and can run its own Kubo daemon.

func BuildNode

func BuildNode(ipfsBin, baseDir string, id int) *Node

func (*Node) APIAddr

func (n *Node) APIAddr() multiaddr.Multiaddr

func (*Node) Connect

func (n *Node) Connect(other *Node) *Node

func (*Node) GetIPFSConfig

func (n *Node) GetIPFSConfig(key string, val interface{})

func (*Node) IPFS

func (n *Node) IPFS(args ...string) RunResult

func (*Node) IPFSAdd

func (n *Node) IPFSAdd(content io.Reader, args ...string) string

func (*Node) IPFSAddStr

func (n *Node) IPFSAddStr(content string, args ...string) string

func (*Node) IPFSCommands

func (n *Node) IPFSCommands() []string

func (*Node) Init

func (n *Node) Init(ipfsArgs ...string) *Node

Init initializes and configures the IPFS node, after which it is ready to run.

func (*Node) IsAlive

func (n *Node) IsAlive() bool

func (*Node) PeerID

func (n *Node) PeerID() peer.ID

func (*Node) Peers

func (n *Node) Peers() []multiaddr.Multiaddr

func (*Node) PipeStrToIPFS

func (n *Node) PipeStrToIPFS(s string, args ...string) RunResult

func (*Node) PipeToIPFS

func (n *Node) PipeToIPFS(reader io.Reader, args ...string) RunResult

func (*Node) ReadConfig

func (n *Node) ReadConfig() *config.Config

func (*Node) RunIPFS

func (n *Node) RunIPFS(args ...string) RunResult

func (*Node) RunPipeToIPFS

func (n *Node) RunPipeToIPFS(reader io.Reader, args ...string) RunResult

func (*Node) SetIPFSConfig

func (n *Node) SetIPFSConfig(key string, val interface{}, flags ...string)

func (*Node) StartDaemon

func (n *Node) StartDaemon(ipfsArgs ...string) *Node

func (*Node) StopDaemon

func (n *Node) StopDaemon() *Node

func (*Node) SwarmAddrs

func (n *Node) SwarmAddrs() []multiaddr.Multiaddr

func (*Node) TryAPIAddr

func (n *Node) TryAPIAddr() (multiaddr.Multiaddr, error)

func (*Node) UpdateConfig

func (n *Node) UpdateConfig(f func(cfg *config.Config))

func (*Node) WaitOnAPI

func (n *Node) WaitOnAPI() *Node

func (*Node) WriteConfig

func (n *Node) WriteConfig(c *config.Config)

type Nodes

type Nodes []*Node

Nodes is a collection of Kubo nodes along with operations on groups of nodes.

func (Nodes) Connect

func (n Nodes) Connect() Nodes

func (Nodes) Init

func (n Nodes) Init(args ...string) Nodes

func (Nodes) StartDaemons

func (n Nodes) StartDaemons() Nodes

func (Nodes) StopDaemons

func (n Nodes) StopDaemons() Nodes

type RunFunc

type RunFunc func(*exec.Cmd) error

type RunRequest

type RunRequest struct {
	Path string
	Args []string
	// Options that are applied to the exec.Cmd just before running it
	CmdOpts []CmdOpt
	// Function to use to run the command.
	// If not specified, defaults to cmd.Run
	RunFunc func(*exec.Cmd) error
	Verbose bool
}

type RunResult

type RunResult struct {
	Stdout  *Buffer
	Stderr  *Buffer
	Err     error
	ExitErr *exec.ExitError
	Cmd     *exec.Cmd
}

type Runner

type Runner struct {
	Env     map[string]string
	Dir     string
	Verbose bool
}

Runner is a process runner which can run subprocesses and aggregate output.

func (*Runner) AssertNoError

func (r *Runner) AssertNoError(result RunResult)

func (*Runner) MustRun

func (r *Runner) MustRun(req RunRequest) RunResult

MustRun runs the command and fails the test if the command fails.

func (*Runner) Run

func (r *Runner) Run(req RunRequest) RunResult

Jump to

Keyboard shortcuts

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