
Previously we had a dependency to the tests package. As the nullreader package is in the pkg directory it should be publicly available. However, having the tests dependency could lead to a transitive dependency to an internal package, if the tests package would import one. Thus, we removed it.
32 lines
572 B
Go
32 lines
572 B
Go
package nullreader
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
const shortTimeout = 100 * time.Millisecond
|
|
|
|
func TestNullReaderDoesNotReturnImmediately(t *testing.T) {
|
|
reader := &NullReader{}
|
|
readerReturned := make(chan bool)
|
|
go func() {
|
|
p := make([]byte, 0, 5)
|
|
_, err := reader.Read(p)
|
|
require.NoError(t, err)
|
|
close(readerReturned)
|
|
}()
|
|
|
|
var received bool
|
|
select {
|
|
case <-readerReturned:
|
|
received = true
|
|
case <-time.After(shortTimeout):
|
|
received = false
|
|
}
|
|
|
|
assert.False(t, received)
|
|
}
|