storj.io/uplink@v1.13.0/private/etag/reader_test.go (about)

     1  // Copyright (C) 2021 Storj Labs, Inc.
     2  // See LICENSE for copying information.
     3  
     4  package etag_test
     5  
     6  import (
     7  	"bytes"
     8  	"crypto/sha256"
     9  	"io"
    10  	"testing"
    11  
    12  	"github.com/stretchr/testify/require"
    13  
    14  	"storj.io/common/memory"
    15  	"storj.io/common/testrand"
    16  	"storj.io/uplink/private/etag"
    17  )
    18  
    19  func TestHashReader(t *testing.T) {
    20  	inputData := testrand.Bytes(1 * memory.KiB)
    21  	expectedETag := sha256.Sum256(inputData)
    22  
    23  	reader := etag.NewHashReader(bytes.NewReader(inputData), sha256.New())
    24  	readData, err := io.ReadAll(reader)
    25  	require.NoError(t, err)
    26  	require.Equal(t, inputData, readData)
    27  	require.Equal(t, expectedETag[:], reader.CurrentETag())
    28  }