forked from smira/go-xz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xz_test.go
67 lines (58 loc) · 1021 Bytes
/
xz_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
57
58
59
60
61
62
63
64
65
66
67
package xz
import (
"bytes"
"io"
"io/ioutil"
"os"
"testing"
)
func TestDecompress(T *testing.T) {
orig, err := os.Open("testdata/spec")
if err != nil {
T.Fatal(err)
}
defer orig.Close()
expected := &bytes.Buffer{}
_, err = io.Copy(expected, orig)
if err != nil {
T.Fatal(err)
}
source, err := os.Open("testdata/spec.xz")
if err != nil {
T.Fatal(err)
}
defer source.Close()
r, err := NewReader(source)
if err != nil {
T.Fatal(err)
}
buf := &bytes.Buffer{}
n, err := io.Copy(buf, r)
if n != int64(expected.Len()) {
T.Fail()
}
if bytes.Compare(buf.Bytes(), expected.Bytes()) != 0 {
T.Fail()
}
err = r.Close()
if err != nil {
T.Fail()
}
}
func BenchmarkDecompress(b *testing.B) {
data, err := ioutil.ReadFile("testdata/spec.xz")
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
r, err := NewReader(bytes.NewReader(data))
if err != nil {
b.Fatal(err)
}
_, err = io.Copy(ioutil.Discard, r)
if err != nil {
b.Fatal(err)
}
}
}