-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil_test.go
62 lines (51 loc) · 1.1 KB
/
util_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
package ctftime
import (
"bytes"
"io/ioutil"
"log"
"net/http"
"path"
"testing"
)
const (
testFile = "event_1.json"
)
func TestGetTestData(t *testing.T) {
buf := getTestData(testFile)
data, err := ioutil.ReadFile(path.Join(test_dir, testFile))
if err != nil {
log.Fatal(err)
}
if string(buf) != string(data) {
t.Errorf("Data doesn't match %v != %v\n", buf, data)
}
}
func TestHttpResponseToStruct(t *testing.T) {
buf := getTestData("event_1.json")
// Create HTTP Response
// 200 OK HTTP/1.0
// <TEST_FILE json data>
response := &http.Response{
Status: "200 OK",
StatusCode: 200,
Proto: "HTTP/1.0",
ProtoMajor: 1,
ProtoMinor: 0,
Body: ioutil.NopCloser(bytes.NewReader(buf)),
}
var events []interface{}
httpResponseToStruct(response, &events)
}
func TestHttpResponseToMap(t *testing.T) {
buf := getTestData("top10_1.json")
response := &http.Response{
Status: "200 OK",
StatusCode: 200,
Proto: "HTTP/1.0",
ProtoMajor: 1,
ProtoMinor: 0,
Body: ioutil.NopCloser(bytes.NewReader(buf)),
}
var top10 Top10s
httpResponseToMap(response, &top10)
}