You've already forked torrent-client
mirror of
https://github.com/veggiedefender/torrent-client.git
synced 2025-11-06 09:29:16 +02:00
Implement peer String() method
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Peer encodes connection information for a peer
|
||||
@@ -28,3 +29,7 @@ func Unmarshal(peersBin []byte) ([]Peer, error) {
|
||||
}
|
||||
return peers, nil
|
||||
}
|
||||
|
||||
func (p Peer) String() string {
|
||||
return net.JoinHostPort(p.IP.String(), strconv.Itoa(int(p.Port)))
|
||||
}
|
||||
|
||||
@@ -37,3 +37,19 @@ func TestUnmarshal(t *testing.T) {
|
||||
assert.Equal(t, test.output, peers)
|
||||
}
|
||||
}
|
||||
|
||||
func TestString(t *testing.T) {
|
||||
tests := []struct {
|
||||
input Peer
|
||||
output string
|
||||
}{
|
||||
{
|
||||
input: Peer{IP: net.IP{127, 0, 0, 1}, Port: 8080},
|
||||
output: "127.0.0.1:8080",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
s := test.input.String()
|
||||
assert.Equal(t, test.output, s)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user