MCPcopy
hub / github.com/coredns/coredns / TestSpoof

Function TestSpoof

plugin/cache/spoof_test.go:14–40  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestSpoof(t *testing.T) {
15 // Send query for example.org, get reply for example.net; should not be cached.
16 c := New()
17 c.Next = spoofHandler(true)
18
19 req := new(dns.Msg)
20 req.SetQuestion("example.org.", dns.TypeA)
21 rec := dnstest.NewRecorder(&test.ResponseWriter{})
22
23 c.ServeDNS(context.TODO(), rec, req)
24
25 qname := rec.Msg.Question[0].Name
26 if c.pcache.Len() != 0 {
27 t.Errorf("Cached %s, while reply had %s", "example.org.", qname)
28 }
29
30 // qtype
31 c.Next = spoofHandlerType()
32 req.SetQuestion("example.org.", dns.TypeMX)
33
34 c.ServeDNS(context.TODO(), rec, req)
35
36 qtype := rec.Msg.Question[0].Qtype
37 if c.pcache.Len() != 0 {
38 t.Errorf("Cached %s type %d, while reply had %d", "example.org.", dns.TypeMX, qtype)
39 }
40}
41
42func TestResponse(t *testing.T) {
43 // Send query for example.org, get reply for example.net; should not be cached.

Callers

nothing calls this directly

Calls 7

NewRecorderFunction · 0.92
spoofHandlerFunction · 0.85
spoofHandlerTypeFunction · 0.85
NewFunction · 0.70
ServeDNSMethod · 0.65
ErrorfMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…