-
Notifications
You must be signed in to change notification settings - Fork 4
/
cmd_test.go
56 lines (51 loc) · 1.03 KB
/
cmd_test.go
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
package ctw
import (
"bytes"
"io/ioutil"
"os"
"testing"
)
func TestCompress(t *testing.T) {
const name = "gettysburg.txt"
const depth = 48
// Compress
f, err := ioutil.TempFile("", "ctw.TestCompress.Compress")
if err != nil {
t.Fatalf("%v", err)
}
defer f.Close()
defer os.Remove(f.Name())
if err := Compress(f, name, depth); err != nil {
t.Fatalf("%v", err)
}
// Decompress
_, err = f.Seek(0, 0)
if err != nil {
t.Fatalf("%v", err)
}
df, err := ioutil.TempFile("", "ctw.TestCompress.Decompress")
if err != nil {
t.Fatalf("%v", err)
}
defer df.Close()
defer os.Remove(df.Name())
if err := Decompress(df, f, depth); err != nil {
t.Fatalf("%v", err)
}
// Check if the decompressed result is the same as the original file
_, err = df.Seek(0, 0)
if err != nil {
t.Fatalf("%v", err)
}
decom, err := ioutil.ReadAll(df)
if err != nil {
t.Fatalf("%v", err)
}
gettys, err := ioutil.ReadFile(name)
if err != nil {
t.Fatalf("%v", err)
}
if !bytes.Equal(gettys, decom) {
t.Errorf("%v %v", gettys, decom)
}
}