From c66708abf4377cce42c0998390c0344cc568aff0 Mon Sep 17 00:00:00 2001 From: knqyf263 Date: Mon, 25 Feb 2019 19:22:00 +0900 Subject: [PATCH] Fix Width types for when screenboard width is string --- datadog-accessors.go | 16 ++++++++-------- integration/screen_widgets_test.go | 5 +++-- integration/screenboards_test.go | 5 +++-- screen_widgets.go | 12 ++++++------ screenboards.go | 3 ++- screenboards_test.go | 5 +++-- 6 files changed, 25 insertions(+), 21 deletions(-) diff --git a/datadog-accessors.go b/datadog-accessors.go index d08aacb..cba827e 100644 --- a/datadog-accessors.go +++ b/datadog-accessors.go @@ -851,7 +851,7 @@ func (c *ConditionalFormat) SetPalette(v string) { } // GetValue returns the Value field if non-nil, zero value otherwise. -func (c *ConditionalFormat) GetValue() string { +func (c *ConditionalFormat) GetValue() json.Number { if c == nil || c.Value == nil { return "" } @@ -860,7 +860,7 @@ func (c *ConditionalFormat) GetValue() string { // GetValueOk returns a tuple with the Value field if it's non-nil, zero value otherwise // and a boolean to check if the value has been set. -func (c *ConditionalFormat) GetValueOk() (string, bool) { +func (c *ConditionalFormat) GetValueOk() (json.Number, bool) { if c == nil || c.Value == nil { return "", false } @@ -877,7 +877,7 @@ func (c *ConditionalFormat) HasValue() bool { } // SetValue allocates a new c.Value and returns the pointer to it. -func (c *ConditionalFormat) SetValue(v string) { +func (c *ConditionalFormat) SetValue(v json.Number) { c.Value = &v } @@ -6555,18 +6555,18 @@ func (s *Screenboard) SetTitle(v string) { } // GetWidth returns the Width field if non-nil, zero value otherwise. -func (s *Screenboard) GetWidth() int { +func (s *Screenboard) GetWidth() json.Number { if s == nil || s.Width == nil { - return 0 + return "" } return *s.Width } // GetWidthOk returns a tuple with the Width field if it's non-nil, zero value otherwise // and a boolean to check if the value has been set. -func (s *Screenboard) GetWidthOk() (int, bool) { +func (s *Screenboard) GetWidthOk() (json.Number, bool) { if s == nil || s.Width == nil { - return 0, false + return "", false } return *s.Width, true } @@ -6581,7 +6581,7 @@ func (s *Screenboard) HasWidth() bool { } // SetWidth allocates a new s.Width and returns the pointer to it. -func (s *Screenboard) SetWidth(v int) { +func (s *Screenboard) SetWidth(v json.Number) { s.Width = &v } diff --git a/integration/screen_widgets_test.go b/integration/screen_widgets_test.go index cde042d..4c09d8a 100644 --- a/integration/screen_widgets_test.go +++ b/integration/screen_widgets_test.go @@ -1,6 +1,7 @@ package integration import ( + "encoding/json" "testing" "github.com/stretchr/testify/assert" @@ -84,7 +85,7 @@ func TestWidgets(t *testing.T) { ConditionalFormats: []datadog.ConditionalFormat{ { Comparator: datadog.String(">="), - Value: datadog.String("1"), + Value: datadog.JsonNumber(json.Number("1")), Palette: datadog.String("white_on_red"), }}, Aggregator: datadog.String("max"), @@ -122,7 +123,7 @@ func TestWidgets(t *testing.T) { ConditionalFormats: []datadog.ConditionalFormat{ { Comparator: datadog.String(">"), - Value: datadog.String("4"), + Value: datadog.JsonNumber(json.Number("4")), Palette: datadog.String("white_on_green"), }}, }}, diff --git a/integration/screenboards_test.go b/integration/screenboards_test.go index 9263ef0..4d5f11b 100644 --- a/integration/screenboards_test.go +++ b/integration/screenboards_test.go @@ -1,6 +1,7 @@ package integration import ( + "encoding/json" "testing" "github.com/zorkian/go-datadog-api" @@ -94,7 +95,7 @@ func getTestScreenboard() *datadog.Screenboard { return &datadog.Screenboard{ Title: datadog.String("___Test-Board___"), Height: datadog.Int(600), - Width: datadog.Int(800), + Width: datadog.JsonNumber(json.Number("800")), Widgets: []datadog.Widget{}, } } @@ -129,7 +130,7 @@ func assertScreenboardEquals(t *testing.T, actual, expected *datadog.Screenboard t.Errorf("Screenboard title does not match: %s != %s", *actual.Title, *expected.Title) } if *actual.Width != *expected.Width { - t.Errorf("Screenboard width does not match: %d != %d", *actual.Width, *expected.Width) + t.Errorf("Screenboard width does not match: %s != %s", *actual.Width, *expected.Width) } if *actual.Height != *expected.Height { t.Errorf("Screenboard width does not match: %d != %d", *actual.Height, *expected.Height) diff --git a/screen_widgets.go b/screen_widgets.go index 29d2405..cce6f8b 100644 --- a/screen_widgets.go +++ b/screen_widgets.go @@ -81,12 +81,12 @@ type TileDefRequest struct { } type ConditionalFormat struct { - Color *string `json:"color,omitempty"` - Palette *string `json:"palette,omitempty"` - Comparator *string `json:"comparator,omitempty"` - Invert *bool `json:"invert,omitempty"` - Value *string `json:"value,omitempty"` - ImageURL *string `json:"image_url,omitempty"` + Color *string `json:"color,omitempty"` + Palette *string `json:"palette,omitempty"` + Comparator *string `json:"comparator,omitempty"` + Invert *bool `json:"invert,omitempty"` + Value *json.Number `json:"value,omitempty"` + ImageURL *string `json:"image_url,omitempty"` } type TileDefRequestStyle struct { diff --git a/screenboards.go b/screenboards.go index 2786c96..7bc9c94 100644 --- a/screenboards.go +++ b/screenboards.go @@ -9,6 +9,7 @@ package datadog import ( + "encoding/json" "fmt" ) @@ -18,7 +19,7 @@ type Screenboard struct { Id *int `json:"id,omitempty"` Title *string `json:"board_title,omitempty"` Height *int `json:"height,omitempty"` - Width *int `json:"width,omitempty"` + Width *json.Number `json:"width,omitempty"` Shared *bool `json:"shared,omitempty"` TemplateVariables []TemplateVariable `json:"template_variables,omitempty"` Widgets []Widget `json:"widgets"` diff --git a/screenboards_test.go b/screenboards_test.go index 48f5e48..480bd09 100644 --- a/screenboards_test.go +++ b/screenboards_test.go @@ -1,6 +1,7 @@ package datadog import ( + "encoding/json" "io/ioutil" "net/http" "net/http/httptest" @@ -42,9 +43,9 @@ func TestGetScreenboard(t *testing.T) { t.Fatalf("expect height %d. Got %d", expectedHeight, height) } - expectedWidth := 1024 + expectedWidth := json.Number("1024") if width := screenboard.GetWidth(); width != expectedWidth { - t.Fatalf("expect width %d. Got %d", expectedWidth, width) + t.Fatalf("expect width %s. Got %s", expectedWidth, width) } expectedReadOnly := false