Documentation ¶
Index ¶
- Variables
- func CreatePeerNodes(t *testing.T, n int, peerings []Peering) (*Harness, Nodes)
- func EnableDebugLogging()
- func NewRandPort() int
- func WaitForFile(path string, timeout time.Duration) error
- type Buffer
- type CmdOpt
- type HTTPClient
- func (c *HTTPClient) BuildURL(urlPath string) string
- func (c *HTTPClient) DisableRedirects() *HTTPClient
- func (c *HTTPClient) Do(req *http.Request) *HTTPResponse
- func (c *HTTPClient) Get(urlPath string, opts ...func(*http.Request)) *HTTPResponse
- func (c *HTTPClient) Head(urlPath string, opts ...func(*http.Request)) *HTTPResponse
- func (c *HTTPClient) Post(urlPath string, body io.Reader, opts ...func(*http.Request)) *HTTPResponse
- func (c *HTTPClient) PostStr(urlpath, body string, opts ...func(*http.Request)) *HTTPResponse
- func (c *HTTPClient) WithHeader(k, v string) func(h *http.Request)
- type HTTPResponse
- type Harness
- func (h *Harness) Cleanup()
- func (h *Harness) ExtractPeerID(m multiaddr.Multiaddr) peer.ID
- func (h *Harness) Mkdirs(paths ...string)
- func (h *Harness) NewNode() *Node
- func (h *Harness) NewNodes(count int) Nodes
- func (h *Harness) Sh(expr string) *RunResult
- func (h *Harness) TempFile() *os.File
- func (h *Harness) WriteFile(filename, contents string)
- func (h *Harness) WriteToTemp(contents string) string
- type Node
- func (n *Node) APIAddr() multiaddr.Multiaddr
- func (n *Node) APIClient() *HTTPClient
- func (n *Node) APIURL() string
- func (n *Node) ConfigFile() string
- func (n *Node) Connect(other *Node) *Node
- func (n *Node) Disconnect(other *Node)
- func (n *Node) GatewayClient() *HTTPClient
- func (n *Node) GatewayURL() string
- func (n *Node) GetIPFSConfig(key string, val interface{})
- func (n *Node) IPFS(args ...string) *RunResult
- func (n *Node) IPFSAdd(content io.Reader, args ...string) string
- func (n *Node) IPFSAddStr(content string, args ...string) string
- func (n *Node) IPFSCommands() []string
- func (n *Node) IPFSDagImport(content io.Reader, cid string, args ...string) error
- func (n *Node) Init(ipfsArgs ...string) *Node
- func (n *Node) IsAlive() bool
- func (n *Node) PeerID() peer.ID
- func (n *Node) PeerWith(other *Node)
- func (n *Node) Peers() []multiaddr.Multiaddr
- func (n *Node) PipeStrToIPFS(s string, args ...string) *RunResult
- func (n *Node) PipeToIPFS(reader io.Reader, args ...string) *RunResult
- func (n *Node) ReadConfig() *config.Config
- func (n *Node) ReadFile(filename string) string
- func (n *Node) ReadUserResourceOverrides() *rcmgr.PartialLimitConfig
- func (n *Node) RunIPFS(args ...string) *RunResult
- func (n *Node) RunPipeToIPFS(reader io.Reader, args ...string) *RunResult
- func (n *Node) SetIPFSConfig(key string, val interface{}, flags ...string)
- func (n *Node) StartDaemon(ipfsArgs ...string) *Node
- func (n *Node) StartDaemonWithAuthorization(secret string, ipfsArgs ...string) *Node
- func (n *Node) StartDaemonWithReq(req RunRequest, authorization string) *Node
- func (n *Node) StopDaemon() *Node
- func (n *Node) SwarmAddrs() []multiaddr.Multiaddr
- func (n *Node) SwarmAddrsWithPeerIDs() []multiaddr.Multiaddr
- func (n *Node) SwarmAddrsWithoutPeerIDs() []multiaddr.Multiaddr
- func (n *Node) TryAPIAddr() (multiaddr.Multiaddr, error)
- func (n *Node) UpdateConfig(f func(cfg *config.Config))
- func (n *Node) UpdateUserSuppliedResourceManagerOverrides(f func(overrides *rcmgr.PartialLimitConfig))
- func (n *Node) WaitOnAPI(authorization string) *Node
- func (n *Node) WriteBytes(filename string, b []byte)
- func (n *Node) WriteConfig(c *config.Config)
- func (n *Node) WriteUserSuppliedResourceOverrides(c *rcmgr.PartialLimitConfig)
- type Nodes
- type Peering
- type RunFunc
- type RunRequest
- type RunResult
- type Runner
- type TestLogger
Constants ¶
This section is empty.
Variables ¶
var RunFuncStart = (*exec.Cmd).Start
Functions ¶
func CreatePeerNodes ¶ added in v0.24.0
func NewRandPort ¶ added in v0.24.0
func NewRandPort() int
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a thread-safe byte buffer.
type CmdOpt ¶
func RunWithEnv ¶
func RunWithPath ¶
func RunWithStderr ¶ added in v0.24.0
func RunWithStdin ¶
func RunWithStdinStr ¶
func RunWithStdout ¶ added in v0.24.0
type HTTPClient ¶
type HTTPClient struct { Client *http.Client BaseURL string Timeout time.Duration TemplateData any }
HTTPClient is an HTTP client with some conveniences for testing. URLs are constructed from a base URL. The response body is buffered into a string. Internal errors cause panics so that tests don't need to check errors. The paths are evaluated as Go templates for readable string interpolation.
func (*HTTPClient) BuildURL ¶
func (c *HTTPClient) BuildURL(urlPath string) string
BuildURL constructs a request URL from the given path by interpolating the string and then appending it to the base URL.
func (*HTTPClient) DisableRedirects ¶
func (c *HTTPClient) DisableRedirects() *HTTPClient
func (*HTTPClient) Do ¶
func (c *HTTPClient) Do(req *http.Request) *HTTPResponse
Do executes the request unchanged.
func (*HTTPClient) Get ¶
func (c *HTTPClient) Get(urlPath string, opts ...func(*http.Request)) *HTTPResponse
func (*HTTPClient) Head ¶
func (c *HTTPClient) Head(urlPath string, opts ...func(*http.Request)) *HTTPResponse
func (*HTTPClient) Post ¶
func (c *HTTPClient) Post(urlPath string, body io.Reader, opts ...func(*http.Request)) *HTTPResponse
func (*HTTPClient) PostStr ¶
func (c *HTTPClient) PostStr(urlpath, body string, opts ...func(*http.Request)) *HTTPResponse
func (*HTTPClient) WithHeader ¶
func (c *HTTPClient) WithHeader(k, v string) func(h *http.Request)
type HTTPResponse ¶
type Harness ¶
Harness tracks state for a test, such as temp dirs and IFPS nodes, and cleans them up after the test.
func (*Harness) ExtractPeerID ¶ added in v0.24.0
ExtractPeerID extracts a peer ID from the given multiaddr, and fatals if it does not contain a peer ID.
func (*Harness) WriteFile ¶
WriteFile writes a file given a filename and its contents. The filename must be a relative path, or this panics.
func (*Harness) WriteToTemp ¶
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 GatewayListenAddr multiaddr.Multiaddr SwarmAddr multiaddr.Multiaddr EnableMDNS bool IPFSBin string Runner *Runner Daemon *RunResult }
Node is a single Kubo node. Each node has its own config and can run its own Kubo daemon.
func (*Node) APIClient ¶
func (n *Node) APIClient() *HTTPClient
func (*Node) ConfigFile ¶ added in v0.24.0
func (*Node) Disconnect ¶ added in v0.24.0
func (*Node) GatewayClient ¶
func (n *Node) GatewayClient() *HTTPClient
func (*Node) GatewayURL ¶
GatewayURL waits for the gateway file and then returns its contents or times out.
func (*Node) GetIPFSConfig ¶
func (*Node) IPFSCommands ¶
func (*Node) IPFSDagImport ¶ added in v0.24.0
func (*Node) ReadConfig ¶
func (*Node) ReadFile ¶ added in v0.24.0
ReadFile reads the specific file. If it is relative, it is relative the node's root dir.
func (*Node) ReadUserResourceOverrides ¶ added in v0.24.0
func (n *Node) ReadUserResourceOverrides() *rcmgr.PartialLimitConfig
func (*Node) RunPipeToIPFS ¶
func (*Node) SetIPFSConfig ¶
func (*Node) StartDaemon ¶
func (*Node) StartDaemonWithAuthorization ¶ added in v0.28.1
func (*Node) StartDaemonWithReq ¶ added in v0.24.0
func (n *Node) StartDaemonWithReq(req RunRequest, authorization string) *Node
StartDaemonWithReq runs a Kubo daemon with the given request. This overwrites the request Path with the Kubo bin path.
For example, if you want to run the daemon and see stderr and stdout to debug:
node.StartDaemonWithReq(harness.RunRequest{ CmdOpts: []harness.CmdOpt{ harness.RunWithStderr(os.Stdout), harness.RunWithStdout(os.Stdout), }, })
func (*Node) StopDaemon ¶
func (*Node) SwarmAddrs ¶
func (n *Node) SwarmAddrs() []multiaddr.Multiaddr
func (*Node) SwarmAddrsWithPeerIDs ¶ added in v0.24.0
func (n *Node) SwarmAddrsWithPeerIDs() []multiaddr.Multiaddr
func (*Node) SwarmAddrsWithoutPeerIDs ¶ added in v0.24.0
func (n *Node) SwarmAddrsWithoutPeerIDs() []multiaddr.Multiaddr
func (*Node) TryAPIAddr ¶
func (*Node) UpdateConfig ¶
func (*Node) UpdateUserSuppliedResourceManagerOverrides ¶ added in v0.24.0
func (n *Node) UpdateUserSuppliedResourceManagerOverrides(f func(overrides *rcmgr.PartialLimitConfig))
func (*Node) WriteBytes ¶ added in v0.24.0
func (*Node) WriteConfig ¶
func (*Node) WriteUserSuppliedResourceOverrides ¶ added in v0.24.0
func (n *Node) WriteUserSuppliedResourceOverrides(c *rcmgr.PartialLimitConfig)
type Nodes ¶
type Nodes []*Node
Nodes is a collection of Kubo nodes along with operations on groups of nodes.
func (Nodes) ForEachPar ¶ added in v0.24.0
func (Nodes) StartDaemons ¶
func (Nodes) StopDaemons ¶
type RunRequest ¶
type RunResult ¶
type Runner ¶
Runner is a process runner which can run subprocesses and aggregate output.
func (*Runner) AssertNoError ¶
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
type TestLogger ¶ added in v0.24.0
type TestLogger struct {
// contains filtered or unexported fields
}
TestLogger is a logger for tests. It buffers output and only writes the output if the test fails or output is explicitly turned on. The purpose of this logger is to allow Go test to run with the verbose flag without printing logs. The verbose flag is useful since it streams test progress, but also printing logs makes the output too verbose.
You can also add prefixes that are prepended to each log message, for extra logging context.
This is implemented as a hierarchy of loggers, with children flushing log entries back to parents. This works because t.Cleanup() processes entries in LIFO order, so children always flush first.
Obviously this logger should never be used in production systems.
func NewTestLogger ¶ added in v0.24.0
func NewTestLogger(t *testing.T) *TestLogger
func (*TestLogger) AddPrefix ¶ added in v0.24.0
func (t *TestLogger) AddPrefix(prefix string) *TestLogger
func (*TestLogger) EnableLogs ¶ added in v0.24.0
func (t *TestLogger) EnableLogs()
func (*TestLogger) Fatal ¶ added in v0.24.0
func (t *TestLogger) Fatal(args ...any)
func (*TestLogger) Fatalf ¶ added in v0.24.0
func (t *TestLogger) Fatalf(format string, args ...any)
func (*TestLogger) Log ¶ added in v0.24.0
func (t *TestLogger) Log(args ...any)
func (*TestLogger) Logf ¶ added in v0.24.0
func (t *TestLogger) Logf(format string, args ...any)