kubo/test/cli/dht_autoclient_test.go
Andrew Gillis aa3c88dcdd
Some checks failed
CodeQL / codeql (push) Has been cancelled
Docker Check / lint (push) Has been cancelled
Docker Check / build (push) Has been cancelled
Gateway Conformance / gateway-conformance (push) Has been cancelled
Gateway Conformance / gateway-conformance-libp2p-experiment (push) Has been cancelled
Go Build / go-build (push) Has been cancelled
Go Check / go-check (push) Has been cancelled
Go Lint / go-lint (push) Has been cancelled
Go Test / unit-tests (push) Has been cancelled
Go Test / cli-tests (push) Has been cancelled
Go Test / example-tests (push) Has been cancelled
Interop / interop-prep (push) Has been cancelled
Sharness / sharness-test (push) Has been cancelled
Spell Check / spellcheck (push) Has been cancelled
Interop / helia-interop (push) Has been cancelled
Interop / ipfs-webui (push) Has been cancelled
shutdown daemon after test (#11135)
2026-01-07 20:51:19 -08:00

42 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.Cleanup(func() { nodes.StopDaemons() })
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()))
}
})
}