Skip to content

Commit 643a7df

Browse files
committed
Add get a screenboard api test
1 parent dd6f675 commit 643a7df

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed

screenboards_test.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package datadog
2+
3+
import (
4+
"io/ioutil"
5+
"net/http"
6+
"net/http/httptest"
7+
"testing"
8+
)
9+
10+
func TestGetScreenboard(t *testing.T) {
11+
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
12+
response, err := ioutil.ReadFile("./tests/fixtures/screenboard_response.json")
13+
if err != nil {
14+
t.Fatal(err)
15+
}
16+
w.Write(response)
17+
}))
18+
defer ts.Close()
19+
20+
datadogClient := Client{
21+
baseUrl: ts.URL,
22+
HttpClient: http.DefaultClient,
23+
}
24+
25+
screenboard, err := datadogClient.GetScreenboard(6334)
26+
if err != nil {
27+
t.Fatal(err)
28+
}
29+
30+
expectedID := 6334
31+
if id := screenboard.GetId(); id != expectedID {
32+
t.Fatalf("expect ID %d. Got %d", expectedID, id)
33+
}
34+
35+
expectedTitle := "dogapi test"
36+
if title := screenboard.GetTitle(); title != expectedTitle {
37+
t.Fatalf("expect title %s. Got %s", expectedTitle, title)
38+
}
39+
40+
expectedHeight := 768
41+
if height := screenboard.GetHeight(); height != expectedHeight {
42+
t.Fatalf("expect height %d. Got %d", expectedHeight, height)
43+
}
44+
45+
expectedWidth := 1024
46+
if width := screenboard.GetWidth(); width != expectedWidth {
47+
t.Fatalf("expect width %d. Got %d", expectedWidth, width)
48+
}
49+
50+
expectedReadOnly := false
51+
readOnly, ok := screenboard.GetReadOnlyOk()
52+
if !ok {
53+
t.Fatalf("expect to have a read_only field")
54+
}
55+
56+
if readOnly != expectedReadOnly {
57+
t.Fatalf("expect read_only %v. Got %v", expectedReadOnly, readOnly)
58+
}
59+
60+
widgets, ok := screenboard.GetWidgetsByOk()
61+
if !ok {
62+
t.Fatal("expect widgets field to exist")
63+
}
64+
for _, widget := range widgets {
65+
validateWidget(t, widget)
66+
}
67+
}
68+
69+
func validateWidget(t *testing.T, wd Widget) {
70+
expectedType := "image"
71+
if widgetType := wd.GetType(); widgetType != expectedType {
72+
t.Fatalf("expect type %s. Got %s", expectedType, widgetType)
73+
}
74+
75+
expectedHeight := 20
76+
if height := wd.GetHeight(); height != expectedHeight {
77+
t.Fatalf("expect height %d. Got %d", expectedHeight, height)
78+
}
79+
80+
expectedWidth := 32
81+
if width := wd.GetWidth(); width != expectedWidth {
82+
t.Fatalf("expect width %d. Got %d", expectedWidth, width)
83+
}
84+
85+
expectedX := 32
86+
if x := wd.GetX(); x != expectedX {
87+
t.Fatalf("expect x %d. Got %d", expectedX, x)
88+
}
89+
90+
expectedY := 7
91+
if y := wd.GetY(); y != expectedY {
92+
t.Fatalf("expect y %d. Got %d", expectedY, y)
93+
}
94+
95+
expectedURL := "http://path/to/image.jpg"
96+
if url := wd.GetURL(); url != expectedURL {
97+
t.Fatalf("expect url %s. Got %s", expectedURL, url)
98+
}
99+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"board_title": "dogapi test",
3+
"height": 768,
4+
"id": 6334,
5+
"widgets": [
6+
{
7+
"height": 20,
8+
"type": "image",
9+
"url": "http://path/to/image.jpg",
10+
"width": 32,
11+
"x": 32,
12+
"y": 7
13+
}
14+
],
15+
"width": 1024,
16+
"created": "2015-12-17T23:06:06.703087+00:00",
17+
"modified": "2015-12-17T23:12:26.726234+00:00",
18+
"read_only": false
19+
}

0 commit comments

Comments
 (0)