github.com/aergoio/aergo@v1.3.1/p2p/p2putil/peerutil_test.go (about) 1 package p2putil 2 3 import ( 4 "github.com/aergoio/aergo/types" 5 "strconv" 6 "strings" 7 "testing" 8 9 "github.com/aergoio/aergo/p2p/p2pcommon" 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestPeerMeta_String(t *testing.T) { 14 type fields struct { 15 ip string 16 port uint32 17 id string 18 } 19 tests := []struct { 20 name string 21 fields fields 22 }{ 23 {"t1", fields{"192.168.1.2", 2, "id0002"}}, 24 {"t2", fields{"0.0.0.0", 2223, "id2223"}}, 25 {"t3", fields{"2001:0db8:85a3:08d3:1319:8a2e:0370:7334", 444, "id0002"}}, 26 {"t4", fields{"::ffff:192.0.1.2", 444, "id0002"}}, 27 } 28 for _, tt := range tests { 29 t.Run(tt.name, func(t *testing.T) { 30 m := p2pcommon.PeerMeta{ 31 IPAddress: tt.fields.ip, 32 Port: tt.fields.port, 33 ID: types.PeerID(tt.fields.id), 34 Designated: false, 35 Outbound: false, 36 } 37 actual := ShortMetaForm(m) 38 assert.True(t, strings.Contains(actual, tt.fields.ip)) 39 assert.True(t, strings.Contains(actual, strconv.Itoa(int(tt.fields.port)))) 40 assert.True(t, strings.Contains(actual, m.ID.Pretty())) 41 m2 := m 42 m2.Designated = true 43 assert.Equal(t, actual, ShortMetaForm(m2)) 44 m3 := m 45 m3.Outbound = true 46 assert.Equal(t, actual, ShortMetaForm(m3)) 47 }) 48 } 49 }