Index: snappy/snappy_test.go |
=================================================================== |
--- a/snappy/snappy_test.go |
+++ b/snappy/snappy_test.go |
@@ -5,8 +5,10 @@ |
package snappy |
import ( |
+ "bufio" |
"bytes" |
"fmt" |
+ "io" |
"io/ioutil" |
"os" |
"rand" |
@@ -63,6 +65,53 @@ |
} |
} |
+func TestReaderWriter(t *testing.T) { |
+ // Test that pushing a file's contents through a pipe whose ends are |
+ // wrapped with a snappy Reader and Writer is the identity transform. |
+ const filename = "/usr/share/dict/words" |
+ pr, pw := io.Pipe() |
+ go func() { |
+ f, err := os.Open(filename) |
+ if err != nil { |
+ pw.CloseWithError(err) |
+ return |
+ } |
+ defer f.Close() |
+ _, err = pw.Write([]byte(Magic)) |
+ if err != nil { |
+ pw.CloseWithError(err) |
+ return |
+ } |
+ w := NewWriter(pw) |
+ _, err = io.Copy(w, f) |
+ if err != nil { |
+ pw.CloseWithError(err) |
+ return |
+ } |
+ pw.CloseWithError(w.Flush()) |
+ }() |
+ f, err := os.Open(filename) |
+ if err != nil { |
+ t.Fatal(err) |
+ } |
+ defer f.Close() |
+ b0 := bufio.NewReader(NewReader(pr)) |
+ b1 := bufio.NewReader(f) |
+ for { |
+ s0, err0 := b0.ReadString('\n') |
+ s1, err1 := b1.ReadString('\n') |
+ if err0 != nil || err1 != nil { |
+ if err0 == os.EOF && err1 == os.EOF { |
+ break |
+ } |
+ t.Fatalf("err0=%v, err1=%v", err0, err1) |
+ } |
+ if s0 != s1 { |
+ t.Fatalf("s0=%q, s1=%q", s0, s1) |
+ } |
+ } |
+} |
+ |
func benchWords(b *testing.B, n int, decode bool) { |
b.StopTimer() |