-
Notifications
You must be signed in to change notification settings - Fork 156
/
log_lists_test.go
81 lines (59 loc) · 1.58 KB
/
log_lists_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 datadog
import (
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetLogsList(t *testing.T) {
assert := assert.New(t)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response, err := ioutil.ReadFile("./tests/fixtures/logs/loglist_response.json")
assert.Nil(err)
w.Write(response)
}))
defer ts.Close()
client := Client{
baseUrl: ts.URL,
HttpClient: http.DefaultClient,
}
req := &LogsListRequest{
Index: String("main"),
Limit: Int(50),
}
logList, err := client.GetLogsList(req)
assert.Nil(err)
assert.Len(logList.Logs, 2)
}
func TestGetLogsListPages(t *testing.T) {
assert := assert.New(t)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
responseBody := &LogsListRequest{}
body, _ := ioutil.ReadAll(r.Body)
json.Unmarshal(body, responseBody)
if responseBody.StartAt == nil {
response, err := ioutil.ReadFile("./tests/fixtures/logs/loglist_response.json")
assert.Nil(err)
w.Write(response)
} else {
assert.Equal(*responseBody.StartAt, "BBBBBWgN8Xwgr1vKDQAAAABBV2dOOFh3ZzZobm1mWXJFYTR0OA")
response, err := ioutil.ReadFile("./tests/fixtures/logs/loglist_page_response.json")
assert.Nil(err)
w.Write(response)
}
}))
defer ts.Close()
client := Client{
baseUrl: ts.URL,
HttpClient: http.DefaultClient,
}
req := &LogsListRequest{
Index: String("main"),
Limit: Int(50),
}
logs, err := client.GetLogsListPages(req, -1)
assert.Nil(err)
assert.Len(logs, 3)
}