plugin/forward: Allow Proxy to be used outside of forward plugin. (#5951)
* plugin/forward: Move Proxy into pkg/plugin/proxy, to allow forward.Proxy to be used outside of forward plugin. Signed-off-by: Patrick Downey <patrick.downey@dioadconsulting.com>
This commit is contained in:
parent
47dceabfc6
commit
f823825f8a
19 changed files with 529 additions and 210 deletions
|
@ -8,23 +8,33 @@ import (
|
|||
"github.com/coredns/caddy/caddyfile"
|
||||
"github.com/coredns/coredns/core/dnsserver"
|
||||
"github.com/coredns/coredns/plugin/dnstap"
|
||||
"github.com/coredns/coredns/plugin/pkg/proxy"
|
||||
"github.com/coredns/coredns/plugin/pkg/transport"
|
||||
)
|
||||
|
||||
func TestList(t *testing.T) {
|
||||
f := Forward{
|
||||
proxies: []*Proxy{{addr: "1.1.1.1:53"}, {addr: "2.2.2.2:53"}, {addr: "3.3.3.3:53"}},
|
||||
p: &roundRobin{},
|
||||
proxies: []*proxy.Proxy{
|
||||
proxy.NewProxy("1.1.1.1:53", transport.DNS),
|
||||
proxy.NewProxy("2.2.2.2:53", transport.DNS),
|
||||
proxy.NewProxy("3.3.3.3:53", transport.DNS),
|
||||
},
|
||||
p: &roundRobin{},
|
||||
}
|
||||
|
||||
expect := []*Proxy{{addr: "2.2.2.2:53"}, {addr: "1.1.1.1:53"}, {addr: "3.3.3.3:53"}}
|
||||
expect := []*proxy.Proxy{
|
||||
proxy.NewProxy("2.2.2.2:53", transport.DNS),
|
||||
proxy.NewProxy("1.1.1.1:53", transport.DNS),
|
||||
proxy.NewProxy("3.3.3.3:53", transport.DNS),
|
||||
}
|
||||
got := f.List()
|
||||
|
||||
if len(got) != len(expect) {
|
||||
t.Fatalf("Expected: %v results, got: %v", len(expect), len(got))
|
||||
}
|
||||
for i, p := range got {
|
||||
if p.addr != expect[i].addr {
|
||||
t.Fatalf("Expected proxy %v to be '%v', got: '%v'", i, expect[i].addr, p.addr)
|
||||
if p.Addr() != expect[i].Addr() {
|
||||
t.Fatalf("Expected proxy %v to be '%v', got: '%v'", i, expect[i].Addr(), p.Addr())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue