Discovery clients now take an announcer, global discovery is delayed

This commit is contained in:
Audrius Butkevicius
2015-07-23 20:01:25 +01:00
parent 8f2db99c86
commit 687fbb0a7e
7 changed files with 62 additions and 32 deletions

View File

@@ -24,6 +24,14 @@ func init() {
device, _ = protocol.DeviceIDFromString("P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2")
}
type FakeAnnouncer struct {
pkt Announce
}
func (f *FakeAnnouncer) Announcement() Announce {
return f.pkt
}
func TestUDP4Success(t *testing.T) {
conn, err := net.ListenUDP("udp4", nil)
if err != nil {
@@ -33,7 +41,7 @@ func TestUDP4Success(t *testing.T) {
port := conn.LocalAddr().(*net.UDPAddr).Port
address := fmt.Sprintf("udp4://127.0.0.1:%d", port)
pkt := &Announce{
pkt := Announce{
Magic: AnnouncementMagic,
This: Device{
device[:],
@@ -41,8 +49,11 @@ func TestUDP4Success(t *testing.T) {
nil,
},
}
ann := &FakeAnnouncer{
pkt: pkt,
}
client, err := New(address, pkt)
client, err := New(address, ann)
if err != nil {
t.Fatal(err)
}
@@ -137,7 +148,7 @@ func TestUDP4Failure(t *testing.T) {
address := fmt.Sprintf("udp4://127.0.0.1:%d/?listenaddress=127.0.0.1&retry=5", port)
pkt := &Announce{
pkt := Announce{
Magic: AnnouncementMagic,
This: Device{
device[:],
@@ -145,8 +156,11 @@ func TestUDP4Failure(t *testing.T) {
nil,
},
}
ann := &FakeAnnouncer{
pkt: pkt,
}
client, err := New(address, pkt)
client, err := New(address, ann)
if err != nil {
t.Fatal(err)
}