-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevents_test.go
81 lines (68 loc) · 1.46 KB
/
events_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
74
75
76
77
78
79
80
81
package ctftime
import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"net/http"
"reflect"
"testing"
)
func TestGetEventsData(t *testing.T) {
client, err := newAPIClient("events", nil)
if err != nil {
log.Fatal(err)
}
result, err := client.GetAPIData()
if err != nil {
log.Fatal(err)
}
body, err := json.Marshal(result)
if err != nil {
log.Fatal(err)
}
dummy_resp := &http.Response{
StatusCode: 200,
ProtoMajor: 1,
ProtoMinor: 0,
Body: ioutil.NopCloser(bytes.NewReader(body)),
}
var dummy_events []Event
httpResponseToStruct(dummy_resp, &dummy_events)
if len(dummy_events) != 3 {
t.Error("Invalid event length!")
}
for _, event := range dummy_events {
valid := reflect.TypeOf(Event{})
actual := reflect.TypeOf(event)
if actual != valid {
t.Errorf("Invalid event type of %v! (should be %v).", actual, valid)
}
}
}
func TestGetEventData(t *testing.T) {
ctx := APIContext{
"event_id": 1,
}
result, err := GetAPIData("events", ctx)
if err != nil {
log.Fatal(err)
}
body, err := json.Marshal(result)
if err != nil {
log.Fatal(err)
}
dummy_resp := &http.Response{
StatusCode: 200,
ProtoMajor: 1,
ProtoMinor: 0,
Body: ioutil.NopCloser(bytes.NewReader(body)),
}
var dummy_event Event
httpResponseToStruct(dummy_resp, &dummy_event)
valid := reflect.TypeOf(Event{})
actual := reflect.TypeOf(dummy_event)
if actual != valid {
t.Errorf("Invalid event type of %v! (should be %v).", actual, valid)
}
}