mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-07 01:08:08 +08:00
go-ipfs-config: fix string formatting of bootstrap peers
This commit is contained in:
parent
ae7c2e962f
commit
e9c30cf356
@ -73,9 +73,16 @@ func ParseBootstrapPeers(addrs []string) ([]peer.AddrInfo, error) {
|
||||
// BootstrapPeerStrings formats a list of AddrInfos as a bootstrap peer list
|
||||
// suitable for serialization.
|
||||
func BootstrapPeerStrings(bps []peer.AddrInfo) []string {
|
||||
bpss := make([]string, len(bps))
|
||||
for i, p := range bps {
|
||||
bpss[i] = p.String()
|
||||
bpss := make([]string, 0, len(bps))
|
||||
for _, pi := range bps {
|
||||
addrs, err := peer.AddrInfoToP2pAddrs(&pi)
|
||||
if err != nil {
|
||||
// programmer error.
|
||||
panic(err)
|
||||
}
|
||||
for _, addr := range addrs {
|
||||
bpss = append(bpss, addr.String())
|
||||
}
|
||||
}
|
||||
return bpss
|
||||
}
|
||||
|
||||
24
config/bootstrap_peers_test.go
Normal file
24
config/bootstrap_peers_test.go
Normal file
@ -0,0 +1,24 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBoostrapPeerStrings(t *testing.T) {
|
||||
parsed, err := ParseBootstrapPeers(DefaultBootstrapAddresses)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
formatted := BootstrapPeerStrings(parsed)
|
||||
sort.Strings(formatted)
|
||||
expected := append([]string{}, DefaultBootstrapAddresses...)
|
||||
sort.Strings(expected)
|
||||
|
||||
for i, s := range formatted {
|
||||
if expected[i] != s {
|
||||
t.Fatalf("expected %s, %s", expected[i], s)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user