diff options
author | 2017-01-06 09:42:30 +0000 | |
---|---|---|
committer | 2017-01-06 09:42:30 +0000 | |
commit | 53ac25d1c327ea2c2924a2e90b510764be94319e (patch) | |
tree | 8947632ec5bba675818f2a33af0c0787b27416e8 /middleware/erratic/erratic_test.go | |
parent | 9a5e0c64fdbefc401f7476014c21700a5dbed454 (diff) | |
download | coredns-53ac25d1c327ea2c2924a2e90b510764be94319e.tar.gz coredns-53ac25d1c327ea2c2924a2e90b510764be94319e.tar.zst coredns-53ac25d1c327ea2c2924a2e90b510764be94319e.zip |
Add middleware/erratic (#471)
This middleware allows playing with responses. Only one type is
implemented: it allows you to drop queries. I.e. withhold the response
from the client.
Diffstat (limited to 'middleware/erratic/erratic_test.go')
-rw-r--r-- | middleware/erratic/erratic_test.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/middleware/erratic/erratic_test.go b/middleware/erratic/erratic_test.go new file mode 100644 index 000000000..eaf34c39b --- /dev/null +++ b/middleware/erratic/erratic_test.go @@ -0,0 +1,45 @@ +package erratic + +import ( + "testing" + + "github.com/miekg/coredns/middleware/pkg/dnsrecorder" + "github.com/miekg/coredns/middleware/test" + + "github.com/miekg/dns" + "golang.org/x/net/context" +) + +func TestErraticDrop(t *testing.T) { + e := &Erratic{amount: 2} // 50% drops + + tests := []struct { + expectedCode int + expectedErr error + drop bool + }{ + {expectedCode: dns.RcodeSuccess, expectedErr: nil, drop: true}, + {expectedCode: dns.RcodeSuccess, expectedErr: nil, drop: false}, + } + + ctx := context.TODO() + + for i, tc := range tests { + req := new(dns.Msg) + req.SetQuestion("example.org.", dns.TypeA) + + rec := dnsrecorder.New(&test.ResponseWriter{}) + code, err := e.ServeDNS(ctx, rec, req) + + if err != tc.expectedErr { + t.Errorf("Test %d: Expected error %q, but got %q", i, tc.expectedErr, err) + } + if code != int(tc.expectedCode) { + t.Errorf("Test %d: Expected status code %d, but got %d", i, tc.expectedCode, code) + } + + if tc.drop && rec.Msg != nil { + t.Errorf("Test %d: Expected dropped packet, but got %q", i, rec.Msg.Question[0].Name) + } + } +} |