stream_test: remove buffer use

This commit is contained in:
Vincent Batts 2015-08-16 19:02:13 -04:00
parent fa4337c370
commit a03956b35e
1 changed files with 7 additions and 8 deletions

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