1package unsnap 2 3// copyright (c) 2013-2014, Jason E. Aten. 4// License: MIT. 5 6import ( 7 "fmt" 8 "io" 9 "os" 10 "os/exec" 11 "testing" 12 13 cv "github.com/glycerine/goconvey/convey" 14) 15 16func TestSnappyFileUncompressedChunk(t *testing.T) { 17 orig := "unenc.txt" 18 compressed := "unenc.txt.snappy" 19 myUncomp := "testout.unsnap" 20 21 cv.Convey("SnappyFile should read snappy compressed with uncompressed chunk file.", t, func() { 22 f, err := Open(compressed) 23 24 out, err := os.Create(myUncomp) 25 if err != nil { 26 panic(err) 27 } 28 29 io.Copy(out, f) 30 out.Close() 31 f.Close() 32 33 cs := []string{orig, myUncomp} 34 cmd := exec.Command("/usr/bin/diff", cs...) 35 bs, err := cmd.Output() 36 if err != nil { 37 fmt.Printf("\nproblem attempting: diff %s %s\n", cs[0], cs[1]) 38 fmt.Printf("output: %v\n", string(bs)) 39 panic(err) 40 } 41 cv.So(len(bs), cv.ShouldEqual, 0) 42 43 }) 44} 45 46func TestSnappyFileCompressed(t *testing.T) { 47 orig := "binary.dat" 48 compressed := "binary.dat.snappy" 49 myUncomp := "testout2.unsnap" 50 51 cv.Convey("SnappyFile should read snappy compressed with compressed chunk file.", t, func() { 52 f, err := Open(compressed) 53 54 out, err := os.Create(myUncomp) 55 if err != nil { 56 panic(err) 57 } 58 59 io.Copy(out, f) 60 out.Close() 61 f.Close() 62 63 cs := []string{orig, myUncomp} 64 cmd := exec.Command("/usr/bin/diff", cs...) 65 bs, err := cmd.Output() 66 if err != nil { 67 fmt.Printf("\nproblem attempting: diff %s %s\n", cs[0], cs[1]) 68 fmt.Printf("output: %v\n", string(bs)) 69 panic(err) 70 } 71 cv.So(len(bs), cv.ShouldEqual, 0) 72 73 }) 74} 75 76func TestSnappyOnBinaryHardToCompress(t *testing.T) { 77 78 // now we check our Write() method, in snap.go 79 80 orig := "binary.dat" 81 myCompressed := "testout_binary.dat.snappy" 82 knownGoodCompressed := "binary.dat.snappy" 83 84 cv.Convey("SnappyFile should write snappy compressed in streaming format, when fed lots of compressing stuff.", t, func() { 85 86 f, err := os.Open(orig) 87 if err != nil { 88 panic(err) 89 } 90 91 out, err := Create(myCompressed) 92 if err != nil { 93 panic(err) 94 } 95 96 io.Copy(out, f) 97 out.Close() 98 f.Close() 99 100 cs := []string{knownGoodCompressed, myCompressed} 101 cmd := exec.Command("/usr/bin/diff", cs...) 102 bs, err := cmd.Output() 103 if err != nil { 104 fmt.Printf("\nproblem attempting: diff %s %s\n", cs[0], cs[1]) 105 fmt.Printf("output: %v\n", string(bs)) 106 panic(err) 107 } 108 cv.So(len(bs), cv.ShouldEqual, 0) 109 110 }) 111} 112