mirror of
https://github.com/coredns/coredns.git
synced 2025-10-29 01:04:15 -04:00
Tc bits (#617)
* middleware/erratic: allow TC bit to be set Add `truncate` as an option. Fixes #593
This commit is contained in:
@@ -39,7 +39,41 @@ func TestErraticDrop(t *testing.T) {
|
||||
}
|
||||
|
||||
if tc.drop && rec.Msg != nil {
|
||||
t.Errorf("Test %d: Expected dropped packet, but got %q", i, rec.Msg.Question[0].Name)
|
||||
t.Errorf("Test %d: Expected dropped message, but got %q", i, rec.Msg.Question[0].Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestErraticTruncate(t *testing.T) {
|
||||
e := &Erratic{truncate: 2} // 50% drops
|
||||
|
||||
tests := []struct {
|
||||
expectedCode int
|
||||
expectedErr error
|
||||
truncate bool
|
||||
}{
|
||||
{expectedCode: dns.RcodeSuccess, expectedErr: nil, truncate: true},
|
||||
{expectedCode: dns.RcodeSuccess, expectedErr: nil, truncate: 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.truncate && !rec.Msg.Truncated {
|
||||
t.Errorf("Test %d: Expected truncated message, but got %q", i, rec.Msg.Question[0].Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user