Skip to content

Commit 088d2e4

Browse files
committed
Accepts ints and strings for Screenboard size.
Besides integer sizes in pixel (e.g. 768) the API can also return percentages (e.g. "100%"). Fixes #192
1 parent 5e411c0 commit 088d2e4

File tree

5 files changed

+104
-74
lines changed

5 files changed

+104
-74
lines changed

datadog-accessors.go

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

64026402
// GetHeight returns the Height field if non-nil, zero value otherwise.
6403-
func (s *Screenboard) GetHeight() int {
6403+
func (s *Screenboard) GetHeight() StrintD {
64046404
if s == nil || s.Height == nil {
6405-
return 0
6405+
return ""
64066406
}
64076407
return *s.Height
64086408
}
64096409

64106410
// GetHeightOk returns a tuple with the Height field if it's non-nil, zero value otherwise
64116411
// and a boolean to check if the value has been set.
6412-
func (s *Screenboard) GetHeightOk() (int, bool) {
6412+
func (s *Screenboard) GetHeightOk() (StrintD, bool) {
64136413
if s == nil || s.Height == nil {
6414-
return 0, false
6414+
return "", false
64156415
}
64166416
return *s.Height, true
64176417
}
@@ -6426,7 +6426,7 @@ func (s *Screenboard) HasHeight() bool {
64266426
}
64276427

64286428
// SetHeight allocates a new s.Height and returns the pointer to it.
6429-
func (s *Screenboard) SetHeight(v int) {
6429+
func (s *Screenboard) SetHeight(v StrintD) {
64306430
s.Height = &v
64316431
}
64326432

@@ -6555,18 +6555,18 @@ func (s *Screenboard) SetTitle(v string) {
65556555
}
65566556

65576557
// GetWidth returns the Width field if non-nil, zero value otherwise.
6558-
func (s *Screenboard) GetWidth() int {
6558+
func (s *Screenboard) GetWidth() StrintD {
65596559
if s == nil || s.Width == nil {
6560-
return 0
6560+
return ""
65616561
}
65626562
return *s.Width
65636563
}
65646564

65656565
// GetWidthOk returns a tuple with the Width field if it's non-nil, zero value otherwise
65666566
// and a boolean to check if the value has been set.
6567-
func (s *Screenboard) GetWidthOk() (int, bool) {
6567+
func (s *Screenboard) GetWidthOk() (StrintD, bool) {
65686568
if s == nil || s.Width == nil {
6569-
return 0, false
6569+
return "", false
65706570
}
65716571
return *s.Width, true
65726572
}
@@ -6581,7 +6581,7 @@ func (s *Screenboard) HasWidth() bool {
65816581
}
65826582

65836583
// SetWidth allocates a new s.Width and returns the pointer to it.
6584-
func (s *Screenboard) SetWidth(v int) {
6584+
func (s *Screenboard) SetWidth(v StrintD) {
65856585
s.Width = &v
65866586
}
65876587

integration/screenboards_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package integration
33
import (
44
"testing"
55

6-
"github.com/zorkian/go-datadog-api"
6+
datadog "github.com/zorkian/go-datadog-api"
77
)
88

99
func TestScreenboardCreateAndDelete(t *testing.T) {
@@ -93,8 +93,8 @@ func TestScreenboardGet(t *testing.T) {
9393
func getTestScreenboard() *datadog.Screenboard {
9494
return &datadog.Screenboard{
9595
Title: datadog.String("___Test-Board___"),
96-
Height: datadog.Int(600),
97-
Width: datadog.Int(800),
96+
Height: datadog.Strint("600"),
97+
Width: datadog.Strint("800"),
9898
Widgets: []datadog.Widget{},
9999
}
100100
}
@@ -129,10 +129,10 @@ func assertScreenboardEquals(t *testing.T, actual, expected *datadog.Screenboard
129129
t.Errorf("Screenboard title does not match: %s != %s", *actual.Title, *expected.Title)
130130
}
131131
if *actual.Width != *expected.Width {
132-
t.Errorf("Screenboard width does not match: %d != %d", *actual.Width, *expected.Width)
132+
t.Errorf("Screenboard width does not match: %s != %s", *actual.Width, *expected.Width)
133133
}
134134
if *actual.Height != *expected.Height {
135-
t.Errorf("Screenboard width does not match: %d != %d", *actual.Height, *expected.Height)
135+
t.Errorf("Screenboard width does not match: %s != %s", *actual.Height, *expected.Height)
136136
}
137137
if len(actual.Widgets) != len(expected.Widgets) {
138138
t.Errorf("Number of Screenboard widgets does not match: %d != %d", len(actual.Widgets), len(expected.Widgets))

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 *int `json:"height,omitempty"`
21-
Width *int `json:"width,omitempty"`
20+
Height *StrintD `json:"height,omitempty"`
21+
Width *StrintD `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: 78 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,68 +11,89 @@ import (
1111
)
1212

1313
func TestGetScreenboard(t *testing.T) {
14-
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
15-
response, err := ioutil.ReadFile("./testdata/fixtures/screenboard_response.json")
16-
if err != nil {
17-
// mustn't call t.Fatal from a different Goroutine
18-
http.Error(w, err.Error(), http.StatusInternalServerError)
19-
return
20-
}
21-
w.Write(response)
22-
}))
23-
defer ts.Close()
24-
25-
datadogClient := Client{
26-
baseUrl: ts.URL,
27-
HttpClient: ts.Client(),
28-
RetryTimeout: 5 * time.Second,
29-
}
30-
31-
got, err := datadogClient.GetScreenboard(6334)
32-
if err != nil {
33-
t.Fatal(err)
34-
}
35-
36-
want := &Screenboard{
37-
Id: Int(6334),
38-
Title: String("dogapi test"),
39-
Height: Int(768),
40-
Width: Int(1024),
41-
ReadOnly: Bool(false),
42-
Widgets: []Widget{
43-
Widget{
44-
Type: String("image"),
45-
Height: Int(20),
46-
Width: Int(32),
47-
X: Int(32),
48-
Y: Int(7),
49-
URL: String("http://path/to/image.jpg"),
50-
},
51-
Widget{
52-
Type: String("timeseries"),
53-
TileDef: &TileDef{
54-
Precision: Strint("42"),
14+
tests := []struct {
15+
file string
16+
want *Screenboard
17+
}{
18+
{
19+
file: "screenboard_response",
20+
want: &Screenboard{
21+
Id: Int(6334),
22+
Title: String("dogapi test"),
23+
Height: Strint("768"),
24+
Width: Strint("1024"),
25+
ReadOnly: Bool(false),
26+
Widgets: []Widget{
27+
Widget{
28+
Type: String("image"),
29+
Height: Int(20),
30+
Width: Int(32),
31+
X: Int(32),
32+
Y: Int(7),
33+
URL: String("http://path/to/image.jpg"),
34+
},
35+
Widget{
36+
Type: String("timeseries"),
37+
TileDef: &TileDef{
38+
Precision: Strint("42"),
39+
},
40+
},
41+
Widget{
42+
Type: String("timeseries"),
43+
TileDef: &TileDef{
44+
Precision: Strint("*"),
45+
},
46+
},
5547
},
5648
},
57-
Widget{
58-
Type: String("timeseries"),
59-
TileDef: &TileDef{
60-
Precision: Strint("*"),
61-
},
49+
},
50+
{
51+
file: "screenboard_response_fullscreen",
52+
want: &Screenboard{
53+
Id: Int(6335),
54+
Title: String("dogapi fullscreen test"),
55+
Height: Strint("100%"),
56+
Width: Strint("100%"),
57+
ReadOnly: Bool(false),
6258
},
6359
},
6460
}
61+
for _, tt := range tests {
62+
t.Run(tt.file, func(t *testing.T) {
63+
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
64+
response, err := ioutil.ReadFile("./testdata/fixtures/" + tt.file + ".json")
65+
if err != nil {
66+
// mustn't call t.Fatal from a different Goroutine
67+
http.Error(w, err.Error(), http.StatusInternalServerError)
68+
return
69+
}
70+
w.Write(response)
71+
}))
72+
defer ts.Close()
73+
74+
datadogClient := Client{
75+
baseUrl: ts.URL,
76+
HttpClient: ts.Client(),
77+
RetryTimeout: 5 * time.Second,
78+
}
79+
80+
got, err := datadogClient.GetScreenboard(6334)
81+
if err != nil {
82+
t.Fatal(err)
83+
}
6584

66-
if !reflect.DeepEqual(got, want) {
67-
// Go formatting doesn't handle pointers gracefully, so we'll display the diff as JSON
68-
gotJSON, err := json.MarshalIndent(got, "", "\t")
69-
if err != nil {
70-
t.Fatal(err)
71-
}
72-
wantJSON, err := json.MarshalIndent(want, "", "\t")
73-
if err != nil {
74-
t.Fatal(err)
75-
}
76-
t.Errorf("got:\n%s\nwant:\n%s", gotJSON, wantJSON)
85+
if !reflect.DeepEqual(got, tt.want) {
86+
// Go formatting doesn't handle pointers gracefully, so we'll display the diff as JSON
87+
gotJSON, err := json.MarshalIndent(got, "", "\t")
88+
if err != nil {
89+
t.Fatal(err)
90+
}
91+
wantJSON, err := json.MarshalIndent(tt.want, "", "\t")
92+
if err != nil {
93+
t.Fatal(err)
94+
}
95+
t.Errorf("got:\n%s\nwant:\n%s", gotJSON, wantJSON)
96+
}
97+
})
7798
}
7899
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"board_title": "dogapi fullscreen test",
3+
"id": 6335,
4+
"height": "100%",
5+
"width": "100%",
6+
"created": "2019-03-01T13:37:00.420042+01:00",
7+
"modified": "2019-03-01T15:25:26.726234+01:00",
8+
"read_only": false
9+
}

0 commit comments

Comments
 (0)