Skip to content

Commit

Permalink
test(dec.int): add errReader case
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Nov 2, 2021
1 parent 7c45269 commit d9c6cb5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
21 changes: 21 additions & 0 deletions dec_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,24 @@ func TestDecoder_uint_sizes(t *testing.T) {
require.Equal(t, uint(69315063), v)
}
}

func TestDecoder_Int(t *testing.T) {
r := errReader{}
get := func() *Decoder {
return &Decoder{
buf: []byte{'1', '2'},
tail: 2,
reader: errReader{},
}
}
t.Run("32", func(t *testing.T) {
d := get()
_, err := d.Int32()
require.ErrorIs(t, err, r.Err())
})
t.Run("64", func(t *testing.T) {
d := get()
_, err := d.Int64()
require.ErrorIs(t, err, r.Err())
})
}
6 changes: 5 additions & 1 deletion dec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ func TestDecoderBig(t *testing.T) {

type errReader struct{}

func (errReader) Err() error {
return io.ErrNoProgress
}

func (e errReader) Read(p []byte) (n int, err error) {
return 0, io.ErrNoProgress
return 0, e.Err()
}

0 comments on commit d9c6cb5

Please sign in to comment.