github.com/koko1123/flow-go-1@v0.29.6/ledger/complete/wal/checksum_test.go (about) 1 package wal 2 3 import ( 4 "bytes" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 ) 9 10 func Test_ChecksumWriter(t *testing.T) { 11 12 buffer := &bytes.Buffer{} 13 14 writer := NewCRC32Writer(buffer) 15 16 _, err := writer.Write([]byte("a")) 17 require.NoError(t, err) 18 19 _, err = writer.Write([]byte("b")) 20 require.NoError(t, err) 21 22 _, err = writer.Write([]byte("c")) 23 require.NoError(t, err) 24 25 crc32 := writer.Crc32() 26 27 require.Equal(t, uint32(0x364b3fb7), crc32) 28 require.Equal(t, "abc", buffer.String()) 29 } 30 31 func Test_ChecksumReader(t *testing.T) { 32 33 buffer := bytes.NewBufferString("abc") 34 35 reader := NewCRC32Reader(buffer) 36 37 b := make([]byte, 1) 38 39 _, err := reader.Read(b) 40 require.NoError(t, err) 41 42 _, err = reader.Read(b) 43 require.NoError(t, err) 44 45 _, err = reader.Read(b) 46 require.NoError(t, err) 47 48 crc32 := reader.Crc32() 49 50 require.Equal(t, uint32(0x364b3fb7), crc32) 51 require.Equal(t, 0, buffer.Len()) 52 }