mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 18:37: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.
74 lines
2.1 KiB
Go
74 lines
2.1 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/ipfs/kubo/test/cli/harness"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestPing(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
t.Run("other", func(t *testing.T) {
|
|
t.Parallel()
|
|
nodes := harness.NewT(t).NewNodes(2).Init().StartDaemons().Connect()
|
|
node1 := nodes[0]
|
|
node2 := nodes[1]
|
|
|
|
node1.IPFS("ping", "-n", "2", "--", node2.PeerID().String())
|
|
node2.IPFS("ping", "-n", "2", "--", node1.PeerID().String())
|
|
})
|
|
|
|
t.Run("ping unreachable peer", func(t *testing.T) {
|
|
t.Parallel()
|
|
nodes := harness.NewT(t).NewNodes(2).Init().StartDaemons().Connect()
|
|
node1 := nodes[0]
|
|
|
|
badPeer := "QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJx"
|
|
res := node1.RunIPFS("ping", "-n", "2", "--", badPeer)
|
|
assert.Contains(t, res.Stdout.String(), fmt.Sprintf("Looking up peer %s", badPeer))
|
|
assert.Contains(t, res.Stderr.String(), "Error: ping failed")
|
|
})
|
|
|
|
t.Run("self", func(t *testing.T) {
|
|
t.Parallel()
|
|
nodes := harness.NewT(t).NewNodes(2).Init().StartDaemons()
|
|
node1 := nodes[0]
|
|
node2 := nodes[1]
|
|
|
|
res := node1.RunIPFS("ping", "-n", "2", "--", node1.PeerID().String())
|
|
assert.Equal(t, 1, res.Cmd.ProcessState.ExitCode())
|
|
assert.Contains(t, res.Stderr.String(), "can't ping self")
|
|
|
|
res = node2.RunIPFS("ping", "-n", "2", "--", node2.PeerID().String())
|
|
assert.Equal(t, 1, res.Cmd.ProcessState.ExitCode())
|
|
assert.Contains(t, res.Stderr.String(), "can't ping self")
|
|
})
|
|
|
|
t.Run("0", func(t *testing.T) {
|
|
t.Parallel()
|
|
nodes := harness.NewT(t).NewNodes(2).Init().StartDaemons().Connect()
|
|
node1 := nodes[0]
|
|
node2 := nodes[1]
|
|
|
|
res := node1.RunIPFS("ping", "-n", "0", "--", node2.PeerID().String())
|
|
assert.Equal(t, 1, res.Cmd.ProcessState.ExitCode())
|
|
assert.Contains(t, res.Stderr.String(), "ping count must be greater than 0")
|
|
})
|
|
|
|
t.Run("offline", func(t *testing.T) {
|
|
t.Parallel()
|
|
nodes := harness.NewT(t).NewNodes(2).Init().StartDaemons().Connect()
|
|
node1 := nodes[0]
|
|
node2 := nodes[1]
|
|
|
|
node2.StopDaemon()
|
|
|
|
res := node1.RunIPFS("ping", "-n", "2", "--", node2.PeerID().String())
|
|
assert.Equal(t, 1, res.Cmd.ProcessState.ExitCode())
|
|
assert.Contains(t, res.Stderr.String(), "ping failed")
|
|
})
|
|
}
|