-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd6f675
commit 643a7df
Showing
2 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
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) | ||
} | ||
|
||
widgets, ok := screenboard.GetWidgetsByOk() | ||
if !ok { | ||
t.Fatal("expect widgets field to exist") | ||
} | ||
for _, widget := range 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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |