ceremonyclient/go-libp2p/core/test/addrs.go
2023-08-20 23:07:43 -05:00

43 lines
709 B
Go

package test
import (
"fmt"
"testing"
ma "github.com/multiformats/go-multiaddr"
)
func GenerateTestAddrs(n int) []ma.Multiaddr {
out := make([]ma.Multiaddr, n)
for i := 0; i < n; i++ {
a, err := ma.NewMultiaddr(fmt.Sprintf("/ip4/1.2.3.4/tcp/%d", i))
if err != nil {
continue
}
out[i] = a
}
return out
}
func AssertAddressesEqual(t *testing.T, exp, act []ma.Multiaddr) {
t.Helper()
if len(exp) != len(act) {
t.Fatalf("lengths not the same. expected %d, got %d\n", len(exp), len(act))
}
for _, a := range exp {
found := false
for _, b := range act {
if a.Equal(b) {
found = true
break
}
}
if !found {
t.Fatalf("expected address %s not found", a)
}
}
}