Skip to content

Commit

Permalink
Add tests for internal/iolimits
Browse files Browse the repository at this point in the history
Signed-off-by: Miloslav Trmač <[email protected]>
  • Loading branch information
mtrmac authored and vrothberg committed Feb 3, 2020
1 parent dd027a4 commit 27e4b20
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions internal/iolimits/iolimits_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package iolimits

import (
"bytes"
"math/rand"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestReadAtMost(t *testing.T) {
for _, c := range []struct {
input, limit int
shouldSucceed bool
}{
{0, 0, true},
{0, 1, true},
{1, 0, false},
{1, 1, true},
{bytes.MinRead*5 - 1, bytes.MinRead * 5, true},
{bytes.MinRead * 5, bytes.MinRead * 5, true},
{bytes.MinRead*5 + 1, bytes.MinRead * 5, false},
} {
input := make([]byte, c.input)
_, err := rand.Read(input)
require.NoError(t, err)
result, err := ReadAtMost(bytes.NewReader(input), c.limit)
if c.shouldSucceed {
assert.NoError(t, err)
assert.Equal(t, result, input)
} else {
assert.Error(t, err)
}
}
}

0 comments on commit 27e4b20

Please sign in to comment.