diff --git a/datadog-accessors.go b/datadog-accessors.go index 5f6589f..5deeda0 100644 --- a/datadog-accessors.go +++ b/datadog-accessors.go @@ -6400,18 +6400,18 @@ func (r *Rule) SetTimeframe(v string) { } // GetHeight returns the Height field if non-nil, zero value otherwise. -func (s *Screenboard) GetHeight() int { +func (s *Screenboard) GetHeight() StrintD { if s == nil || s.Height == nil { - return 0 + return "" } return *s.Height } // GetHeightOk returns a tuple with the Height field if it's non-nil, zero value otherwise // and a boolean to check if the value has been set. -func (s *Screenboard) GetHeightOk() (int, bool) { +func (s *Screenboard) GetHeightOk() (StrintD, bool) { if s == nil || s.Height == nil { - return 0, false + return "", false } return *s.Height, true } @@ -6426,7 +6426,7 @@ func (s *Screenboard) HasHeight() bool { } // SetHeight allocates a new s.Height and returns the pointer to it. -func (s *Screenboard) SetHeight(v int) { +func (s *Screenboard) SetHeight(v StrintD) { s.Height = &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() StrintD { 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() (StrintD, 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 StrintD) { s.Width = &v } diff --git a/integration/screenboards_test.go b/integration/screenboards_test.go index 9263ef0..9d7e534 100644 --- a/integration/screenboards_test.go +++ b/integration/screenboards_test.go @@ -3,7 +3,7 @@ package integration import ( "testing" - "github.com/zorkian/go-datadog-api" + datadog "github.com/zorkian/go-datadog-api" ) func TestScreenboardCreateAndDelete(t *testing.T) { @@ -93,8 +93,8 @@ func TestScreenboardGet(t *testing.T) { func getTestScreenboard() *datadog.Screenboard { return &datadog.Screenboard{ Title: datadog.String("___Test-Board___"), - Height: datadog.Int(600), - Width: datadog.Int(800), + Height: datadog.Strint("600"), + Width: datadog.Strint("800"), Widgets: []datadog.Widget{}, } } @@ -129,10 +129,10 @@ 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) + t.Errorf("Screenboard width does not match: %s != %s", *actual.Height, *expected.Height) } if len(actual.Widgets) != len(expected.Widgets) { t.Errorf("Number of Screenboard widgets does not match: %d != %d", len(actual.Widgets), len(expected.Widgets)) diff --git a/screenboards.go b/screenboards.go index 2786c96..2de8932 100644 --- a/screenboards.go +++ b/screenboards.go @@ -17,8 +17,8 @@ import ( type Screenboard struct { Id *int `json:"id,omitempty"` Title *string `json:"board_title,omitempty"` - Height *int `json:"height,omitempty"` - Width *int `json:"width,omitempty"` + Height *StrintD `json:"height,omitempty"` + Width *StrintD `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 c89543e..319c777 100644 --- a/screenboards_test.go +++ b/screenboards_test.go @@ -11,68 +11,89 @@ import ( ) func TestGetScreenboard(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - response, err := ioutil.ReadFile("./testdata/fixtures/screenboard_response.json") - if err != nil { - // mustn't call t.Fatal from a different Goroutine - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - w.Write(response) - })) - defer ts.Close() - - datadogClient := Client{ - baseUrl: ts.URL, - HttpClient: ts.Client(), - RetryTimeout: 5 * time.Second, - } - - got, err := datadogClient.GetScreenboard(6334) - if err != nil { - t.Fatal(err) - } - - want := &Screenboard{ - Id: Int(6334), - Title: String("dogapi test"), - Height: Int(768), - Width: Int(1024), - ReadOnly: Bool(false), - Widgets: []Widget{ - Widget{ - Type: String("image"), - Height: Int(20), - Width: Int(32), - X: Int(32), - Y: Int(7), - URL: String("http://path/to/image.jpg"), - }, - Widget{ - Type: String("timeseries"), - TileDef: &TileDef{ - Precision: Strint("42"), + tests := []struct { + file string + want *Screenboard + }{ + { + file: "screenboard_response", + want: &Screenboard{ + Id: Int(6334), + Title: String("dogapi test"), + Height: Strint("768"), + Width: Strint("1024"), + ReadOnly: Bool(false), + Widgets: []Widget{ + Widget{ + Type: String("image"), + Height: Int(20), + Width: Int(32), + X: Int(32), + Y: Int(7), + URL: String("http://path/to/image.jpg"), + }, + Widget{ + Type: String("timeseries"), + TileDef: &TileDef{ + Precision: Strint("42"), + }, + }, + Widget{ + Type: String("timeseries"), + TileDef: &TileDef{ + Precision: Strint("*"), + }, + }, }, }, - Widget{ - Type: String("timeseries"), - TileDef: &TileDef{ - Precision: Strint("*"), - }, + }, + { + file: "screenboard_response_fullscreen", + want: &Screenboard{ + Id: Int(6335), + Title: String("dogapi fullscreen test"), + Height: Strint("100%"), + Width: Strint("100%"), + ReadOnly: Bool(false), }, }, } + for _, tt := range tests { + t.Run(tt.file, func(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + response, err := ioutil.ReadFile("./testdata/fixtures/" + tt.file + ".json") + if err != nil { + // mustn't call t.Fatal from a different Goroutine + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + w.Write(response) + })) + defer ts.Close() + + datadogClient := Client{ + baseUrl: ts.URL, + HttpClient: ts.Client(), + RetryTimeout: 5 * time.Second, + } + + got, err := datadogClient.GetScreenboard(6334) + if err != nil { + t.Fatal(err) + } - if !reflect.DeepEqual(got, want) { - // Go formatting doesn't handle pointers gracefully, so we'll display the diff as JSON - gotJSON, err := json.MarshalIndent(got, "", "\t") - if err != nil { - t.Fatal(err) - } - wantJSON, err := json.MarshalIndent(want, "", "\t") - if err != nil { - t.Fatal(err) - } - t.Errorf("got:\n%s\nwant:\n%s", gotJSON, wantJSON) + if !reflect.DeepEqual(got, tt.want) { + // Go formatting doesn't handle pointers gracefully, so we'll display the diff as JSON + gotJSON, err := json.MarshalIndent(got, "", "\t") + if err != nil { + t.Fatal(err) + } + wantJSON, err := json.MarshalIndent(tt.want, "", "\t") + if err != nil { + t.Fatal(err) + } + t.Errorf("got:\n%s\nwant:\n%s", gotJSON, wantJSON) + } + }) } } diff --git a/testdata/fixtures/screenboard_response_fullscreen.json b/testdata/fixtures/screenboard_response_fullscreen.json new file mode 100644 index 0000000..f20bd03 --- /dev/null +++ b/testdata/fixtures/screenboard_response_fullscreen.json @@ -0,0 +1,9 @@ +{ + "board_title": "dogapi fullscreen test", + "id": 6335, + "height": "100%", + "width": "100%", + "created": "2019-03-01T13:37:00.420042+01:00", + "modified": "2019-03-01T15:25:26.726234+01:00", + "read_only": false +}