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