-
Notifications
You must be signed in to change notification settings - Fork 1
/
reader_multi_test.go
73 lines (55 loc) · 1.2 KB
/
reader_multi_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
68
69
70
71
72
73
package yenc
import (
"bufio"
"bytes"
"encoding/hex"
"io/ioutil"
"log"
"os"
"testing"
"github.com/andrewstuart/nntp"
)
func TestDecMulti(t *testing.T) {
b := &bytes.Buffer{}
f1, err := os.Open("./test/00000020.ntx")
if err != nil {
t.Fatalf("f1 error")
}
art, err := nntp.NewResponse(f1)
if err != nil {
t.Errorf("Article 1 err: %v\n", err)
}
r := NewReader(art.Body)
_, err = bufio.NewReader(r).WriteTo(b)
if err != nil {
if err, ok := err.(ErrBadCRC); ok {
t.Log(err)
}
t.Errorf("Article 1 error: %v\n", err)
}
f2, err := os.Open("./test/00000021.ntx")
if err != nil {
t.Fatalf("f2 error")
}
art2, err := nntp.NewResponse(f2)
if err != nil {
t.Errorf("art2 error: %v\n", err)
}
r = NewReader(art2.Body)
_, err = bufio.NewReader(r).WriteTo(b)
if err != nil {
if err, ok := err.(ErrBadCRC); ok {
t.Log(err)
}
t.Errorf("Article 2 error: %v\n", err)
}
fenc, err := ioutil.ReadFile("./test/joystick.jpg")
if err != nil {
t.Fatalf("Error loading file for comparison")
}
if !bytes.Equal(b.Bytes(), fenc) {
log.Println("got", hex.Dump(b.Bytes()))
log.Println("expected", fenc)
t.Error("Multipart did not decode properly (decoded separately)")
}
}