github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/blobs/blob_io_test.go (about)

     1  package blobs
     2  
     3  import (
     4  	"io"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func TestEmptyRead(t *testing.T) {
    12  	blobCh := make(chan Blob)
    13  	bcr := NewBlobChannelReader(blobCh)
    14  	close(blobCh)
    15  	var buf [1]byte
    16  	n, err := bcr.Read(buf[:])
    17  	assert.Equal(t, 0, n)
    18  	assert.ErrorIs(t, err, io.EOF)
    19  }
    20  
    21  func TestWriteClosedChannel(t *testing.T) {
    22  	blobCh := make(chan Blob)
    23  	bcw := NewBlobChannelWriter(blobCh, 4)
    24  	require.NoError(t, bcw.Close())
    25  	var buf [8]byte
    26  	_, err := bcw.Write(buf[:])
    27  	require.ErrorIs(t, err, ErrBlobChannelWriterClosed)
    28  }
    29  
    30  func TestEmptyWrite(t *testing.T) {
    31  	blobCh := make(chan Blob)
    32  	bcw := NewBlobChannelWriter(blobCh, 4)
    33  	close(blobCh)
    34  	assert.Panics(t, func() {
    35  		var buf [8]byte
    36  		_, _ = bcw.Write(buf[:])
    37  	})
    38  }