forked from dotabuff/manta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_test.go
61 lines (49 loc) · 1.46 KB
/
parser_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
package manta
import (
"bytes"
"compress/bzip2"
"io"
"net"
"net/http"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestStreamingReaderTimeout(t *testing.T) {
assert := assert.New(t)
// create a http client with a timeout too low to get the entire replay
client := http.Client{
Timeout: 2 * time.Second,
}
// request the replay, the timeout should be enough for it to begin successfully
resp, err := client.Get("http://replay111.valve.net/570/2526759078_1821332888.dem.bz2")
if err != nil {
t.Fatalf("unable to get remote replay: %s", err)
}
defer resp.Body.Close()
// create a new parser with the streaming response
parser, err := NewStreamParser(bzip2.NewReader(resp.Body))
if err != nil {
t.Fatalf("unable to create parser: %s", err)
}
// expect the parser to fail after a bit under 2 seconds with a timeout error
err = parser.Start()
netErr, ok := err.(net.Error)
assert.True(ok)
assert.True(netErr.Timeout())
}
func TestStreamingReaderUnexpectedEOF(t *testing.T) {
assert := assert.New(t)
// get data
data := mustGetReplayData("2159568145", "https://s3-us-west-2.amazonaws.com/manta.dotabuff/2159568145.dem")
// cut the data at a random point
reader := bytes.NewReader(data[:6666])
// begin parsing the incomplete data
parser, err := NewStreamParser(reader)
if err != nil {
t.Fatalf("unable to create parser: %s", err)
}
// expect an unexpected EOF error
err = parser.Start()
assert.Equal(io.ErrUnexpectedEOF, err)
}