2019-05-14 16:14:39 -04:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"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")
|
|
|
|
|
|
|
|
_, err := ioutil.ReadAll(r)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
r = strings.NewReader("Test")
|
|
|
|
_, err = ioutil.ReadAll(&LimitedReader{R: r, N: 4})
|
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
r = strings.NewReader("Test")
|
|
|
|
_, err = ioutil.ReadAll(&LimitedReader{R: r, N: 2})
|
|
|
|
assert.Error(t, err, "read exceeds the defined limit")
|
|
|
|
}
|