mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-26 04:47:45 +08:00
This is intended as a replacement for sharness. These are vanilla Go tests which can be run in your IDE for quick iteration on end-to-end CLI tests. This also removes IPTB by duplicating its functionality in the test harness. This isn't a big deal...IPTB's complexity is mostly around the fact that its state needs to be saved to disk in between `iptb` command invocations, and that it uses Go plugins to inject functionality, neither of which are relevant here. If we merge this, we'll have to live with bifurcated tests for a while until they are all migrated. I'd recommend we self-enforce a rule that, if we need to touch a sharness test, we migrate it and one more test over to Go tests first. Then eventually we will have migrated everything.
48 lines
872 B
Go
48 lines
872 B
Go
package harness
|
|
|
|
import (
|
|
"github.com/multiformats/go-multiaddr"
|
|
)
|
|
|
|
// Nodes is a collection of Kubo nodes along with operations on groups of nodes.
|
|
type Nodes []*Node
|
|
|
|
func (n Nodes) Init(args ...string) Nodes {
|
|
for _, node := range n {
|
|
node.Init()
|
|
}
|
|
return n
|
|
}
|
|
|
|
func (n Nodes) Connect() Nodes {
|
|
for i, node := range n {
|
|
for j, otherNode := range n {
|
|
if i == j {
|
|
continue
|
|
}
|
|
node.Connect(otherNode)
|
|
}
|
|
}
|
|
for _, node := range n {
|
|
firstPeer := node.Peers()[0]
|
|
if _, err := firstPeer.ValueForProtocol(multiaddr.P_P2P); err != nil {
|
|
log.Panicf("unexpected state for node %d with peer ID %s: %s", node.ID, node.PeerID(), err)
|
|
}
|
|
}
|
|
return n
|
|
}
|
|
|
|
func (n Nodes) StartDaemons() Nodes {
|
|
for _, node := range n {
|
|
node.StartDaemon()
|
|
}
|
|
return n
|
|
}
|
|
|
|
func (n Nodes) StopDaemons() Nodes {
|
|
for _, node := range n {
|
|
node.StopDaemon()
|
|
}
|
|
return n
|
|
}
|