Skip to content

Commit

Permalink
Unit test for the resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
inercia committed Sep 2, 2015
1 parent 74499bf commit 460bedd
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions probe/endpoint/resolver_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package endpoint_test

import (
"testing"

"github.com/weaveworks/scope/probe/endpoint"
"time"
)

func TestReverseResolver(t *testing.T) {
revRes := endpoint.NewReverseResolver(100)
tests := []struct {
ip string
name string
}{
{"8.8.8.8", "google-public-dns-a.google.com."},
{"8.8.4.4", "google-public-dns-b.google.com."},
}

// first time: no names are returned for our reverse resolutions
for _, v := range tests {
if name, err := revRes.Get(v.ip); name != "" || err == nil {
t.Errorf("we didn't get an error, or the cache was not empty, hen trying to resolve '%s'", v.ip)
}
}

// after some time, the async resolver should have the names in the cache
time.Sleep(500 * time.Millisecond)

// so, if we check again these IPs, we should have the names now
for _, v := range tests {
name, err := revRes.Get(v.ip)
if err != nil {
t.Errorf("we got an error when trying to resolve '%s': %s", v.ip, err)
}
if name != v.name {
t.Errorf("got %s for '%s', but expected '%s'", name, v.ip, v.name)
}
}
}

0 comments on commit 460bedd

Please sign in to comment.