From e73e7e0f6db0ea1fe05cc98c415402beeb80641e Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Wed, 31 Oct 2018 13:55:06 +0900 Subject: [PATCH 1/5] fix X,Y Json mapping --- screen_widgets.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/screen_widgets.go b/screen_widgets.go index d5c4d46..282e00e 100644 --- a/screen_widgets.go +++ b/screen_widgets.go @@ -90,8 +90,8 @@ type Widget struct { TitleSize *int `json:"title_size,omitempty"` Height *int `json:"height,omitempty"` Width *int `json:"width,omitempty"` - X *int `json:"y,omitempty"` - Y *int `json:"x,omitempty"` + X *int `json:"x,omitempty"` + Y *int `json:"y,omitempty"` // For Timeseries, TopList, EventTimeline, EvenStream, AlertGraph, CheckStatus, ServiceSummary, LogStream widgets Time *Time `json:"time,omitempty"` From 2de54bc277ac45bc659d81bc2db12fb984f03765 Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Wed, 31 Oct 2018 13:58:17 +0900 Subject: [PATCH 2/5] fix width/height data type to int --- datadog-accessors.go | 20 ++++++++++---------- integration/screenboards_test.go | 11 ++++++----- screenboards.go | 4 ++-- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/datadog-accessors.go b/datadog-accessors.go index 415b353..2e259e3 100644 --- a/datadog-accessors.go +++ b/datadog-accessors.go @@ -6338,18 +6338,18 @@ func (r *Rule) SetTimeframe(v string) { } // GetHeight returns the Height field if non-nil, zero value otherwise. -func (s *Screenboard) GetHeight() string { +func (s *Screenboard) GetHeight() int { if s == nil || s.Height == nil { - return "" + return 0 } 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() (string, bool) { +func (s *Screenboard) GetHeightOk() (int, bool) { if s == nil || s.Height == nil { - return "", false + return 0, false } return *s.Height, true } @@ -6364,7 +6364,7 @@ func (s *Screenboard) HasHeight() bool { } // SetHeight allocates a new s.Height and returns the pointer to it. -func (s *Screenboard) SetHeight(v string) { +func (s *Screenboard) SetHeight(v int) { s.Height = &v } @@ -6493,18 +6493,18 @@ func (s *Screenboard) SetTitle(v string) { } // GetWidth returns the Width field if non-nil, zero value otherwise. -func (s *Screenboard) GetWidth() string { +func (s *Screenboard) GetWidth() int { if s == nil || s.Width == nil { - return "" + return 0 } 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() (string, bool) { +func (s *Screenboard) GetWidthOk() (int, bool) { if s == nil || s.Width == nil { - return "", false + return 0, false } return *s.Width, true } @@ -6519,7 +6519,7 @@ func (s *Screenboard) HasWidth() bool { } // SetWidth allocates a new s.Width and returns the pointer to it. -func (s *Screenboard) SetWidth(v string) { +func (s *Screenboard) SetWidth(v int) { s.Width = &v } diff --git a/integration/screenboards_test.go b/integration/screenboards_test.go index 4afce69..9263ef0 100644 --- a/integration/screenboards_test.go +++ b/integration/screenboards_test.go @@ -1,8 +1,9 @@ package integration import ( - "github.com/zorkian/go-datadog-api" "testing" + + "github.com/zorkian/go-datadog-api" ) func TestScreenboardCreateAndDelete(t *testing.T) { @@ -92,8 +93,8 @@ func TestScreenboardGet(t *testing.T) { func getTestScreenboard() *datadog.Screenboard { return &datadog.Screenboard{ Title: datadog.String("___Test-Board___"), - Height: datadog.String("600"), - Width: datadog.String("800"), + Height: datadog.Int(600), + Width: datadog.Int(800), Widgets: []datadog.Widget{}, } } @@ -128,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: %s != %s", *actual.Width, *expected.Width) + t.Errorf("Screenboard width does not match: %d != %d", *actual.Width, *expected.Width) } if *actual.Height != *expected.Height { - t.Errorf("Screenboard width does not match: %s != %s", *actual.Height, *expected.Height) + t.Errorf("Screenboard width does not match: %d != %d", *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 3bc52a5..2786c96 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 *string `json:"height,omitempty"` - Width *string `json:"width,omitempty"` + Height *int `json:"height,omitempty"` + Width *int `json:"width,omitempty"` Shared *bool `json:"shared,omitempty"` TemplateVariables []TemplateVariable `json:"template_variables,omitempty"` Widgets []Widget `json:"widgets"` From 40a994ded21adf6d27d4b1823fd88485a9ab382c Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Wed, 31 Oct 2018 13:59:01 +0900 Subject: [PATCH 3/5] Add Get Widgets Method to Screenboard --- datadog-accessors.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/datadog-accessors.go b/datadog-accessors.go index 2e259e3..f1acab9 100644 --- a/datadog-accessors.go +++ b/datadog-accessors.go @@ -6523,6 +6523,23 @@ func (s *Screenboard) SetWidth(v int) { s.Width = &v } +// GetWidgets returns the []Widget field if non-nil, zero value otherwise. +func (s *Screenboard) GetWidgets() []Widget { + if s == nil || s.Widgets == nil { + return []Widget{} + } + return s.Widgets +} + +// GetWidgetsByOk returns a tuple with the []Widget field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (s *Screenboard) GetWidgetsByOk() ([]Widget, bool) { + if s == nil || s.Widgets == nil { + return []Widget{}, false + } + return s.Widgets, true +} + // GetId returns the Id field if non-nil, zero value otherwise. func (s *ScreenboardLite) GetId() int { if s == nil || s.Id == nil { From 7ca3ad24ee5e2509d26ed0283f4a7d20a272ad44 Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Wed, 31 Oct 2018 13:59:56 +0900 Subject: [PATCH 4/5] Add get a screenboard api test --- screenboards_test.go | 95 ++++++++++++++++++++++++ tests/fixtures/screenboard_response.json | 19 +++++ 2 files changed, 114 insertions(+) create mode 100644 screenboards_test.go create mode 100644 tests/fixtures/screenboard_response.json diff --git a/screenboards_test.go b/screenboards_test.go new file mode 100644 index 0000000..48f5e48 --- /dev/null +++ b/screenboards_test.go @@ -0,0 +1,95 @@ +package datadog + +import ( + "io/ioutil" + "net/http" + "net/http/httptest" + "testing" +) + +func TestGetScreenboard(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + response, err := ioutil.ReadFile("./tests/fixtures/screenboard_response.json") + if err != nil { + t.Fatal(err) + } + w.Write(response) + })) + defer ts.Close() + + datadogClient := Client{ + baseUrl: ts.URL, + HttpClient: http.DefaultClient, + } + + screenboard, err := datadogClient.GetScreenboard(6334) + if err != nil { + t.Fatal(err) + } + + expectedID := 6334 + if id := screenboard.GetId(); id != expectedID { + t.Fatalf("expect ID %d. Got %d", expectedID, id) + } + + expectedTitle := "dogapi test" + if title := screenboard.GetTitle(); title != expectedTitle { + t.Fatalf("expect title %s. Got %s", expectedTitle, title) + } + + expectedHeight := 768 + if height := screenboard.GetHeight(); height != expectedHeight { + t.Fatalf("expect height %d. Got %d", expectedHeight, height) + } + + expectedWidth := 1024 + if width := screenboard.GetWidth(); width != expectedWidth { + t.Fatalf("expect width %d. Got %d", expectedWidth, width) + } + + expectedReadOnly := false + readOnly, ok := screenboard.GetReadOnlyOk() + if !ok { + t.Fatalf("expect to have a read_only field") + } + + if readOnly != expectedReadOnly { + t.Fatalf("expect read_only %v. Got %v", expectedReadOnly, readOnly) + } + + for _, widget := range screenboard.Widgets { + validateWidget(t, widget) + } +} + +func validateWidget(t *testing.T, wd Widget) { + expectedType := "image" + if widgetType := wd.GetType(); widgetType != expectedType { + t.Fatalf("expect type %s. Got %s", expectedType, widgetType) + } + + expectedHeight := 20 + if height := wd.GetHeight(); height != expectedHeight { + t.Fatalf("expect height %d. Got %d", expectedHeight, height) + } + + expectedWidth := 32 + if width := wd.GetWidth(); width != expectedWidth { + t.Fatalf("expect width %d. Got %d", expectedWidth, width) + } + + expectedX := 32 + if x := wd.GetX(); x != expectedX { + t.Fatalf("expect x %d. Got %d", expectedX, x) + } + + expectedY := 7 + if y := wd.GetY(); y != expectedY { + t.Fatalf("expect y %d. Got %d", expectedY, y) + } + + expectedURL := "http://path/to/image.jpg" + if url := wd.GetURL(); url != expectedURL { + t.Fatalf("expect url %s. Got %s", expectedURL, url) + } +} diff --git a/tests/fixtures/screenboard_response.json b/tests/fixtures/screenboard_response.json new file mode 100644 index 0000000..d83934a --- /dev/null +++ b/tests/fixtures/screenboard_response.json @@ -0,0 +1,19 @@ +{ + "board_title": "dogapi test", + "height": 768, + "id": 6334, + "widgets": [ + { + "height": 20, + "type": "image", + "url": "http://path/to/image.jpg", + "width": 32, + "x": 32, + "y": 7 + } + ], + "width": 1024, + "created": "2015-12-17T23:06:06.703087+00:00", + "modified": "2015-12-17T23:12:26.726234+00:00", + "read_only": false + } \ No newline at end of file From 291e198a60fdea68992b225037fc7c37c0c1e067 Mon Sep 17 00:00:00 2001 From: kterada0509 Date: Wed, 31 Oct 2018 14:21:16 +0900 Subject: [PATCH 5/5] execute make generate --- datadog-accessors.go | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/datadog-accessors.go b/datadog-accessors.go index f1acab9..2e259e3 100644 --- a/datadog-accessors.go +++ b/datadog-accessors.go @@ -6523,23 +6523,6 @@ func (s *Screenboard) SetWidth(v int) { s.Width = &v } -// GetWidgets returns the []Widget field if non-nil, zero value otherwise. -func (s *Screenboard) GetWidgets() []Widget { - if s == nil || s.Widgets == nil { - return []Widget{} - } - return s.Widgets -} - -// GetWidgetsByOk returns a tuple with the []Widget field if it's non-nil, zero value otherwise -// and a boolean to check if the value has been set. -func (s *Screenboard) GetWidgetsByOk() ([]Widget, bool) { - if s == nil || s.Widgets == nil { - return []Widget{}, false - } - return s.Widgets, true -} - // GetId returns the Id field if non-nil, zero value otherwise. func (s *ScreenboardLite) GetId() int { if s == nil || s.Id == nil {