2019-05-14 16:14:39 -04:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
2022-02-25 08:37:07 -05:00
|
|
|
"io"
|
2019-05-14 16:14:39 -04:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/assert"
|
2019-05-14 16:14:39 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestLimitReaderReadAll(t *testing.T) {
|
|
|
|
r := strings.NewReader("Reader")
|
|
|
|
|
2022-02-25 08:37:07 -05:00
|
|
|
_, err := io.ReadAll(r)
|
2019-05-14 16:14:39 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
r = strings.NewReader("Test")
|
2022-02-25 08:37:07 -05:00
|
|
|
_, err = io.ReadAll(&LimitedReader{R: r, N: 4})
|
2019-05-14 16:14:39 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
r = strings.NewReader("Test")
|
2022-02-25 08:37:07 -05:00
|
|
|
_, err = io.ReadAll(&LimitedReader{R: r, N: 2})
|
2019-05-14 16:14:39 -04:00
|
|
|
assert.Error(t, err, "read exceeds the defined limit")
|
|
|
|
}
|