-
Notifications
You must be signed in to change notification settings - Fork 156
/
screenboards_test.go
95 lines (78 loc) · 2.25 KB
/
screenboards_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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package datadog
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
)
func TestGetScreenboard(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response, err := ioutil.ReadFile("./tests/fixtures/screenboard_response.json")
if err != nil {
t.Fatal(err)
}
w.Write(response)
}))
defer ts.Close()
datadogClient := Client{
baseUrl: ts.URL,
HttpClient: http.DefaultClient,
}
screenboard, err := datadogClient.GetScreenboard(6334)
if err != nil {
t.Fatal(err)
}
expectedID := 6334
if id := screenboard.GetId(); id != expectedID {
t.Fatalf("expect ID %d. Got %d", expectedID, id)
}
expectedTitle := "dogapi test"
if title := screenboard.GetTitle(); title != expectedTitle {
t.Fatalf("expect title %s. Got %s", expectedTitle, title)
}
expectedHeight := 768
if height := screenboard.GetHeight(); height != expectedHeight {
t.Fatalf("expect height %d. Got %d", expectedHeight, height)
}
expectedWidth := 1024
if width := screenboard.GetWidth(); width != expectedWidth {
t.Fatalf("expect width %d. Got %d", expectedWidth, width)
}
expectedReadOnly := false
readOnly, ok := screenboard.GetReadOnlyOk()
if !ok {
t.Fatalf("expect to have a read_only field")
}
if readOnly != expectedReadOnly {
t.Fatalf("expect read_only %v. Got %v", expectedReadOnly, readOnly)
}
for _, widget := range screenboard.Widgets {
validateWidget(t, widget)
}
}
func validateWidget(t *testing.T, wd Widget) {
expectedType := "image"
if widgetType := wd.GetType(); widgetType != expectedType {
t.Fatalf("expect type %s. Got %s", expectedType, widgetType)
}
expectedHeight := 20
if height := wd.GetHeight(); height != expectedHeight {
t.Fatalf("expect height %d. Got %d", expectedHeight, height)
}
expectedWidth := 32
if width := wd.GetWidth(); width != expectedWidth {
t.Fatalf("expect width %d. Got %d", expectedWidth, width)
}
expectedX := 32
if x := wd.GetX(); x != expectedX {
t.Fatalf("expect x %d. Got %d", expectedX, x)
}
expectedY := 7
if y := wd.GetY(); y != expectedY {
t.Fatalf("expect y %d. Got %d", expectedY, y)
}
expectedURL := "http://path/to/image.jpg"
if url := wd.GetURL(); url != expectedURL {
t.Fatalf("expect url %s. Got %s", expectedURL, url)
}
}