Skip to content

Commit

Permalink
Complete test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rasky committed Sep 14, 2015
1 parent 6d9b137 commit 0c28d85
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion xdr2/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ func (d *Decoder) decodeStruct(v reflect.Value) (int, error) {
hasopt, n2, err := d.DecodeBool()
n += n2
if err != nil {
return n2, err
return n, err
}
if !hasopt {
continue
Expand Down
3 changes: 3 additions & 0 deletions xdr2/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@ func TestUnmarshal(t *testing.T) {
{[]byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00},
optionalDataStruct{1, &optionalDataStruct{2, nil}},
16, nil},
{[]byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00},
optionalDataStruct{1, nil},
7, &UnmarshalError{ErrorCode: ErrIO}},
{[]byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00},
invalidOptionalDataStruct{},
0, &UnmarshalError{ErrorCode: ErrBadOptional}},
Expand Down
2 changes: 1 addition & 1 deletion xdr2/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ func (enc *Encoder) encodeStruct(v reflect.Value) (int, error) {
n2, err := enc.EncodeBool(hasopt)
n += n2
if err != nil {
return n2, err
return n, err
}
if !hasopt {
continue
Expand Down
6 changes: 5 additions & 1 deletion xdr2/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,12 @@ func TestMarshal(t *testing.T) {
{optionalDataStruct{1, &optionalDataStruct{2, nil}},
[]byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00},
16, nil},
{optionalDataStruct{1, nil},
[]uint8{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00},
7, &MarshalError{ErrorCode: ErrIO}},
{invalidOptionalDataStruct{1},
[]byte{}, 0, &MarshalError{ErrorCode: ErrBadOptional}},
[]byte{},
0, &MarshalError{ErrorCode: ErrBadOptional}},

// Expected errors
{nilInterface, []byte{}, 0, &MarshalError{ErrorCode: ErrNilInterface}},
Expand Down

0 comments on commit 0c28d85

Please sign in to comment.