-
Notifications
You must be signed in to change notification settings - Fork 712
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |