Commit b68f3049 authored by Mikio Hara's avatar Mikio Hara

dns/dnsmessage: align error messages in test

Change-Id: I008840a981179bb9397735b88155d7476ae76599
Reviewed-on: https://go-review.googlesource.com/101296Reviewed-by: 's avatarIan Gudger <igudger@google.com>
parent d9ff770d
...@@ -73,7 +73,7 @@ func TestQuestionPackUnpack(t *testing.T) { ...@@ -73,7 +73,7 @@ func TestQuestionPackUnpack(t *testing.T) {
} }
buf, err := want.pack(make([]byte, 1, 50), map[string]int{}, 1) buf, err := want.pack(make([]byte, 1, 50), map[string]int{}, 1)
if err != nil { if err != nil {
t.Fatal("Packing failed:", err) t.Fatal("Question.pack() =", err)
} }
var p Parser var p Parser
p.msg = buf p.msg = buf
...@@ -82,13 +82,13 @@ func TestQuestionPackUnpack(t *testing.T) { ...@@ -82,13 +82,13 @@ func TestQuestionPackUnpack(t *testing.T) {
p.off = 1 p.off = 1
got, err := p.Question() got, err := p.Question()
if err != nil { if err != nil {
t.Fatalf("Unpacking failed: %v\n%s", err, string(buf[1:])) t.Fatalf("Parser{%q}.Question() = %v", string(buf[1:]), err)
} }
if p.off != len(buf) { if p.off != len(buf) {
t.Errorf("Unpacked different amount than packed: got n = %d, want = %d", p.off, len(buf)) t.Errorf("unpacked different amount than packed: got = %d, want = %d", p.off, len(buf))
} }
if !reflect.DeepEqual(got, want) { if !reflect.DeepEqual(got, want) {
t.Errorf("Got = %+v, want = %+v", got, want) t.Errorf("got from Parser.Question() = %+v, want = %+v", got, want)
} }
} }
...@@ -108,11 +108,11 @@ func TestName(t *testing.T) { ...@@ -108,11 +108,11 @@ func TestName(t *testing.T) {
for _, test := range tests { for _, test := range tests {
n, err := NewName(test) n, err := NewName(test)
if err != nil { if err != nil {
t.Errorf("Creating name for %q: %v", test, err) t.Errorf("NewName(%q) = %v", test, err)
continue continue
} }
if ns := n.String(); ns != test { if ns := n.String(); ns != test {
t.Errorf("Got %#v.String() = %q, want = %q", n, ns, test) t.Errorf("got %#v.String() = %q, want = %q", n, ns, test)
continue continue
} }
} }
...@@ -140,7 +140,7 @@ func TestNamePackUnpack(t *testing.T) { ...@@ -140,7 +140,7 @@ func TestNamePackUnpack(t *testing.T) {
want := mustNewName(test.want) want := mustNewName(test.want)
buf, err := in.pack(make([]byte, 0, 30), map[string]int{}, 0) buf, err := in.pack(make([]byte, 0, 30), map[string]int{}, 0)
if err != test.err { if err != test.err {
t.Errorf("Packing of %q: got err = %v, want err = %v", test.in, err, test.err) t.Errorf("got %q.pack() = %v, want = %v", test.in, err, test.err)
continue continue
} }
if test.err != nil { if test.err != nil {
...@@ -149,19 +149,19 @@ func TestNamePackUnpack(t *testing.T) { ...@@ -149,19 +149,19 @@ func TestNamePackUnpack(t *testing.T) {
var got Name var got Name
n, err := got.unpack(buf, 0) n, err := got.unpack(buf, 0)
if err != nil { if err != nil {
t.Errorf("Unpacking for %q failed: %v", test.in, err) t.Errorf("%q.unpack() = %v", test.in, err)
continue continue
} }
if n != len(buf) { if n != len(buf) {
t.Errorf( t.Errorf(
"Unpacked different amount than packed for %q: got n = %d, want = %d", "unpacked different amount than packed for %q: got = %d, want = %d",
test.in, test.in,
n, n,
len(buf), len(buf),
) )
} }
if got != want { if got != want {
t.Errorf("Unpacking packing of %q: got = %#v, want = %#v", test.in, got, want) t.Errorf("unpacking packing of %q: got = %#v, want = %#v", test.in, got, want)
} }
} }
} }
...@@ -171,20 +171,20 @@ func TestIncompressibleName(t *testing.T) { ...@@ -171,20 +171,20 @@ func TestIncompressibleName(t *testing.T) {
compression := map[string]int{} compression := map[string]int{}
buf, err := name.pack(make([]byte, 0, 100), compression, 0) buf, err := name.pack(make([]byte, 0, 100), compression, 0)
if err != nil { if err != nil {
t.Fatal("First packing failed:", err) t.Fatal("first Name.pack() =", err)
} }
buf, err = name.pack(buf, compression, 0) buf, err = name.pack(buf, compression, 0)
if err != nil { if err != nil {
t.Fatal("Second packing failed:", err) t.Fatal("second Name.pack() =", err)
} }
var n1 Name var n1 Name
off, err := n1.unpackCompressed(buf, 0, false /* allowCompression */) off, err := n1.unpackCompressed(buf, 0, false /* allowCompression */)
if err != nil { if err != nil {
t.Fatal("Unpacking incompressible name without pointers failed:", err) t.Fatal("unpacking incompressible name without pointers failed:", err)
} }
var n2 Name var n2 Name
if _, err := n2.unpackCompressed(buf, off, false /* allowCompression */); err != errCompressedSRV { if _, err := n2.unpackCompressed(buf, off, false /* allowCompression */); err != errCompressedSRV {
t.Errorf("Unpacking compressed incompressible name with pointers: got err = %v, want = %v", err, errCompressedSRV) t.Errorf("unpacking compressed incompressible name with pointers: got %v, want = %v", err, errCompressedSRV)
} }
} }
...@@ -207,7 +207,7 @@ func TestHeaderUnpackError(t *testing.T) { ...@@ -207,7 +207,7 @@ func TestHeaderUnpackError(t *testing.T) {
for _, want := range wants { for _, want := range wants {
n, err := h.unpack(buf, 0) n, err := h.unpack(buf, 0)
if n != 0 || !checkErrorPrefix(err, want) { if n != 0 || !checkErrorPrefix(err, want) {
t.Errorf("got h.unpack([%d]byte, 0) = %d, %v, want = 0, %s", len(buf), n, err, want) t.Errorf("got header.unpack([%d]byte, 0) = %d, %v, want = 0, %s", len(buf), n, err, want)
} }
buf = append(buf, 0, 0) buf = append(buf, 0, 0)
} }
...@@ -219,7 +219,7 @@ func TestParserStart(t *testing.T) { ...@@ -219,7 +219,7 @@ func TestParserStart(t *testing.T) {
for i := 0; i <= 1; i++ { for i := 0; i <= 1; i++ {
_, err := p.Start([]byte{}) _, err := p.Start([]byte{})
if !checkErrorPrefix(err, want) { if !checkErrorPrefix(err, want) {
t.Errorf("got p.Start(nil) = _, %v, want = _, %s", err, want) t.Errorf("got Parser.Start(nil) = _, %v, want = _, %s", err, want)
} }
} }
} }
...@@ -242,7 +242,7 @@ func TestResourceNotStarted(t *testing.T) { ...@@ -242,7 +242,7 @@ func TestResourceNotStarted(t *testing.T) {
for _, test := range tests { for _, test := range tests {
if err := test.fn(&Parser{}); err != ErrNotStarted { if err := test.fn(&Parser{}); err != ErrNotStarted {
t.Errorf("got _, %v = p.%s(), want = _, %v", err, test.name, ErrNotStarted) t.Errorf("got Parser.%s() = _ , %v, want = _, %v", test.name, err, ErrNotStarted)
} }
} }
} }
...@@ -266,15 +266,15 @@ func TestDNSPackUnpack(t *testing.T) { ...@@ -266,15 +266,15 @@ func TestDNSPackUnpack(t *testing.T) {
for i, want := range wants { for i, want := range wants {
b, err := want.Pack() b, err := want.Pack()
if err != nil { if err != nil {
t.Fatalf("%d: packing failed: %v", i, err) t.Fatalf("%d: Message.Pack() = %v", i, err)
} }
var got Message var got Message
err = got.Unpack(b) err = got.Unpack(b)
if err != nil { if err != nil {
t.Fatalf("%d: unpacking failed: %v", i, err) t.Fatalf("%d: Message.Unapck() = %v", i, err)
} }
if !reflect.DeepEqual(got, want) { if !reflect.DeepEqual(got, want) {
t.Errorf("%d: got = %+v, want = %+v", i, &got, &want) t.Errorf("%d: Message.Pack/Unpack() roundtrip: got = %+v, want = %+v", i, &got, &want)
} }
} }
} }
...@@ -299,16 +299,16 @@ func TestDNSAppendPackUnpack(t *testing.T) { ...@@ -299,16 +299,16 @@ func TestDNSAppendPackUnpack(t *testing.T) {
b := make([]byte, 2, 514) b := make([]byte, 2, 514)
b, err := want.AppendPack(b) b, err := want.AppendPack(b)
if err != nil { if err != nil {
t.Fatalf("%d: packing failed: %v", i, err) t.Fatalf("%d: Message.AppendPack() = %v", i, err)
} }
b = b[2:] b = b[2:]
var got Message var got Message
err = got.Unpack(b) err = got.Unpack(b)
if err != nil { if err != nil {
t.Fatalf("%d: unpacking failed: %v", i, err) t.Fatalf("%d: Message.Unapck() = %v", i, err)
} }
if !reflect.DeepEqual(got, want) { if !reflect.DeepEqual(got, want) {
t.Errorf("%d: got = %+v, want = %+v", i, &got, &want) t.Errorf("%d: Message.AppendPack/Unpack() roundtrip: got = %+v, want = %+v", i, &got, &want)
} }
} }
} }
...@@ -317,11 +317,11 @@ func TestSkipAll(t *testing.T) { ...@@ -317,11 +317,11 @@ func TestSkipAll(t *testing.T) {
msg := largeTestMsg() msg := largeTestMsg()
buf, err := msg.Pack() buf, err := msg.Pack()
if err != nil { if err != nil {
t.Fatal("Packing large test message:", err) t.Fatal("Message.Pack() =", err)
} }
var p Parser var p Parser
if _, err := p.Start(buf); err != nil { if _, err := p.Start(buf); err != nil {
t.Fatal(err) t.Fatal("Parser.Start(non-nil) =", err)
} }
tests := []struct { tests := []struct {
...@@ -336,7 +336,7 @@ func TestSkipAll(t *testing.T) { ...@@ -336,7 +336,7 @@ func TestSkipAll(t *testing.T) {
for _, test := range tests { for _, test := range tests {
for i := 1; i <= 3; i++ { for i := 1; i <= 3; i++ {
if err := test.f(); err != nil { if err := test.f(); err != nil {
t.Errorf("Call #%d to %s(): %v", i, test.name, err) t.Errorf("%d: Parser.%s() = %v", i, test.name, err)
} }
} }
} }
...@@ -347,11 +347,11 @@ func TestSkipEach(t *testing.T) { ...@@ -347,11 +347,11 @@ func TestSkipEach(t *testing.T) {
buf, err := msg.Pack() buf, err := msg.Pack()
if err != nil { if err != nil {
t.Fatal("Packing test message:", err) t.Fatal("Message.Pack() =", err)
} }
var p Parser var p Parser
if _, err := p.Start(buf); err != nil { if _, err := p.Start(buf); err != nil {
t.Fatal(err) t.Fatal("Parser.Start(non-nil) =", err)
} }
tests := []struct { tests := []struct {
...@@ -365,10 +365,10 @@ func TestSkipEach(t *testing.T) { ...@@ -365,10 +365,10 @@ func TestSkipEach(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
if err := test.f(); err != nil { if err := test.f(); err != nil {
t.Errorf("First call: got %s() = %v, want = %v", test.name, err, nil) t.Errorf("first Parser.%s() = %v, want = nil", test.name, err)
} }
if err := test.f(); err != ErrSectionDone { if err := test.f(); err != ErrSectionDone {
t.Errorf("Second call: got %s() = %v, want = %v", test.name, err, ErrSectionDone) t.Errorf("second Parser.%s() = %v, want = %v", test.name, err, ErrSectionDone)
} }
} }
} }
...@@ -378,11 +378,11 @@ func TestSkipAfterRead(t *testing.T) { ...@@ -378,11 +378,11 @@ func TestSkipAfterRead(t *testing.T) {
buf, err := msg.Pack() buf, err := msg.Pack()
if err != nil { if err != nil {
t.Fatal("Packing test message:", err) t.Fatal("Message.Pack() =", err)
} }
var p Parser var p Parser
if _, err := p.Start(buf); err != nil { if _, err := p.Start(buf); err != nil {
t.Fatal(err) t.Fatal("Parser.Srart(non-nil) =", err)
} }
tests := []struct { tests := []struct {
...@@ -397,10 +397,10 @@ func TestSkipAfterRead(t *testing.T) { ...@@ -397,10 +397,10 @@ func TestSkipAfterRead(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
if err := test.read(); err != nil { if err := test.read(); err != nil {
t.Errorf("Got %s() = _, %v, want = _, %v", test.name, err, nil) t.Errorf("got Parser.%s() = _, %v, want = _, nil", test.name, err)
} }
if err := test.skip(); err != ErrSectionDone { if err := test.skip(); err != ErrSectionDone {
t.Errorf("Got Skip%s() = %v, want = %v", test.name, err, ErrSectionDone) t.Errorf("got Parser.Skip%s() = %v, want = %v", test.name, err, ErrSectionDone)
} }
} }
} }
...@@ -419,7 +419,7 @@ func TestSkipNotStarted(t *testing.T) { ...@@ -419,7 +419,7 @@ func TestSkipNotStarted(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
if err := test.f(); err != ErrNotStarted { if err := test.f(); err != ErrNotStarted {
t.Errorf("Got %s() = %v, want = %v", test.name, err, ErrNotStarted) t.Errorf("got Parser.%s() = %v, want = %v", test.name, err, ErrNotStarted)
} }
} }
} }
...@@ -463,7 +463,7 @@ func TestTooManyRecords(t *testing.T) { ...@@ -463,7 +463,7 @@ func TestTooManyRecords(t *testing.T) {
for _, test := range tests { for _, test := range tests {
if _, got := test.msg.Pack(); got != test.want { if _, got := test.msg.Pack(); got != test.want {
t.Errorf("Packing %d %s: got = %v, want = %v", recs, test.name, got, test.want) t.Errorf("got Message.Pack() for %d %s = %v, want = %v", recs, test.name, got, test.want)
} }
} }
} }
...@@ -487,30 +487,30 @@ func TestVeryLongTxt(t *testing.T) { ...@@ -487,30 +487,30 @@ func TestVeryLongTxt(t *testing.T) {
} }
buf, err := want.pack(make([]byte, 0, 8000), map[string]int{}, 0) buf, err := want.pack(make([]byte, 0, 8000), map[string]int{}, 0)
if err != nil { if err != nil {
t.Fatal("Packing failed:", err) t.Fatal("Resource.pack() =", err)
} }
var got Resource var got Resource
off, err := got.Header.unpack(buf, 0) off, err := got.Header.unpack(buf, 0)
if err != nil { if err != nil {
t.Fatal("Unpacking ResourceHeader failed:", err) t.Fatal("ResourceHeader.unpack() =", err)
} }
body, n, err := unpackResourceBody(buf, off, got.Header) body, n, err := unpackResourceBody(buf, off, got.Header)
if err != nil { if err != nil {
t.Fatal("Unpacking failed:", err) t.Fatal("unpackResourceBody() =", err)
} }
got.Body = body got.Body = body
if n != len(buf) { if n != len(buf) {
t.Errorf("Unpacked different amount than packed: got n = %d, want = %d", n, len(buf)) t.Errorf("unpacked different amount than packed: got = %d, want = %d", n, len(buf))
} }
if !reflect.DeepEqual(got, want) { if !reflect.DeepEqual(got, want) {
t.Errorf("Got = %#v, want = %#v", got, want) t.Errorf("Resource.pack/unpack() roundtrip: got = %#v, want = %#v", got, want)
} }
} }
func TestTooLongTxt(t *testing.T) { func TestTooLongTxt(t *testing.T) {
rb := TXTResource{[]string{strings.Repeat(".", 256)}} rb := TXTResource{[]string{strings.Repeat(".", 256)}}
if _, err := rb.pack(make([]byte, 0, 8000), map[string]int{}, 0); err != errStringTooLong { if _, err := rb.pack(make([]byte, 0, 8000), map[string]int{}, 0); err != errStringTooLong {
t.Errorf("Packing TXTRecord with 256 character string: got err = %v, want = %v", err, errStringTooLong) t.Errorf("packing TXTResource with 256 character string: got err = %v, want = %v", err, errStringTooLong)
} }
} }
...@@ -524,13 +524,13 @@ func TestStartAppends(t *testing.T) { ...@@ -524,13 +524,13 @@ func TestStartAppends(t *testing.T) {
buf, err := b.Finish() buf, err := b.Finish()
if err != nil { if err != nil {
t.Fatal("Building failed:", err) t.Fatal("Builder.Finish() =", err)
} }
if got, want := len(buf), headerLen+2; got != want { if got, want := len(buf), headerLen+2; got != want {
t.Errorf("Got len(buf} = %d, want = %d", got, want) t.Errorf("got len(buf) = %d, want = %d", got, want)
} }
if string(buf[:2]) != string(wantBuf) { if string(buf[:2]) != string(wantBuf) {
t.Errorf("Original data not preserved, got = %v, want = %v", buf[:2], wantBuf) t.Errorf("original data not preserved, got = %#v, want = %#v", buf[:2], wantBuf)
} }
} }
...@@ -557,7 +557,7 @@ func TestStartError(t *testing.T) { ...@@ -557,7 +557,7 @@ func TestStartError(t *testing.T) {
for _, env := range envs { for _, env := range envs {
for _, test := range tests { for _, test := range tests {
if got := test.fn(env.fn()); got != env.want { if got := test.fn(env.fn()); got != env.want {
t.Errorf("got Builder{%s}.Start%s = %v, want = %v", env.name, test.name, got, env.want) t.Errorf("got Builder{%s}.Start%s() = %v, want = %v", env.name, test.name, got, env.want)
} }
} }
} }
...@@ -594,7 +594,7 @@ func TestBuilderResourceError(t *testing.T) { ...@@ -594,7 +594,7 @@ func TestBuilderResourceError(t *testing.T) {
for _, env := range envs { for _, env := range envs {
for _, test := range tests { for _, test := range tests {
if got := test.fn(env.fn()); got != env.want { if got := test.fn(env.fn()); got != env.want {
t.Errorf("got Builder{%s}.%s = %v, want = %v", env.name, test.name, got, env.want) t.Errorf("got Builder{%s}.%s() = %v, want = %v", env.name, test.name, got, env.want)
} }
} }
} }
...@@ -604,7 +604,7 @@ func TestFinishError(t *testing.T) { ...@@ -604,7 +604,7 @@ func TestFinishError(t *testing.T) {
var b Builder var b Builder
want := ErrNotStarted want := ErrNotStarted
if _, got := b.Finish(); got != want { if _, got := b.Finish(); got != want {
t.Errorf("got Builder{}.Finish() = %v, want = %v", got, want) t.Errorf("got Builder.Finish() = %v, want = %v", got, want)
} }
} }
...@@ -612,76 +612,76 @@ func TestBuilder(t *testing.T) { ...@@ -612,76 +612,76 @@ func TestBuilder(t *testing.T) {
msg := largeTestMsg() msg := largeTestMsg()
want, err := msg.Pack() want, err := msg.Pack()
if err != nil { if err != nil {
t.Fatal("Packing without builder:", err) t.Fatal("Message.Pack() =", err)
} }
b := NewBuilder(nil, msg.Header) b := NewBuilder(nil, msg.Header)
b.EnableCompression() b.EnableCompression()
if err := b.StartQuestions(); err != nil { if err := b.StartQuestions(); err != nil {
t.Fatal("b.StartQuestions():", err) t.Fatal("Builder.StartQuestions() =", err)
} }
for _, q := range msg.Questions { for _, q := range msg.Questions {
if err := b.Question(q); err != nil { if err := b.Question(q); err != nil {
t.Fatalf("b.Question(%#v): %v", q, err) t.Fatalf("Builder.Question(%#v) = %v", q, err)
} }
} }
if err := b.StartAnswers(); err != nil { if err := b.StartAnswers(); err != nil {
t.Fatal("b.StartAnswers():", err) t.Fatal("Builder.StartAnswers() =", err)
} }
for _, a := range msg.Answers { for _, a := range msg.Answers {
switch a.Header.Type { switch a.Header.Type {
case TypeA: case TypeA:
if err := b.AResource(a.Header, *a.Body.(*AResource)); err != nil { if err := b.AResource(a.Header, *a.Body.(*AResource)); err != nil {
t.Fatalf("b.AResource(%#v): %v", a, err) t.Fatalf("Builder.AResource(%#v) = %v", a, err)
} }
case TypeNS: case TypeNS:
if err := b.NSResource(a.Header, *a.Body.(*NSResource)); err != nil { if err := b.NSResource(a.Header, *a.Body.(*NSResource)); err != nil {
t.Fatalf("b.NSResource(%#v): %v", a, err) t.Fatalf("Builder.NSResource(%#v) = %v", a, err)
} }
case TypeCNAME: case TypeCNAME:
if err := b.CNAMEResource(a.Header, *a.Body.(*CNAMEResource)); err != nil { if err := b.CNAMEResource(a.Header, *a.Body.(*CNAMEResource)); err != nil {
t.Fatalf("b.CNAMEResource(%#v): %v", a, err) t.Fatalf("Builder.CNAMEResource(%#v) = %v", a, err)
} }
case TypeSOA: case TypeSOA:
if err := b.SOAResource(a.Header, *a.Body.(*SOAResource)); err != nil { if err := b.SOAResource(a.Header, *a.Body.(*SOAResource)); err != nil {
t.Fatalf("b.SOAResource(%#v): %v", a, err) t.Fatalf("Builder.SOAResource(%#v) = %v", a, err)
} }
case TypePTR: case TypePTR:
if err := b.PTRResource(a.Header, *a.Body.(*PTRResource)); err != nil { if err := b.PTRResource(a.Header, *a.Body.(*PTRResource)); err != nil {
t.Fatalf("b.PTRResource(%#v): %v", a, err) t.Fatalf("Builder.PTRResource(%#v) = %v", a, err)
} }
case TypeMX: case TypeMX:
if err := b.MXResource(a.Header, *a.Body.(*MXResource)); err != nil { if err := b.MXResource(a.Header, *a.Body.(*MXResource)); err != nil {
t.Fatalf("b.MXResource(%#v): %v", a, err) t.Fatalf("Builder.MXResource(%#v) = %v", a, err)
} }
case TypeTXT: case TypeTXT:
if err := b.TXTResource(a.Header, *a.Body.(*TXTResource)); err != nil { if err := b.TXTResource(a.Header, *a.Body.(*TXTResource)); err != nil {
t.Fatalf("b.TXTResource(%#v): %v", a, err) t.Fatalf("Builder.TXTResource(%#v) = %v", a, err)
} }
case TypeAAAA: case TypeAAAA:
if err := b.AAAAResource(a.Header, *a.Body.(*AAAAResource)); err != nil { if err := b.AAAAResource(a.Header, *a.Body.(*AAAAResource)); err != nil {
t.Fatalf("b.AAAAResource(%#v): %v", a, err) t.Fatalf("Builder.AAAAResource(%#v) = %v", a, err)
} }
case TypeSRV: case TypeSRV:
if err := b.SRVResource(a.Header, *a.Body.(*SRVResource)); err != nil { if err := b.SRVResource(a.Header, *a.Body.(*SRVResource)); err != nil {
t.Fatalf("b.SRVResource(%#v): %v", a, err) t.Fatalf("Builder.SRVResource(%#v) = %v", a, err)
} }
} }
} }
if err := b.StartAuthorities(); err != nil { if err := b.StartAuthorities(); err != nil {
t.Fatal("b.StartAuthorities():", err) t.Fatal("Builder.StartAuthorities() =", err)
} }
for _, a := range msg.Authorities { for _, a := range msg.Authorities {
if err := b.NSResource(a.Header, *a.Body.(*NSResource)); err != nil { if err := b.NSResource(a.Header, *a.Body.(*NSResource)); err != nil {
t.Fatalf("b.NSResource(%#v): %v", a, err) t.Fatalf("Builder.NSResource(%#v) = %v", a, err)
} }
} }
if err := b.StartAdditionals(); err != nil { if err := b.StartAdditionals(); err != nil {
t.Fatal("b.StartAdditionals():", err) t.Fatal("Builder.StartAdditionals() =", err)
} }
for _, a := range msg.Additionals { for _, a := range msg.Additionals {
switch a.Body.(type) { switch a.Body.(type) {
...@@ -698,10 +698,10 @@ func TestBuilder(t *testing.T) { ...@@ -698,10 +698,10 @@ func TestBuilder(t *testing.T) {
got, err := b.Finish() got, err := b.Finish()
if err != nil { if err != nil {
t.Fatal("b.Finish():", err) t.Fatal("Builder.Finish() =", err)
} }
if !bytes.Equal(got, want) { if !bytes.Equal(got, want) {
t.Fatalf("Got from Builder: %#v\nwant = %#v", got, want) t.Fatalf("got from Builder.Finish() = %#v\nwant = %#v", got, want)
} }
} }
...@@ -756,7 +756,7 @@ func TestResourcePack(t *testing.T) { ...@@ -756,7 +756,7 @@ func TestResourcePack(t *testing.T) {
} { } {
_, err := tt.m.Pack() _, err := tt.m.Pack()
if !reflect.DeepEqual(err, tt.err) { if !reflect.DeepEqual(err, tt.err) {
t.Errorf("got %v for %v; want %v", err, tt.m, tt.err) t.Errorf("got Message{%v}.Pack() = %v, want %v", tt.m, err, tt.err)
} }
} }
} }
...@@ -945,7 +945,7 @@ func benchmarkParsingSetup() ([]byte, error) { ...@@ -945,7 +945,7 @@ func benchmarkParsingSetup() ([]byte, error) {
buf, err := msg.Pack() buf, err := msg.Pack()
if err != nil { if err != nil {
return nil, fmt.Errorf("msg.Pack(): %v", err) return nil, fmt.Errorf("Message.Pack() = %v", err)
} }
return buf, nil return buf, nil
} }
...@@ -953,7 +953,7 @@ func benchmarkParsingSetup() ([]byte, error) { ...@@ -953,7 +953,7 @@ func benchmarkParsingSetup() ([]byte, error) {
func benchmarkParsing(tb testing.TB, buf []byte) { func benchmarkParsing(tb testing.TB, buf []byte) {
var p Parser var p Parser
if _, err := p.Start(buf); err != nil { if _, err := p.Start(buf); err != nil {
tb.Fatal("p.Start(buf):", err) tb.Fatal("Parser.Start(non-nil) =", err)
} }
for { for {
...@@ -962,7 +962,7 @@ func benchmarkParsing(tb testing.TB, buf []byte) { ...@@ -962,7 +962,7 @@ func benchmarkParsing(tb testing.TB, buf []byte) {
break break
} }
if err != nil { if err != nil {
tb.Fatal("p.Question():", err) tb.Fatal("Parser.Question() =", err)
} }
} }
...@@ -972,32 +972,32 @@ func benchmarkParsing(tb testing.TB, buf []byte) { ...@@ -972,32 +972,32 @@ func benchmarkParsing(tb testing.TB, buf []byte) {
break break
} }
if err != nil { if err != nil {
panic(err) tb.Fatal("Parser.AnswerHeader() =", err)
} }
switch h.Type { switch h.Type {
case TypeA: case TypeA:
if _, err := p.AResource(); err != nil { if _, err := p.AResource(); err != nil {
tb.Fatal("p.AResource():", err) tb.Fatal("Parser.AResource() =", err)
} }
case TypeAAAA: case TypeAAAA:
if _, err := p.AAAAResource(); err != nil { if _, err := p.AAAAResource(); err != nil {
tb.Fatal("p.AAAAResource():", err) tb.Fatal("Parser.AAAAResource() =", err)
} }
case TypeCNAME: case TypeCNAME:
if _, err := p.CNAMEResource(); err != nil { if _, err := p.CNAMEResource(); err != nil {
tb.Fatal("p.CNAMEResource():", err) tb.Fatal("Parser.CNAMEResource() =", err)
} }
case TypeNS: case TypeNS:
if _, err := p.NSResource(); err != nil { if _, err := p.NSResource(); err != nil {
tb.Fatal("p.NSResource():", err) tb.Fatal("Parser.NSResource() =", err)
} }
case TypeOPT: case TypeOPT:
if _, err := p.OPTResource(); err != nil { if _, err := p.OPTResource(); err != nil {
tb.Fatal("Parser.OPTResource() =", err) tb.Fatal("Parser.OPTResource() =", err)
} }
default: default:
tb.Fatalf("unknown type: %T", h) tb.Fatalf("got unknown type: %T", h)
} }
} }
} }
...@@ -1021,7 +1021,7 @@ func TestParsingAllocs(t *testing.T) { ...@@ -1021,7 +1021,7 @@ func TestParsingAllocs(t *testing.T) {
} }
if allocs := testing.AllocsPerRun(100, func() { benchmarkParsing(t, buf) }); allocs > 0.5 { if allocs := testing.AllocsPerRun(100, func() { benchmarkParsing(t, buf) }); allocs > 0.5 {
t.Errorf("Allocations during parsing: got = %f, want ~0", allocs) t.Errorf("allocations during parsing: got = %f, want ~0", allocs)
} }
} }
...@@ -1035,7 +1035,7 @@ func benchmarkBuilding(tb testing.TB, name Name, buf []byte) { ...@@ -1035,7 +1035,7 @@ func benchmarkBuilding(tb testing.TB, name Name, buf []byte) {
bld := NewBuilder(buf, Header{Response: true, Authoritative: true}) bld := NewBuilder(buf, Header{Response: true, Authoritative: true})
if err := bld.StartQuestions(); err != nil { if err := bld.StartQuestions(); err != nil {
tb.Fatal("bld.StartQuestions():", err) tb.Fatal("Builder.StartQuestions() =", err)
} }
q := Question{ q := Question{
Name: name, Name: name,
...@@ -1043,7 +1043,7 @@ func benchmarkBuilding(tb testing.TB, name Name, buf []byte) { ...@@ -1043,7 +1043,7 @@ func benchmarkBuilding(tb testing.TB, name Name, buf []byte) {
Class: ClassINET, Class: ClassINET,
} }
if err := bld.Question(q); err != nil { if err := bld.Question(q); err != nil {
tb.Fatalf("bld.Question(%+v): %v", q, err) tb.Fatalf("Builder.Question(%+v) = %v", q, err)
} }
hdr := ResourceHeader{ hdr := ResourceHeader{
...@@ -1051,27 +1051,27 @@ func benchmarkBuilding(tb testing.TB, name Name, buf []byte) { ...@@ -1051,27 +1051,27 @@ func benchmarkBuilding(tb testing.TB, name Name, buf []byte) {
Class: ClassINET, Class: ClassINET,
} }
if err := bld.StartAnswers(); err != nil { if err := bld.StartAnswers(); err != nil {
tb.Fatal("bld.StartQuestions():", err) tb.Fatal("Builder.StartQuestions() =", err)
} }
ar := AResource{[4]byte{}} ar := AResource{[4]byte{}}
if err := bld.AResource(hdr, ar); err != nil { if err := bld.AResource(hdr, ar); err != nil {
tb.Fatalf("bld.AResource(%+v, %+v): %v", hdr, ar, err) tb.Fatalf("Builder.AResource(%+v, %+v) = %v", hdr, ar, err)
} }
aaar := AAAAResource{[16]byte{}} aaar := AAAAResource{[16]byte{}}
if err := bld.AAAAResource(hdr, aaar); err != nil { if err := bld.AAAAResource(hdr, aaar); err != nil {
tb.Fatalf("bld.AAAAResource(%+v, %+v): %v", hdr, aaar, err) tb.Fatalf("Builder.AAAAResource(%+v, %+v) = %v", hdr, aaar, err)
} }
cnr := CNAMEResource{name} cnr := CNAMEResource{name}
if err := bld.CNAMEResource(hdr, cnr); err != nil { if err := bld.CNAMEResource(hdr, cnr); err != nil {
tb.Fatalf("bld.CNAMEResource(%+v, %+v): %v", hdr, cnr, err) tb.Fatalf("Builder.CNAMEResource(%+v, %+v) = %v", hdr, cnr, err)
} }
nsr := NSResource{name} nsr := NSResource{name}
if err := bld.NSResource(hdr, nsr); err != nil { if err := bld.NSResource(hdr, nsr); err != nil {
tb.Fatalf("bld.NSResource(%+v, %+v): %v", hdr, nsr, err) tb.Fatalf("Builder.NSResource(%+v, %+v) = %v", hdr, nsr, err)
} }
extrc := 0xfe0 | RCodeNotImplemented extrc := 0xfe0 | RCodeNotImplemented
...@@ -1084,7 +1084,7 @@ func benchmarkBuilding(tb testing.TB, name Name, buf []byte) { ...@@ -1084,7 +1084,7 @@ func benchmarkBuilding(tb testing.TB, name Name, buf []byte) {
} }
if _, err := bld.Finish(); err != nil { if _, err := bld.Finish(); err != nil {
tb.Fatal("bld.Finish():", err) tb.Fatal("Builder.Finish() =", err)
} }
} }
...@@ -1099,7 +1099,7 @@ func BenchmarkBuilding(b *testing.B) { ...@@ -1099,7 +1099,7 @@ func BenchmarkBuilding(b *testing.B) {
func TestBuildingAllocs(t *testing.T) { func TestBuildingAllocs(t *testing.T) {
name, buf := benchmarkBuildingSetup() name, buf := benchmarkBuildingSetup()
if allocs := testing.AllocsPerRun(100, func() { benchmarkBuilding(t, name, buf) }); allocs > 0.5 { if allocs := testing.AllocsPerRun(100, func() { benchmarkBuilding(t, name, buf) }); allocs > 0.5 {
t.Errorf("Allocations during building: got = %f, want ~0", allocs) t.Errorf("allocations during building: got = %f, want ~0", allocs)
} }
} }
...@@ -1154,7 +1154,7 @@ func BenchmarkPack(b *testing.B) { ...@@ -1154,7 +1154,7 @@ func BenchmarkPack(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
if _, err := msg.Pack(); err != nil { if _, err := msg.Pack(); err != nil {
b.Fatal(err) b.Fatal("Message.Pack() =", err)
} }
} }
} }
...@@ -1167,7 +1167,7 @@ func BenchmarkAppendPack(b *testing.B) { ...@@ -1167,7 +1167,7 @@ func BenchmarkAppendPack(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
if _, err := msg.AppendPack(buf[:0]); err != nil { if _, err := msg.AppendPack(buf[:0]); err != nil {
b.Fatal(err) b.Fatal("Message.AppendPack() = ", err)
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment