depot/packages/networking/ipfs-cluster/cmd/ipfs-cluster-service/main_test.go

39 lines
690 B
Go
Raw Normal View History

2022-10-19 23:23:11 +03:00
package main
import (
"testing"
"github.com/ipfs-cluster/ipfs-cluster/cmdutils"
ma "github.com/multiformats/go-multiaddr"
)
func TestRandomPorts(t *testing.T) {
port := "9096"
m1, _ := ma.NewMultiaddr("/ip4/0.0.0.0/tcp/9096")
m2, _ := ma.NewMultiaddr("/ip6/::/udp/9096")
addresses, err := cmdutils.RandomizePorts([]ma.Multiaddr{m1, m2})
if err != nil {
t.Fatal(err)
}
v1, err := addresses[0].ValueForProtocol(ma.P_TCP)
if err != nil {
t.Fatal(err)
}
v2, err := addresses[1].ValueForProtocol(ma.P_UDP)
if err != nil {
t.Fatal(err)
}
if v1 == port {
t.Error("expected different ipv4 ports")
}
if v2 == port {
t.Error("expected different ipv6 ports")
}
}