Commit f5bfe5c2 authored by Mikio Hara's avatar Mikio Hara

dns/dnsmessage: tweak the error value on nil resource body

Change-Id: I17444d1cc3ce03b6947aaae18d4cecdf9c36193f
Reviewed-on: https://go-review.googlesource.com/47110Reviewed-by: 's avatarIan Gudger <igudger@google.com>
Reviewed-by: 's avatarMatt Layher <mdlayher@gmail.com>
Run-TryBot: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 1f922427
......@@ -80,6 +80,7 @@ var (
errReserved = errors.New("segment prefix is reserved")
errTooManyPtr = errors.New("too many pointers (>10)")
errInvalidPtr = errors.New("invalid pointer")
errNilResouceBody = errors.New("nil resource body")
errResourceLen = errors.New("insufficient data for resource body length")
errSegTooLong = errors.New("segment length too long")
errZeroSegLen = errors.New("zero length segment")
......@@ -281,7 +282,7 @@ type ResourceBody interface {
func (r *Resource) pack(msg []byte, compression map[string]int) ([]byte, error) {
if r.Body == nil {
return msg, &nestedError{"Resource", errors.New("nil resource body")}
return msg, errNilResouceBody
}
oldMsg := msg
r.Header.Type = r.Body.realType()
......
......@@ -535,8 +535,12 @@ func TestBuilder(t *testing.T) {
}
func TestResourcePack(t *testing.T) {
for _, m := range []Message{
for _, tt := range []struct {
m Message
err error
}{
{
Message{
Questions: []Question{
{
Name: mustNewName("."),
......@@ -546,7 +550,10 @@ func TestResourcePack(t *testing.T) {
},
Answers: []Resource{{ResourceHeader{}, nil}},
},
&nestedError{"packing Answer", errNilResouceBody},
},
{
Message{
Questions: []Question{
{
Name: mustNewName("."),
......@@ -556,7 +563,14 @@ func TestResourcePack(t *testing.T) {
},
Authorities: []Resource{{ResourceHeader{}, (*NSResource)(nil)}},
},
&nestedError{"packing Authority",
&nestedError{"ResourceHeader",
&nestedError{"Name", errNonCanonicalName},
},
},
},
{
Message{
Questions: []Question{
{
Name: mustNewName("."),
......@@ -566,9 +580,12 @@ func TestResourcePack(t *testing.T) {
},
Additionals: []Resource{{ResourceHeader{}, nil}},
},
&nestedError{"packing Additional", errNilResouceBody},
},
} {
if _, err := m.Pack(); err == nil {
t.Errorf("should fail: %v", m)
_, err := tt.m.Pack()
if !reflect.DeepEqual(err, tt.err) {
t.Errorf("got %v for %v; want %v", err, tt.m, tt.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