diff options
Diffstat (limited to 'plugin/forward/proxy_test.go')
-rw-r--r-- | plugin/forward/proxy_test.go | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/plugin/forward/proxy_test.go b/plugin/forward/proxy_test.go index 01e8ef6fd..d68d1def2 100644 --- a/plugin/forward/proxy_test.go +++ b/plugin/forward/proxy_test.go @@ -29,10 +29,10 @@ func TestProxyClose(t *testing.T) { p := NewProxy(s.Addr, nil) p.start(hcInterval) - go func() { p.Connect(ctx, state, false, false) }() - go func() { p.Connect(ctx, state, true, false) }() - go func() { p.Connect(ctx, state, false, false) }() - go func() { p.Connect(ctx, state, true, false) }() + go func() { p.Connect(ctx, state, options{}) }() + go func() { p.Connect(ctx, state, options{forceTCP: true}) }() + go func() { p.Connect(ctx, state, options{}) }() + go func() { p.Connect(ctx, state, options{forceTCP: true}) }() p.close() } @@ -93,3 +93,30 @@ func TestProxyTLSFail(t *testing.T) { t.Fatal("Expected *not* to receive reply, but got one") } } + +func TestProtocolSelection(t *testing.T) { + p := NewProxy("bad_address", nil) + + stateUDP := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)} + stateTCP := request.Request{W: &test.ResponseWriter{TCP: true}, Req: new(dns.Msg)} + ctx := context.TODO() + + go func() { + p.Connect(ctx, stateUDP, options{}) + p.Connect(ctx, stateUDP, options{forceTCP: true}) + p.Connect(ctx, stateUDP, options{preferUDP: true}) + p.Connect(ctx, stateUDP, options{preferUDP: true, forceTCP: true}) + p.Connect(ctx, stateTCP, options{}) + p.Connect(ctx, stateTCP, options{forceTCP: true}) + p.Connect(ctx, stateTCP, options{preferUDP: true}) + p.Connect(ctx, stateTCP, options{preferUDP: true, forceTCP: true}) + }() + + for i, exp := range []string{"udp", "tcp", "udp", "tcp", "tcp", "tcp", "udp", "tcp"} { + proto := <-p.transport.dial + p.transport.ret <- nil + if proto != exp { + t.Errorf("Unexpected protocol in case %d, expected %q, actual %q", i, exp, proto) + } + } +} |