Skip to content

Commit

Permalink
chore(kit/io): Tests for LimitedReadCloser.
Browse files Browse the repository at this point in the history
  • Loading branch information
brettbuddin committed Jun 16, 2020
1 parent 524c7d1 commit cb8d38d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions kit/io/limited_read_closer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io

import (
"bytes"
"io"
"io/ioutil"
"testing"

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

func TestLimitedReadCloser_Exceeded(t *testing.T) {
b := closer{bytes.NewBufferString("howdy")}
rc := NewLimitedReadCloser(b, 2)

out, err := ioutil.ReadAll(rc)
require.NoError(t, err)
assert.Equal(t, []byte("how"), out)
assert.Equal(t, ErrReadLimitExceeded, rc.Close())
}

func TestLimitedReadCloser_Happy(t *testing.T) {
b := closer{bytes.NewBufferString("ho")}
rc := NewLimitedReadCloser(b, 2)

out, err := ioutil.ReadAll(rc)
require.NoError(t, err)
assert.Equal(t, []byte("ho"), out)
assert.Nil(t, err)
}

type closer struct {
io.Reader
}

func (c closer) Close() error { return nil }

0 comments on commit cb8d38d

Please sign in to comment.