Debian Codegraph @

fastly/event_logs_test.go

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 package fastly
2
3 import (
4 "bytes"
5 "io/ioutil"
6 "testing"
7 )
8
9 var testEventID = "3OMewexIMbzrQj77xxxxxx"
10
11 func TestClient_APIEvents(t *testing.T) {
12 }
13
14 func TestClient_GetAPIEvent_validation(t *testing.T) {
15 var err error
16 _, err = testClient.GetAPIEvent(&GetAPIEventInput{
17 EventID: "",
18 })
19 if err != ErrMissingEventID {
20 t.Errorf("bad error: %s", err)
21 }
22
23 }
24
25 func TestGetAPIEventsFilterInput_formatFilters(t *testing.T) {
26 tests := []struct {
27 description string
28 filters GetAPIEventsFilterInput
29 expected map[string]string
30 }{
31 {
32 description: "converts both strings and ints to strings",
33 filters: GetAPIEventsFilterInput{
34 CustomerID: "65135846153687547",
35 ServiceID: "5343548168357658",
36 EventType: "version.activate",
37 UserID: "654681384354746951",
38 MaxResults: 1,
39 PageNumber: 2,
40 },
41 expected: map[string]string{
42 "filter[customer_id]": "65135846153687547",
43 "filter[service_id]": "5343548168357658",
44 "filter[event_type]": "version.activate",
45 "filter[user_id]": "654681384354746951",
46 "page[size]": "1",
47 "page[number]": "2",
48 },
49 },
50 }
51 for _, testcase := range tests {
52 answer := testcase.filters.formatEventFilters()
53 if len(answer) != len(testcase.expected) {
54 t.Errorf("In test %s: Expected map with %d entries,got one with %d", testcase.description, len(testcase.expected), len(answer))
55 }
56 for key, value := range testcase.expected {
57 if answer[key] != value {
58 t.Errorf("In test %s: Expected %s key to have value %s, got %s", testcase.description, key, value, answer[key])
59 }
60 }
61 }
62 }
63
64 func TestGetEventsPages(t *testing.T) {
65 tests := []struct {
66 description string
67 input string
68 expectedPages EventsPaginationInfo
69 expectedErr error
70 }{
71 {
72 description: "returns the next page",
73 input: `{"links": {"next": "https://google.com/2"}, "data": []}`,
74 expectedPages: EventsPaginationInfo{
75 Next: "https://google.com/2",
76 },
77 },
78 {
79 description: "returns multiple pages",
80 input: `{"links": {"next": "https://google.com/2", "first": "https://google.com/1"}, "data": []}`,
81 expectedPages: EventsPaginationInfo{
82 First: "https://google.com/1",
83 Next: "https://google.com/2",
84 },
85 },
86 {
87 description: "returns no pages",
88 input: `{"data": []}`,
89 expectedPages: EventsPaginationInfo{},
90 },
91 }
92 for _, testcase := range tests {
93 pages, reader, err := getEventsPages(bytes.NewReader([]byte(testcase.input)))
94 if pages != testcase.expectedPages {
95 t.Errorf("Test %s: Expected pages %+v, got %+v", testcase.description, testcase.expectedPages, pages)
96 }
97
98 // we expect to be able to get the original input out again
99 resultBytes, _ := ioutil.ReadAll(reader)
100 if string(resultBytes) != testcase.input {
101 t.Errorf("Test %s: Expected body %s, got %s", testcase.description, testcase.input, string(resultBytes))
102 }
103 if err != testcase.expectedErr {
104 t.Errorf("Test %s: Expected error %v, got %v", testcase.description, testcase.expectedErr, err)
105 }
106 }
107 }