MCPcopy
hub / github.com/coredns/coredns / TestProxy

Function TestProxy

plugin/forward/proxy_test.go:14–42  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestProxy(t *testing.T) {
15 s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
16 ret := new(dns.Msg)
17 ret.SetReply(r)
18 ret.Answer = append(ret.Answer, test.A("example.org. IN A 127.0.0.1"))
19 w.WriteMsg(ret)
20 })
21 defer s.Close()
22
23 c := caddy.NewTestController("dns", "forward . "+s.Addr)
24 fs, err := parseForward(c)
25 f := fs[0]
26 if err != nil {
27 t.Errorf("Failed to create forwarder: %s", err)
28 }
29 f.OnStartup()
30 defer f.OnShutdown()
31
32 m := new(dns.Msg)
33 m.SetQuestion("example.org.", dns.TypeA)
34 rec := dnstest.NewRecorder(&test.ResponseWriter{})
35
36 if _, err := f.ServeDNS(context.TODO(), rec, m); err != nil {
37 t.Fatal("Expected to receive reply, but didn't")
38 }
39 if x := rec.Msg.Answer[0].Header().Name; x != "example.org." {
40 t.Errorf("Expected %s, got %s", "example.org.", x)
41 }
42}
43
44func TestProxyTLSFail(t *testing.T) {
45 // This is an udp/tcp test server, so we shouldn't reach it with TLS.

Callers

nothing calls this directly

Calls 11

CloseMethod · 0.95
NewServerFunction · 0.92
AFunction · 0.92
NewRecorderFunction · 0.92
parseForwardFunction · 0.85
ErrorfMethod · 0.65
ServeDNSMethod · 0.65
FatalMethod · 0.65
WriteMsgMethod · 0.45
OnStartupMethod · 0.45
OnShutdownMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…