Skip to content

Commit ae3affd

Browse files
teraken0509zorkian
authored andcommitted
Bugfix fix screenboard (#190)
* fix X,Y Json mapping * fix width/height data type to int * Add Get Widgets Method to Screenboard * Add get a screenboard api test * execute make generate
1 parent 973d66a commit ae3affd

File tree

6 files changed

+134
-19
lines changed

6 files changed

+134
-19
lines changed

datadog-accessors.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6338,18 +6338,18 @@ func (r *Rule) SetTimeframe(v string) {
63386338
}
63396339

63406340
// GetHeight returns the Height field if non-nil, zero value otherwise.
6341-
func (s *Screenboard) GetHeight() string {
6341+
func (s *Screenboard) GetHeight() int {
63426342
if s == nil || s.Height == nil {
6343-
return ""
6343+
return 0
63446344
}
63456345
return *s.Height
63466346
}
63476347

63486348
// GetHeightOk returns a tuple with the Height field if it's non-nil, zero value otherwise
63496349
// and a boolean to check if the value has been set.
6350-
func (s *Screenboard) GetHeightOk() (string, bool) {
6350+
func (s *Screenboard) GetHeightOk() (int, bool) {
63516351
if s == nil || s.Height == nil {
6352-
return "", false
6352+
return 0, false
63536353
}
63546354
return *s.Height, true
63556355
}
@@ -6364,7 +6364,7 @@ func (s *Screenboard) HasHeight() bool {
63646364
}
63656365

63666366
// SetHeight allocates a new s.Height and returns the pointer to it.
6367-
func (s *Screenboard) SetHeight(v string) {
6367+
func (s *Screenboard) SetHeight(v int) {
63686368
s.Height = &v
63696369
}
63706370

@@ -6493,18 +6493,18 @@ func (s *Screenboard) SetTitle(v string) {
64936493
}
64946494

64956495
// GetWidth returns the Width field if non-nil, zero value otherwise.
6496-
func (s *Screenboard) GetWidth() string {
6496+
func (s *Screenboard) GetWidth() int {
64976497
if s == nil || s.Width == nil {
6498-
return ""
6498+
return 0
64996499
}
65006500
return *s.Width
65016501
}
65026502

65036503
// GetWidthOk returns a tuple with the Width field if it's non-nil, zero value otherwise
65046504
// and a boolean to check if the value has been set.
6505-
func (s *Screenboard) GetWidthOk() (string, bool) {
6505+
func (s *Screenboard) GetWidthOk() (int, bool) {
65066506
if s == nil || s.Width == nil {
6507-
return "", false
6507+
return 0, false
65086508
}
65096509
return *s.Width, true
65106510
}
@@ -6519,7 +6519,7 @@ func (s *Screenboard) HasWidth() bool {
65196519
}
65206520

65216521
// SetWidth allocates a new s.Width and returns the pointer to it.
6522-
func (s *Screenboard) SetWidth(v string) {
6522+
func (s *Screenboard) SetWidth(v int) {
65236523
s.Width = &v
65246524
}
65256525

integration/screenboards_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package integration
22

33
import (
4-
"github.com/zorkian/go-datadog-api"
54
"testing"
5+
6+
"github.com/zorkian/go-datadog-api"
67
)
78

89
func TestScreenboardCreateAndDelete(t *testing.T) {
@@ -92,8 +93,8 @@ func TestScreenboardGet(t *testing.T) {
9293
func getTestScreenboard() *datadog.Screenboard {
9394
return &datadog.Screenboard{
9495
Title: datadog.String("___Test-Board___"),
95-
Height: datadog.String("600"),
96-
Width: datadog.String("800"),
96+
Height: datadog.Int(600),
97+
Width: datadog.Int(800),
9798
Widgets: []datadog.Widget{},
9899
}
99100
}
@@ -128,10 +129,10 @@ func assertScreenboardEquals(t *testing.T, actual, expected *datadog.Screenboard
128129
t.Errorf("Screenboard title does not match: %s != %s", *actual.Title, *expected.Title)
129130
}
130131
if *actual.Width != *expected.Width {
131-
t.Errorf("Screenboard width does not match: %s != %s", *actual.Width, *expected.Width)
132+
t.Errorf("Screenboard width does not match: %d != %d", *actual.Width, *expected.Width)
132133
}
133134
if *actual.Height != *expected.Height {
134-
t.Errorf("Screenboard width does not match: %s != %s", *actual.Height, *expected.Height)
135+
t.Errorf("Screenboard width does not match: %d != %d", *actual.Height, *expected.Height)
135136
}
136137
if len(actual.Widgets) != len(expected.Widgets) {
137138
t.Errorf("Number of Screenboard widgets does not match: %d != %d", len(actual.Widgets), len(expected.Widgets))

screen_widgets.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ type Widget struct {
9090
TitleSize *int `json:"title_size,omitempty"`
9191
Height *int `json:"height,omitempty"`
9292
Width *int `json:"width,omitempty"`
93-
X *int `json:"y,omitempty"`
94-
Y *int `json:"x,omitempty"`
93+
X *int `json:"x,omitempty"`
94+
Y *int `json:"y,omitempty"`
9595

9696
// For Timeseries, TopList, EventTimeline, EvenStream, AlertGraph, CheckStatus, ServiceSummary, LogStream widgets
9797
Time *Time `json:"time,omitempty"`

screenboards.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717
type Screenboard struct {
1818
Id *int `json:"id,omitempty"`
1919
Title *string `json:"board_title,omitempty"`
20-
Height *string `json:"height,omitempty"`
21-
Width *string `json:"width,omitempty"`
20+
Height *int `json:"height,omitempty"`
21+
Width *int `json:"width,omitempty"`
2222
Shared *bool `json:"shared,omitempty"`
2323
TemplateVariables []TemplateVariable `json:"template_variables,omitempty"`
2424
Widgets []Widget `json:"widgets"`

screenboards_test.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
for _, widget := range screenboard.Widgets {
61+
validateWidget(t, widget)
62+
}
63+
}
64+
65+
func validateWidget(t *testing.T, wd Widget) {
66+
expectedType := "image"
67+
if widgetType := wd.GetType(); widgetType != expectedType {
68+
t.Fatalf("expect type %s. Got %s", expectedType, widgetType)
69+
}
70+
71+
expectedHeight := 20
72+
if height := wd.GetHeight(); height != expectedHeight {
73+
t.Fatalf("expect height %d. Got %d", expectedHeight, height)
74+
}
75+
76+
expectedWidth := 32
77+
if width := wd.GetWidth(); width != expectedWidth {
78+
t.Fatalf("expect width %d. Got %d", expectedWidth, width)
79+
}
80+
81+
expectedX := 32
82+
if x := wd.GetX(); x != expectedX {
83+
t.Fatalf("expect x %d. Got %d", expectedX, x)
84+
}
85+
86+
expectedY := 7
87+
if y := wd.GetY(); y != expectedY {
88+
t.Fatalf("expect y %d. Got %d", expectedY, y)
89+
}
90+
91+
expectedURL := "http://path/to/image.jpg"
92+
if url := wd.GetURL(); url != expectedURL {
93+
t.Fatalf("expect url %s. Got %s", expectedURL, url)
94+
}
95+
}
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)