Skip to content

Commit

Permalink
new file: resolver_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
nbari committed Jun 6, 2017
1 parent a1c0e73 commit 6a6b7b5
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions resolver_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package slashquery

import (
"testing"

"github.com/slashquery/resolver"
)

func TestResolveUpstreams(t *testing.T) {
upstreams := make(map[string]*Upstream)
upstreams["localhost"] = &Upstream{
Servers: []string{"127.0.0.1"},
}
r, err := resolver.New("8.8.8.8")
if err != nil {
t.Fatal(err)
}
sq := &Slashquery{
Upstreams: upstreams,
Servers: make(map[string]*Servers),
Resolver: r,
}

sq.ResolveUpstreams()

if val, ok := sq.Servers["127.0.0.1"]; !ok {
t.Fatalf("Expecting %q", "127.0.0.1")
} else {
v := val.Addresses[0]
if v != "127.0.0.1" {
t.Fatalf("Expecting %q", "127.0.0.1")
}
}
}

func TestResolveUpstream(t *testing.T) {
config := make(map[string]string)
config["debug"] = "yes"
upstreams := make(map[string]*Upstream)
upstreams["localhost"] = &Upstream{
Servers: []string{"127.0.0.1"},
}
r, err := resolver.New("8.8.8.8")
if err != nil {
t.Fatal(err)
}
sq := &Slashquery{
Upstreams: upstreams,
Servers: make(map[string]*Servers),
Resolver: r,
Config: config,
}

sq.ResolveUpstream("127.0.0.1")

if val, ok := sq.Servers["127.0.0.1"]; !ok {
t.Fatalf("Expecting %q", "127.0.0.1")
} else {
v := val.Addresses[0]
if v != "127.0.0.1" {
t.Fatalf("Expecting %q", "127.0.0.1")
}
}
}

0 comments on commit 6a6b7b5

Please sign in to comment.