tracker/chihaya_test.go
Josh de Kock a9d3c2e071 store/peer_store: Add tests & functions for getting info about peers
This commit adds four functions: GetSeeders, GetLeechers,
NumSeeders, and NumLeechers to the store/peer_store API. The
first two functions are for getting a list of all the
seeders/leechers by an info hash, the latter two are helper
functions which use the Get functions, combine the ipv4, and
ipv4, and then len() them. It also adds some minimal tests for
memory/peer_store.
2016-04-02 21:49:08 +01:00

46 lines
1.2 KiB
Go

// Copyright 2016 The Chihaya Authors. All rights reserved.
// Use of this source code is governed by the BSD 2-Clause license,
// which can be found in the LICENSE file.
package chihaya
import (
"net"
"testing"
"github.com/stretchr/testify/assert"
)
var (
peers = []struct {
peerID string
ip string
port uint16
}{
{"-AZ3034-6wfG2wk6wWLc", "250.183.81.177", 5720},
{"-BS5820-oy4La2MWGEFj", "fd45:7856:3dae::48", 2878},
{"-TR0960-6ep6svaa61r4", "fd45:7856:3dae::48", 2878},
{"-BS5820-oy4La2MWGEFj", "fd0a:29a8:8445::38", 2878},
{"-BS5820-oy4La2MWGEFj", "fd45:7856:3dae::48", 8999},
}
)
func TestPeerEquality(t *testing.T) {
// Build peers from test data.
var builtPeers []*Peer
for _, peer := range peers {
builtPeers = append(builtPeers, &Peer{
ID: PeerID(peer.peerID),
IP: net.ParseIP(peer.ip),
Port: peer.port,
})
}
assert.True(t, builtPeers[0].Equal(builtPeers[0]))
assert.False(t, builtPeers[0].Equal(builtPeers[1]))
assert.True(t, builtPeers[1].Equal(builtPeers[1]))
assert.False(t, builtPeers[1].Equal(builtPeers[2]))
assert.False(t, builtPeers[1].Equal(builtPeers[3]))
assert.False(t, builtPeers[1].Equal(builtPeers[4]))
}