Skip to content

Commit

Permalink
Fix Width types for when screenboard width is string
Browse files Browse the repository at this point in the history
  • Loading branch information
knqyf263 committed Feb 26, 2019
1 parent b815c45 commit c66708a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 21 deletions.
16 changes: 8 additions & 8 deletions datadog-accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
Expand All @@ -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
}
Expand All @@ -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
}

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

Expand Down
5 changes: 3 additions & 2 deletions integration/screen_widgets_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package integration

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
}},
}},
Expand Down
5 changes: 3 additions & 2 deletions integration/screenboards_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package integration

import (
"encoding/json"
"testing"

"github.com/zorkian/go-datadog-api"
Expand Down Expand Up @@ -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{},
}
}
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions screen_widgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion screenboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package datadog

import (
"encoding/json"
"fmt"
)

Expand All @@ -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"`
Expand Down
5 changes: 3 additions & 2 deletions screenboards_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package datadog

import (
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c66708a

Please sign in to comment.