github.com/code-to-go/safepool.lib@v0.0.0-20221205180519-ee25e63c226e/security/hash_test.go (about)

     1  package security
     2  
     3  import (
     4  	"bytes"
     5  	"crypto/rand"
     6  	"io"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestHashStream(t *testing.T) {
    13  
    14  	b := make([]byte, 1024)
    15  	rand.Read(b)
    16  
    17  	r := bytes.NewBuffer(b)
    18  	s, _ := NewHashStream(r, nil)
    19  	w := &bytes.Buffer{}
    20  
    21  	io.Copy(w, s)
    22  	hash := s.Hash()
    23  
    24  	s, _ = NewHashStream(nil, &bytes.Buffer{})
    25  	io.Copy(s, w)
    26  
    27  	assert.Equal(t, hash, s.Hash())
    28  }