1
0
Fork 0
mirror of https://github.com/vbatts/merkle.git synced 2024-11-27 08:45:39 +00:00

stream_test: remove buffer use

This commit is contained in:
Vincent Batts 2015-08-16 19:02:13 -04:00
parent fa4337c370
commit a03956b35e

View file

@ -1,7 +1,6 @@
package merkle package merkle
import ( import (
"bytes"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
@ -59,15 +58,15 @@ func TestMerkleHashWriterLargeChunk(t *testing.T) {
} }
func TestMerkleHashWriter(t *testing.T) { func TestMerkleHashWriter(t *testing.T) {
msg := "the quick brown fox jumps over the lazy dog" msg := []byte("the quick brown fox jumps over the lazy dog")
expectedSum := "48940c1c72636648ad40aa59c162f2208e835b38" expectedSum := "48940c1c72636648ad40aa59c162f2208e835b38"
h := NewHash(DefaultHashMaker, 10) h := NewHash(DefaultHashMaker, 10)
i, err := io.Copy(h, bytes.NewBufferString(msg)) i, err := h.Write(msg)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if i != int64(len(msg)) { if i != len(msg) {
t.Fatalf("expected to write %d, only wrote %d", len(msg), i) t.Fatalf("expected to write %d, only wrote %d", len(msg), i)
} }
@ -103,11 +102,11 @@ func TestMerkleHashWriter(t *testing.T) {
} }
// write our msg again and get the same sum // write our msg again and get the same sum
i, err = io.Copy(h, bytes.NewBufferString(msg)) i, err = h.Write(msg)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if i != int64(len(msg)) { if i != len(msg) {
t.Fatalf("expected to write %d, only wrote %d", len(msg), i) t.Fatalf("expected to write %d, only wrote %d", len(msg), i)
} }
// Test Sum(), ensure same sum // Test Sum(), ensure same sum
@ -117,11 +116,11 @@ func TestMerkleHashWriter(t *testing.T) {
} }
// Write more. This should pop the last node, and use the lastBlock. // Write more. This should pop the last node, and use the lastBlock.
i, err = io.Copy(h, bytes.NewBufferString(msg)) i, err = h.Write(msg)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if i != int64(len(msg)) { if i != len(msg) {
t.Fatalf("expected to write %d, only wrote %d", len(msg), i) t.Fatalf("expected to write %d, only wrote %d", len(msg), i)
} }
expectedNum = 9 expectedNum = 9