| 1 | package cli |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/ipfs/go-test/random" |
| 8 | "github.com/ipfs/kubo/test/cli/harness" |
| 9 | "github.com/stretchr/testify/assert" |
| 10 | ) |
| 11 | |
| 12 | func TestDHTAutoclient(t *testing.T) { |
| 13 | t.Parallel() |
| 14 | nodes := harness.NewT(t).NewNodes(10).Init() |
| 15 | harness.Nodes(nodes[8:]).ForEachPar(func(node *harness.Node) { |
| 16 | node.IPFS("config", "Routing.Type", "autoclient") |
| 17 | }) |
| 18 | nodes.StartDaemons().Connect() |
| 19 | t.Cleanup(func() { nodes.StopDaemons() }) |
| 20 | |
| 21 | t.Run("file added on node in client mode is retrievable from node in client mode", func(t *testing.T) { |
| 22 | t.Parallel() |
| 23 | randomBytes := random.Bytes(1000) |
| 24 | randomBytes = append(randomBytes, '\r') |
| 25 | hash := nodes[8].IPFSAdd(bytes.NewReader(randomBytes)) |
| 26 | |
| 27 | res := nodes[9].IPFS("cat", hash) |
| 28 | assert.Equal(t, randomBytes, []byte(res.Stdout.Trimmed())) |
| 29 | }) |
| 30 | |
| 31 | t.Run("file added on node in server mode is retrievable from all nodes", func(t *testing.T) { |
| 32 | t.Parallel() |
| 33 | randomBytes := random.Bytes(1000) |
| 34 | hash := nodes[0].IPFSAdd(bytes.NewReader(randomBytes)) |
| 35 | |
| 36 | for i := range 10 { |
| 37 | res := nodes[i].IPFS("cat", hash) |
| 38 | assert.Equal(t, randomBytes, []byte(res.Stdout.Trimmed())) |
| 39 | } |
| 40 | }) |
| 41 | } |