-
Notifications
You must be signed in to change notification settings - Fork 2
/
decode_test.go
50 lines (47 loc) · 1.05 KB
/
decode_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
package webarchive
import (
"os"
"testing"
)
func TestDecodePayload(t *testing.T) {
checkExamples(t)
f, _ := os.Open("examples/decode.warc")
defer f.Close()
rdr, err := NewWARCReader(f)
if err != nil {
t.Fatal("failure loading example: " + err.Error())
}
rec, err := rdr.NextPayload()
if err != nil {
t.Fatal(err)
}
dec := DecodePayload(rec)
buf := make([]byte, 4)
if i, err := dec.Read(buf); err != nil || i != 4 {
t.Fatal("failure reading decode.warc")
}
if string(buf) != "\n<!D" {
t.Fatalf("expecting ' <!D' got %s", buf)
}
}
func TestDecodePayloadT(t *testing.T) {
checkExamples(t)
f, _ := os.Open("examples/decode.warc")
defer f.Close()
rdr, err := NewWARCReader(f)
if err != nil {
t.Fatal("failure loading example: " + err.Error())
}
rec, err := rdr.NextPayload()
if err != nil {
t.Fatal(err)
}
dec := DecodePayloadT(rec)
buf := make([]byte, 4)
if i, err := dec.Read(buf); err != nil || i != 4 {
t.Fatal("failure reading decode.warc")
}
if string(buf) == "\n<!D" {
t.Fatalf("expecting gibberish got %s", buf)
}
}