kubo/test/cli/dht_autoclient_test.go
Andrew Gillis b8a1aa471c
Some checks are pending
CodeQL / codeql (push) Waiting to run
Docker Build / docker-build (push) Waiting to run
Gateway Conformance / gateway-conformance (push) Waiting to run
Gateway Conformance / gateway-conformance-libp2p-experiment (push) Waiting to run
Go Build / go-build (push) Waiting to run
Go Check / go-check (push) Waiting to run
Go Lint / go-lint (push) Waiting to run
Go Test / go-test (push) Waiting to run
Interop / interop-prep (push) Waiting to run
Interop / helia-interop (push) Blocked by required conditions
Interop / ipfs-webui (push) Blocked by required conditions
Sharness / sharness-test (push) Waiting to run
Spell Check / spellcheck (push) Waiting to run
chore: replace random test utils with equivalents in go-test/random (#10915)
Replace test functionality that is dublicated in go-test/random
2025-08-14 10:37:55 -07:00

41 lines
1.1 KiB
Go

package cli
import (
"bytes"
"testing"
"github.com/ipfs/go-test/random"
"github.com/ipfs/kubo/test/cli/harness"
"github.com/stretchr/testify/assert"
)
func TestDHTAutoclient(t *testing.T) {
t.Parallel()
nodes := harness.NewT(t).NewNodes(10).Init()
harness.Nodes(nodes[8:]).ForEachPar(func(node *harness.Node) {
node.IPFS("config", "Routing.Type", "autoclient")
})
nodes.StartDaemons().Connect()
t.Run("file added on node in client mode is retrievable from node in client mode", func(t *testing.T) {
t.Parallel()
randomBytes := random.Bytes(1000)
randomBytes = append(randomBytes, '\r')
hash := nodes[8].IPFSAdd(bytes.NewReader(randomBytes))
res := nodes[9].IPFS("cat", hash)
assert.Equal(t, randomBytes, []byte(res.Stdout.Trimmed()))
})
t.Run("file added on node in server mode is retrievable from all nodes", func(t *testing.T) {
t.Parallel()
randomBytes := random.Bytes(1000)
hash := nodes[0].IPFSAdd(bytes.NewReader(randomBytes))
for i := 0; i < 10; i++ {
res := nodes[i].IPFS("cat", hash)
assert.Equal(t, randomBytes, []byte(res.Stdout.Trimmed()))
}
})
}