Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix fix screenboard #190

Merged
merged 5 commits into from
Nov 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions datadog-accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}
Expand All @@ -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
}

Expand Down
11 changes: 6 additions & 5 deletions integration/screenboards_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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{},
}
}
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions screen_widgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 2 additions & 2 deletions screenboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
95 changes: 95 additions & 0 deletions screenboards_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
19 changes: 19 additions & 0 deletions tests/fixtures/screenboard_response.json
Original file line number Diff line number Diff line change
@@ -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
}