fix up some other badly saved deps.
237e257f37
was probably done with an older
version of godep
This commit is contained in:
parent
8ce04586e0
commit
8a9b0f6628
|
@ -1,117 +0,0 @@
|
|||
package backoff
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
// This is an example that demonstrates how this package could be used
|
||||
// to perform various advanced operations.
|
||||
//
|
||||
// It executes an HTTP GET request with exponential backoff,
|
||||
// while errors are logged and failed responses are closed, as required by net/http package.
|
||||
//
|
||||
// Note we define a condition function which is used inside the operation to
|
||||
// determine whether the operation succeeded or failed.
|
||||
func Example() error {
|
||||
res, err := GetWithRetry(
|
||||
"http://localhost:9999",
|
||||
ErrorIfStatusCodeIsNot(http.StatusOK),
|
||||
NewExponentialBackOff())
|
||||
|
||||
if err != nil {
|
||||
// Close response body of last (failed) attempt.
|
||||
// The Last attempt isn't handled by the notify-on-error function,
|
||||
// which closes the body of all the previous attempts.
|
||||
if e := res.Body.Close(); e != nil {
|
||||
log.Printf("error closing last attempt's response body: %s", e)
|
||||
}
|
||||
log.Printf("too many failed request attempts: %s", err)
|
||||
return err
|
||||
}
|
||||
defer res.Body.Close() // The response's Body must be closed.
|
||||
|
||||
// Read body
|
||||
_, _ = ioutil.ReadAll(res.Body)
|
||||
|
||||
// Do more stuff
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetWithRetry is a helper function that performs an HTTP GET request
|
||||
// to the given URL, and retries with the given backoff using the given condition function.
|
||||
//
|
||||
// It also uses a notify-on-error function which logs
|
||||
// and closes the response body of the failed request.
|
||||
func GetWithRetry(url string, condition Condition, bck BackOff) (*http.Response, error) {
|
||||
var res *http.Response
|
||||
err := RetryNotify(
|
||||
func() error {
|
||||
var err error
|
||||
res, err = http.Get(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return condition(res)
|
||||
},
|
||||
bck,
|
||||
LogAndClose())
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
||||
// Condition is a retry condition function.
|
||||
// It receives a response, and returns an error
|
||||
// if the response failed the condition.
|
||||
type Condition func(*http.Response) error
|
||||
|
||||
// ErrorIfStatusCodeIsNot returns a retry condition function.
|
||||
// The condition returns an error
|
||||
// if the given response's status code is not the given HTTP status code.
|
||||
func ErrorIfStatusCodeIsNot(status int) Condition {
|
||||
return func(res *http.Response) error {
|
||||
if res.StatusCode != status {
|
||||
return NewError(res)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Error is returned on ErrorIfX() condition functions throughout this package.
|
||||
type Error struct {
|
||||
Response *http.Response
|
||||
}
|
||||
|
||||
func NewError(res *http.Response) *Error {
|
||||
// Sanity check
|
||||
if res == nil {
|
||||
panic("response object is nil")
|
||||
}
|
||||
return &Error{Response: res}
|
||||
}
|
||||
func (err *Error) Error() string { return "request failed" }
|
||||
|
||||
// LogAndClose is a notify-on-error function.
|
||||
// It logs the error and closes the response body.
|
||||
func LogAndClose() Notify {
|
||||
return func(err error, wait time.Duration) {
|
||||
switch e := err.(type) {
|
||||
case *Error:
|
||||
defer e.Response.Body.Close()
|
||||
|
||||
b, err := ioutil.ReadAll(e.Response.Body)
|
||||
var body string
|
||||
if err != nil {
|
||||
body = "can't read body"
|
||||
} else {
|
||||
body = string(b)
|
||||
}
|
||||
|
||||
log.Printf("%s: %s", e.Response.Status, body)
|
||||
default:
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package backoff
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestNextBackOffMillis(t *testing.T) {
|
||||
subtestNextBackOff(t, 0, new(ZeroBackOff))
|
||||
subtestNextBackOff(t, Stop, new(StopBackOff))
|
||||
}
|
||||
|
||||
func subtestNextBackOff(t *testing.T, expectedValue time.Duration, backOffPolicy BackOff) {
|
||||
for i := 0; i < 10; i++ {
|
||||
next := backOffPolicy.NextBackOff()
|
||||
if next != expectedValue {
|
||||
t.Errorf("got: %d expected: %d", next, expectedValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConstantBackOff(t *testing.T) {
|
||||
backoff := NewConstantBackOff(time.Second)
|
||||
if backoff.NextBackOff() != time.Second {
|
||||
t.Error("invalid interval")
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
package backoff
|
||||
|
||||
import "log"
|
||||
|
||||
func ExampleRetry() error {
|
||||
operation := func() error {
|
||||
// An operation that might fail.
|
||||
return nil // or return errors.New("some error")
|
||||
}
|
||||
|
||||
err := Retry(operation, NewExponentialBackOff())
|
||||
if err != nil {
|
||||
// Handle error.
|
||||
return err
|
||||
}
|
||||
|
||||
// Operation is successful.
|
||||
return nil
|
||||
}
|
||||
|
||||
func ExampleTicker() error {
|
||||
operation := func() error {
|
||||
// An operation that might fail
|
||||
return nil // or return errors.New("some error")
|
||||
}
|
||||
|
||||
b := NewExponentialBackOff()
|
||||
ticker := NewTicker(b)
|
||||
|
||||
var err error
|
||||
|
||||
// Ticks will continue to arrive when the previous operation is still running,
|
||||
// so operations that take a while to fail could run in quick succession.
|
||||
for _ = range ticker.C {
|
||||
if err = operation(); err != nil {
|
||||
log.Println(err, "will retry...")
|
||||
continue
|
||||
}
|
||||
|
||||
ticker.Stop()
|
||||
break
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
// Operation has failed.
|
||||
return err
|
||||
}
|
||||
|
||||
// Operation is successful.
|
||||
return nil
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
package backoff
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestBackOff(t *testing.T) {
|
||||
var (
|
||||
testInitialInterval = 500 * time.Millisecond
|
||||
testRandomizationFactor = 0.1
|
||||
testMultiplier = 2.0
|
||||
testMaxInterval = 5 * time.Second
|
||||
testMaxElapsedTime = 15 * time.Minute
|
||||
)
|
||||
|
||||
exp := NewExponentialBackOff()
|
||||
exp.InitialInterval = testInitialInterval
|
||||
exp.RandomizationFactor = testRandomizationFactor
|
||||
exp.Multiplier = testMultiplier
|
||||
exp.MaxInterval = testMaxInterval
|
||||
exp.MaxElapsedTime = testMaxElapsedTime
|
||||
exp.Reset()
|
||||
|
||||
var expectedResults = []time.Duration{500, 1000, 2000, 4000, 5000, 5000, 5000, 5000, 5000, 5000}
|
||||
for i, d := range expectedResults {
|
||||
expectedResults[i] = d * time.Millisecond
|
||||
}
|
||||
|
||||
for _, expected := range expectedResults {
|
||||
assertEquals(t, expected, exp.currentInterval)
|
||||
// Assert that the next backoff falls in the expected range.
|
||||
var minInterval = expected - time.Duration(testRandomizationFactor*float64(expected))
|
||||
var maxInterval = expected + time.Duration(testRandomizationFactor*float64(expected))
|
||||
var actualInterval = exp.NextBackOff()
|
||||
if !(minInterval <= actualInterval && actualInterval <= maxInterval) {
|
||||
t.Error("error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetRandomizedInterval(t *testing.T) {
|
||||
// 33% chance of being 1.
|
||||
assertEquals(t, 1, getRandomValueFromInterval(0.5, 0, 2))
|
||||
assertEquals(t, 1, getRandomValueFromInterval(0.5, 0.33, 2))
|
||||
// 33% chance of being 2.
|
||||
assertEquals(t, 2, getRandomValueFromInterval(0.5, 0.34, 2))
|
||||
assertEquals(t, 2, getRandomValueFromInterval(0.5, 0.66, 2))
|
||||
// 33% chance of being 3.
|
||||
assertEquals(t, 3, getRandomValueFromInterval(0.5, 0.67, 2))
|
||||
assertEquals(t, 3, getRandomValueFromInterval(0.5, 0.99, 2))
|
||||
}
|
||||
|
||||
type TestClock struct {
|
||||
i time.Duration
|
||||
start time.Time
|
||||
}
|
||||
|
||||
func (c *TestClock) Now() time.Time {
|
||||
t := c.start.Add(c.i)
|
||||
c.i += time.Second
|
||||
return t
|
||||
}
|
||||
|
||||
func TestGetElapsedTime(t *testing.T) {
|
||||
var exp = NewExponentialBackOff()
|
||||
exp.Clock = &TestClock{}
|
||||
exp.Reset()
|
||||
|
||||
var elapsedTime = exp.GetElapsedTime()
|
||||
if elapsedTime != time.Second {
|
||||
t.Errorf("elapsedTime=%d", elapsedTime)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMaxElapsedTime(t *testing.T) {
|
||||
var exp = NewExponentialBackOff()
|
||||
exp.Clock = &TestClock{start: time.Time{}.Add(10000 * time.Second)}
|
||||
// Change the currentElapsedTime to be 0 ensuring that the elapsed time will be greater
|
||||
// than the max elapsed time.
|
||||
exp.startTime = time.Time{}
|
||||
assertEquals(t, Stop, exp.NextBackOff())
|
||||
}
|
||||
|
||||
func TestBackOffOverflow(t *testing.T) {
|
||||
var (
|
||||
testInitialInterval time.Duration = math.MaxInt64 / 2
|
||||
testMaxInterval time.Duration = math.MaxInt64
|
||||
testMultiplier = 2.1
|
||||
)
|
||||
|
||||
exp := NewExponentialBackOff()
|
||||
exp.InitialInterval = testInitialInterval
|
||||
exp.Multiplier = testMultiplier
|
||||
exp.MaxInterval = testMaxInterval
|
||||
exp.Reset()
|
||||
|
||||
exp.NextBackOff()
|
||||
// Assert that when an overflow is possible the current varerval time.Duration is set to the max varerval time.Duration .
|
||||
assertEquals(t, testMaxInterval, exp.currentInterval)
|
||||
}
|
||||
|
||||
func assertEquals(t *testing.T, expected, value time.Duration) {
|
||||
if expected != value {
|
||||
t.Errorf("got: %d, expected: %d", value, expected)
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package backoff
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRetry(t *testing.T) {
|
||||
const successOn = 3
|
||||
var i = 0
|
||||
|
||||
// This function is successfull on "successOn" calls.
|
||||
f := func() error {
|
||||
i++
|
||||
log.Printf("function is called %d. time\n", i)
|
||||
|
||||
if i == successOn {
|
||||
log.Println("OK")
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Println("error")
|
||||
return errors.New("error")
|
||||
}
|
||||
|
||||
err := Retry(f, NewExponentialBackOff())
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %s", err.Error())
|
||||
}
|
||||
if i != successOn {
|
||||
t.Errorf("invalid number of retries: %d", i)
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package backoff
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTicker(t *testing.T) {
|
||||
const successOn = 3
|
||||
var i = 0
|
||||
|
||||
// This function is successfull on "successOn" calls.
|
||||
f := func() error {
|
||||
i++
|
||||
log.Printf("function is called %d. time\n", i)
|
||||
|
||||
if i == successOn {
|
||||
log.Println("OK")
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Println("error")
|
||||
return errors.New("error")
|
||||
}
|
||||
|
||||
b := NewExponentialBackOff()
|
||||
ticker := NewTicker(b)
|
||||
|
||||
var err error
|
||||
for _ = range ticker.C {
|
||||
if err = f(); err != nil {
|
||||
t.Log(err)
|
||||
continue
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %s", err.Error())
|
||||
}
|
||||
if i != successOn {
|
||||
t.Errorf("invalid number of retries: %d", i)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
*.sublime*
|
||||
cmd
|
|
@ -0,0 +1,21 @@
|
|||
language: go
|
||||
|
||||
go:
|
||||
- 1.4
|
||||
- 1.5
|
||||
- tip
|
||||
|
||||
env:
|
||||
- "PATH=/home/travis/gopath/bin:$PATH"
|
||||
script:
|
||||
- go get -u github.com/golang/lint/golint
|
||||
- golint ./...
|
||||
- test `gofmt -l . | wc -l` = 0
|
||||
- make test
|
||||
|
||||
install:
|
||||
- go get -v -t . && make updatedeps
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- go: tip
|
|
@ -1,138 +0,0 @@
|
|||
package integration
|
||||
|
||||
import (
|
||||
"github.com/zorkian/go-datadog-api"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func init() {
|
||||
client = initTest()
|
||||
}
|
||||
|
||||
func TestCreateAndDeleteDashboard(t *testing.T) {
|
||||
expected := getTestDashboard()
|
||||
// create the dashboard and compare it
|
||||
actual, err := client.CreateDashboard(expected)
|
||||
if err != nil {
|
||||
t.Fatalf("Creating a dashboard failed when it shouldn't. (%s)", err)
|
||||
}
|
||||
|
||||
defer cleanUpDashboard(t, actual.Id)
|
||||
|
||||
assertDashboardEquals(t, actual, expected)
|
||||
|
||||
// now try to fetch it freshly and compare it again
|
||||
actual, err = client.GetDashboard(actual.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving a dashboard failed when it shouldn't. (%s)", err)
|
||||
}
|
||||
assertDashboardEquals(t, actual, expected)
|
||||
|
||||
}
|
||||
|
||||
func TestUpdateDashboard(t *testing.T) {
|
||||
expected := getTestDashboard()
|
||||
board, err := client.CreateDashboard(expected)
|
||||
if err != nil {
|
||||
t.Fatalf("Creating a dashboard failed when it shouldn't. (%s)", err)
|
||||
}
|
||||
|
||||
defer cleanUpDashboard(t, board.Id)
|
||||
board.Title = "___New-Test-Board___"
|
||||
|
||||
if err := client.UpdateDashboard(board); err != nil {
|
||||
t.Fatalf("Updating a dashboard failed when it shouldn't: %s", err)
|
||||
}
|
||||
|
||||
actual, err := client.GetDashboard(board.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving a dashboard failed when it shouldn't: %s", err)
|
||||
}
|
||||
|
||||
assertDashboardEquals(t, actual, board)
|
||||
}
|
||||
|
||||
func TestGetDashboards(t *testing.T) {
|
||||
boards, err := client.GetDashboards()
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving dashboards failed when it shouldn't: %s", err)
|
||||
}
|
||||
|
||||
num := len(boards)
|
||||
board := createTestDashboard(t)
|
||||
defer cleanUpDashboard(t, board.Id)
|
||||
|
||||
boards, err = client.GetDashboards()
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving dashboards failed when it shouldn't: %s", err)
|
||||
}
|
||||
|
||||
if num+1 != len(boards) {
|
||||
t.Fatalf("Number of dashboards didn't match expected: %d != %d", len(boards), num+1)
|
||||
}
|
||||
}
|
||||
|
||||
func getTestDashboard() *datadog.Dashboard {
|
||||
return &datadog.Dashboard{
|
||||
Title: "___Test-Board___",
|
||||
Description: "Testboard description",
|
||||
TemplateVariables: []datadog.TemplateVariable{},
|
||||
Graphs: createGraph(),
|
||||
}
|
||||
}
|
||||
|
||||
func createTestDashboard(t *testing.T) *datadog.Dashboard {
|
||||
board := getTestDashboard()
|
||||
board, err := client.CreateDashboard(board)
|
||||
if err != nil {
|
||||
t.Fatalf("Creating a dashboard failed when it shouldn't: %s", err)
|
||||
}
|
||||
|
||||
return board
|
||||
}
|
||||
|
||||
func cleanUpDashboard(t *testing.T, id int) {
|
||||
if err := client.DeleteDashboard(id); err != nil {
|
||||
t.Fatalf("Deleting a dashboard failed when it shouldn't. Manual cleanup needed. (%s)", err)
|
||||
}
|
||||
|
||||
deletedBoard, err := client.GetDashboard(id)
|
||||
if deletedBoard != nil {
|
||||
t.Fatal("Dashboard hasn't been deleted when it should have been. Manual cleanup needed.")
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
t.Fatal("Fetching deleted dashboard didn't lead to an error. Manual cleanup needed.")
|
||||
}
|
||||
}
|
||||
|
||||
type TestGraphDefintionRequests struct {
|
||||
Query string `json:"q"`
|
||||
Stacked bool `json:"stacked"`
|
||||
}
|
||||
|
||||
func createGraph() []datadog.Graph {
|
||||
graphDefinition := datadog.Graph{}.Definition
|
||||
graphDefinition.Viz = "timeseries"
|
||||
r := datadog.Graph{}.Definition.Requests
|
||||
graphDefinition.Requests = append(r, TestGraphDefintionRequests{Query: "avg:system.mem.free{*}", Stacked: false})
|
||||
graph := datadog.Graph{Title: "Mandatory graph", Definition: graphDefinition}
|
||||
graphs := []datadog.Graph{}
|
||||
graphs = append(graphs, graph)
|
||||
return graphs
|
||||
}
|
||||
|
||||
func assertDashboardEquals(t *testing.T, actual, expected *datadog.Dashboard) {
|
||||
if actual.Title != expected.Title {
|
||||
t.Errorf("Dashboard title does not match: %s != %s", actual.Title, expected.Title)
|
||||
}
|
||||
if actual.Description != expected.Description {
|
||||
t.Errorf("Dashboard description does not match: %s != %s", actual.Description, expected.Description)
|
||||
}
|
||||
if len(actual.Graphs) != len(expected.Graphs) {
|
||||
t.Errorf("Number of Dashboard graphs does not match: %d != %d", len(actual.Graphs), len(expected.Graphs))
|
||||
}
|
||||
if len(actual.TemplateVariables) != len(expected.TemplateVariables) {
|
||||
t.Errorf("Number of Dashboard template variables does not match: %d != %d", len(actual.TemplateVariables), len(expected.TemplateVariables))
|
||||
}
|
||||
}
|
|
@ -1,110 +0,0 @@
|
|||
package integration
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/zorkian/go-datadog-api"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func init() {
|
||||
client = initTest()
|
||||
}
|
||||
|
||||
func TestCreateAndDeleteDowntime(t *testing.T) {
|
||||
expected := getTestDowntime()
|
||||
// create the downtime and compare it
|
||||
actual := createTestDowntime(t)
|
||||
defer cleanUpDowntime(t, actual.Id)
|
||||
|
||||
// Set ID of our original struct to zero we we can easily compare the results
|
||||
expected.Id = actual.Id
|
||||
assert.Equal(t, expected, actual)
|
||||
|
||||
actual, err := client.GetDowntime(actual.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving a downtime failed when it shouldn't: (%s)", err)
|
||||
}
|
||||
assert.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestUpdateDowntime(t *testing.T) {
|
||||
|
||||
downtime := createTestDowntime(t)
|
||||
|
||||
downtime.Scope = []string{"env:downtime_test", "env:downtime_test2"}
|
||||
defer cleanUpDowntime(t, downtime.Id)
|
||||
|
||||
if err := client.UpdateDowntime(downtime); err != nil {
|
||||
t.Fatalf("Updating a downtime failed when it shouldn't: %s", err)
|
||||
}
|
||||
|
||||
actual, err := client.GetDowntime(downtime.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving a downtime failed when it shouldn't: %s", err)
|
||||
}
|
||||
|
||||
assert.Equal(t, downtime, actual)
|
||||
|
||||
}
|
||||
|
||||
func TestGetDowntime(t *testing.T) {
|
||||
downtimes, err := client.GetDowntimes()
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving downtimes failed when it shouldn't: %s", err)
|
||||
}
|
||||
num := len(downtimes)
|
||||
|
||||
downtime := createTestDowntime(t)
|
||||
defer cleanUpDowntime(t, downtime.Id)
|
||||
|
||||
downtimes, err = client.GetDowntimes()
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving downtimes failed when it shouldn't: %s", err)
|
||||
}
|
||||
|
||||
if num+1 != len(downtimes) {
|
||||
t.Fatalf("Number of downtimes didn't match expected: %d != %d", len(downtimes), num+1)
|
||||
}
|
||||
}
|
||||
|
||||
func getTestDowntime() *datadog.Downtime {
|
||||
|
||||
r := &datadog.Recurrence{
|
||||
Type: "weeks",
|
||||
Period: 1,
|
||||
WeekDays: []string{"Mon", "Tue", "Wed", "Thu", "Fri"},
|
||||
}
|
||||
|
||||
return &datadog.Downtime{
|
||||
Message: "Test downtime message",
|
||||
Scope: []string{"env:downtime_test"},
|
||||
Start: 1577836800,
|
||||
End: 1577840400,
|
||||
Recurrence: r,
|
||||
}
|
||||
}
|
||||
|
||||
func createTestDowntime(t *testing.T) *datadog.Downtime {
|
||||
downtime := getTestDowntime()
|
||||
downtime, err := client.CreateDowntime(downtime)
|
||||
if err != nil {
|
||||
t.Fatalf("Creating a downtime failed when it shouldn't: %s", err)
|
||||
}
|
||||
|
||||
return downtime
|
||||
}
|
||||
|
||||
func cleanUpDowntime(t *testing.T, id int) {
|
||||
if err := client.DeleteDowntime(id); err != nil {
|
||||
t.Fatalf("Deleting a downtime failed when it shouldn't. Manual cleanup needed. (%s)", err)
|
||||
}
|
||||
|
||||
deletedDowntime, err := client.GetDowntime(id)
|
||||
if deletedDowntime != nil && deletedDowntime.Canceled == 0 {
|
||||
t.Fatal("Downtime hasn't been deleted when it should have been. Manual cleanup needed.")
|
||||
}
|
||||
|
||||
if err == nil && deletedDowntime.Canceled == 0 {
|
||||
t.Fatal("Fetching deleted downtime didn't lead to an error and downtime Canceled not set.")
|
||||
}
|
||||
}
|
|
@ -1,152 +0,0 @@
|
|||
package integration
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/zorkian/go-datadog-api"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func init() {
|
||||
client = initTest()
|
||||
}
|
||||
|
||||
func TestCreateAndDeleteMonitor(t *testing.T) {
|
||||
expected := getTestMonitor()
|
||||
// create the monitor and compare it
|
||||
actual := createTestMonitor(t)
|
||||
defer cleanUpMonitor(t, actual.Id)
|
||||
|
||||
// Set ID of our original struct to zero we we can easily compare the results
|
||||
expected.Id = actual.Id
|
||||
assert.Equal(t, expected, actual)
|
||||
|
||||
actual, err := client.GetMonitor(actual.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving a monitor failed when it shouldn't: (%s)", err)
|
||||
}
|
||||
assert.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestUpdateMonitor(t *testing.T) {
|
||||
|
||||
monitor := createTestMonitor(t)
|
||||
defer cleanUpMonitor(t, monitor.Id)
|
||||
|
||||
monitor.Name = "___New-Test-Monitor___"
|
||||
if err := client.UpdateMonitor(monitor); err != nil {
|
||||
t.Fatalf("Updating a monitor failed when it shouldn't: %s", err)
|
||||
}
|
||||
|
||||
actual, err := client.GetMonitor(monitor.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving a monitor failed when it shouldn't: %s", err)
|
||||
}
|
||||
|
||||
assert.Equal(t, monitor, actual)
|
||||
|
||||
}
|
||||
|
||||
func TestGetMonitor(t *testing.T) {
|
||||
monitors, err := client.GetMonitors()
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving monitors failed when it shouldn't: %s", err)
|
||||
}
|
||||
num := len(monitors)
|
||||
|
||||
monitor := createTestMonitor(t)
|
||||
defer cleanUpMonitor(t, monitor.Id)
|
||||
|
||||
monitors, err = client.GetMonitors()
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving monitors failed when it shouldn't: %s", err)
|
||||
}
|
||||
|
||||
if num+1 != len(monitors) {
|
||||
t.Fatalf("Number of monitors didn't match expected: %d != %d", len(monitors), num+1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMuteUnmuteMonitor(t *testing.T) {
|
||||
monitor := createTestMonitor(t)
|
||||
defer cleanUpMonitor(t, monitor.Id)
|
||||
|
||||
// Mute
|
||||
err := client.MuteMonitor(monitor.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to mute monitor")
|
||||
|
||||
}
|
||||
|
||||
monitor, err = client.GetMonitor(monitor.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving monitors failed when it shouldn't: %s", err)
|
||||
}
|
||||
|
||||
// Mute without options will result in monitor.Options.Silenced
|
||||
// to have a key of "*" with value 0
|
||||
assert.Equal(t, 0, monitor.Options.Silenced["*"])
|
||||
|
||||
// Unmute
|
||||
err = client.UnmuteMonitor(monitor.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to unmute monitor")
|
||||
}
|
||||
|
||||
// Update remote state
|
||||
monitor, err = client.GetMonitor(monitor.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving monitors failed when it shouldn't: %s", err)
|
||||
}
|
||||
|
||||
// Assert this map is empty
|
||||
assert.Equal(t, 0, len(monitor.Options.Silenced))
|
||||
}
|
||||
|
||||
/*
|
||||
Testing of global mute and unmuting has not been added for following reasons:
|
||||
* Disabling and enabling of global monitoring does an @all mention which is noisy
|
||||
* It exposes risk to users that run integration tests in their main account
|
||||
* There is no endpoint to verify success
|
||||
*/
|
||||
|
||||
func getTestMonitor() *datadog.Monitor {
|
||||
|
||||
o := datadog.Options{
|
||||
NotifyNoData: true,
|
||||
NoDataTimeframe: 60,
|
||||
Silenced: map[string]int{},
|
||||
}
|
||||
|
||||
return &datadog.Monitor{
|
||||
Message: "Test message",
|
||||
Query: "avg(last_15m):avg:system.disk.in_use{*} by {host,device} > 0.8",
|
||||
Name: "Test monitor",
|
||||
Options: o,
|
||||
Type: "metric alert",
|
||||
}
|
||||
}
|
||||
|
||||
func createTestMonitor(t *testing.T) *datadog.Monitor {
|
||||
monitor := getTestMonitor()
|
||||
monitor, err := client.CreateMonitor(monitor)
|
||||
if err != nil {
|
||||
t.Fatalf("Creating a monitor failed when it shouldn't: %s", err)
|
||||
}
|
||||
|
||||
return monitor
|
||||
}
|
||||
|
||||
func cleanUpMonitor(t *testing.T, id int) {
|
||||
if err := client.DeleteMonitor(id); err != nil {
|
||||
t.Fatalf("Deleting a monitor failed when it shouldn't. Manual cleanup needed. (%s)", err)
|
||||
}
|
||||
|
||||
deletedMonitor, err := client.GetMonitor(id)
|
||||
if deletedMonitor != nil {
|
||||
t.Fatal("Monitor hasn't been deleted when it should have been. Manual cleanup needed.")
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
t.Fatal("Fetching deleted monitor didn't lead to an error.")
|
||||
}
|
||||
}
|
|
@ -1,766 +0,0 @@
|
|||
package integration
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/zorkian/go-datadog-api"
|
||||
)
|
||||
|
||||
func TestAlertValueWidget(t *testing.T) {
|
||||
board := createTestScreenboard(t)
|
||||
defer cleanUpScreenboard(t, board.Id)
|
||||
|
||||
expected := datadog.Widget{}.AlertValueWidget
|
||||
|
||||
expected.X = 1
|
||||
expected.Y = 1
|
||||
expected.Width = 5
|
||||
expected.Height = 5
|
||||
expected.TitleText = "foo"
|
||||
expected.TitleAlign = "center"
|
||||
expected.TitleSize = 1
|
||||
expected.Title = true
|
||||
expected.TextSize = "auto"
|
||||
expected.Precision = 2
|
||||
expected.AlertId = 1
|
||||
expected.Type = "alert_value"
|
||||
expected.Unit = "auto"
|
||||
expected.AddTimeframe = false
|
||||
|
||||
w := datadog.Widget{AlertValueWidget: expected}
|
||||
|
||||
board.Widgets = append(board.Widgets, w)
|
||||
|
||||
if err := client.UpdateScreenboard(board); err != nil {
|
||||
t.Fatalf("Updating a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actual, err := client.GetScreenboard(board.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actualWidget := actual.Widgets[0].AlertValueWidget
|
||||
|
||||
assertEquals(t, "x", actualWidget.X, expected.X)
|
||||
assertEquals(t, "y", actualWidget.Y, expected.Y)
|
||||
assertEquals(t, "height", actualWidget.Height, expected.Height)
|
||||
assertEquals(t, "width", actualWidget.Width, expected.Width)
|
||||
assertEquals(t, "title_text", actualWidget.TitleText, expected.TitleText)
|
||||
assertEquals(t, "title_size", actualWidget.TitleSize, expected.TitleSize)
|
||||
assertEquals(t, "title_align", actualWidget.TitleAlign, expected.TitleAlign)
|
||||
assertEquals(t, "title", actualWidget.Title, expected.Title)
|
||||
assertEquals(t, "text_size", actualWidget.TextSize, expected.TextSize)
|
||||
assertEquals(t, "precision", actualWidget.Precision, expected.Precision)
|
||||
assertEquals(t, "alert_id", actualWidget.AlertId, expected.AlertId)
|
||||
assertEquals(t, "type", actualWidget.Type, expected.Type)
|
||||
assertEquals(t, "unit", actualWidget.Unit, expected.Unit)
|
||||
assertEquals(t, "add_timeframe", actualWidget.AddTimeframe, expected.AddTimeframe)
|
||||
}
|
||||
|
||||
func TestChangeWidget(t *testing.T) {
|
||||
board := createTestScreenboard(t)
|
||||
defer cleanUpScreenboard(t, board.Id)
|
||||
|
||||
expected := datadog.Widget{}.ChangeWidget
|
||||
|
||||
expected.X = 1
|
||||
expected.Y = 1
|
||||
expected.Width = 5
|
||||
expected.Height = 5
|
||||
expected.TitleText = "foo"
|
||||
expected.TitleAlign = "center"
|
||||
expected.TitleSize = 1
|
||||
expected.Title = true
|
||||
expected.Aggregator = "min"
|
||||
expected.TileDef = datadog.TileDef{}
|
||||
|
||||
w := datadog.Widget{ChangeWidget: expected}
|
||||
|
||||
board.Widgets = append(board.Widgets, w)
|
||||
|
||||
if err := client.UpdateScreenboard(board); err != nil {
|
||||
t.Fatalf("Updating a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actual, err := client.GetScreenboard(board.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actualWidget := actual.Widgets[0].ChangeWidget
|
||||
|
||||
assertEquals(t, "x", actualWidget.X, expected.X)
|
||||
assertEquals(t, "y", actualWidget.Y, expected.Y)
|
||||
assertEquals(t, "height", actualWidget.Height, expected.Height)
|
||||
assertEquals(t, "width", actualWidget.Width, expected.Width)
|
||||
assertEquals(t, "title_text", actualWidget.TitleText, expected.TitleText)
|
||||
assertEquals(t, "title_size", actualWidget.TitleSize, expected.TitleSize)
|
||||
assertEquals(t, "title_align", actualWidget.TitleAlign, expected.TitleAlign)
|
||||
assertEquals(t, "title", actualWidget.Title, expected.Title)
|
||||
assertEquals(t, "aggregator", actualWidget.Aggregator, expected.Aggregator)
|
||||
assertTileDefEquals(t, actualWidget.TileDef, expected.TileDef)
|
||||
}
|
||||
|
||||
func TestGraphWidget(t *testing.T) {
|
||||
board := createTestScreenboard(t)
|
||||
defer cleanUpScreenboard(t, board.Id)
|
||||
|
||||
expected := datadog.Widget{}.GraphWidget
|
||||
|
||||
expected.X = 1
|
||||
expected.Y = 1
|
||||
expected.Width = 5
|
||||
expected.Height = 5
|
||||
expected.TitleText = "foo"
|
||||
expected.TitleAlign = "center"
|
||||
expected.TitleSize = 1
|
||||
expected.Title = true
|
||||
expected.Timeframe = "1d"
|
||||
expected.Type = "alert_graph"
|
||||
expected.Legend = true
|
||||
expected.LegendSize = 5
|
||||
expected.TileDef = datadog.TileDef{}
|
||||
|
||||
w := datadog.Widget{GraphWidget: expected}
|
||||
|
||||
board.Widgets = append(board.Widgets, w)
|
||||
|
||||
if err := client.UpdateScreenboard(board); err != nil {
|
||||
t.Fatalf("Updating a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actual, err := client.GetScreenboard(board.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actualWidget := actual.Widgets[0].GraphWidget
|
||||
|
||||
assertEquals(t, "x", actualWidget.X, expected.X)
|
||||
assertEquals(t, "y", actualWidget.Y, expected.Y)
|
||||
assertEquals(t, "height", actualWidget.Height, expected.Height)
|
||||
assertEquals(t, "width", actualWidget.Width, expected.Width)
|
||||
assertEquals(t, "title_text", actualWidget.TitleText, expected.TitleText)
|
||||
assertEquals(t, "title_size", actualWidget.TitleSize, expected.TitleSize)
|
||||
assertEquals(t, "title_align", actualWidget.TitleAlign, expected.TitleAlign)
|
||||
assertEquals(t, "title", actualWidget.Title, expected.Title)
|
||||
assertEquals(t, "type", actualWidget.Type, expected.Type)
|
||||
assertEquals(t, "timeframe", actualWidget.Timeframe, expected.Timeframe)
|
||||
assertEquals(t, "legend", actualWidget.Legend, expected.Legend)
|
||||
assertEquals(t, "legend_size", actualWidget.LegendSize, expected.LegendSize)
|
||||
assertTileDefEquals(t, actualWidget.TileDef, expected.TileDef)
|
||||
}
|
||||
|
||||
func TestEventTimelineWidget(t *testing.T) {
|
||||
board := createTestScreenboard(t)
|
||||
defer cleanUpScreenboard(t, board.Id)
|
||||
|
||||
expected := datadog.Widget{}.EventTimelineWidget
|
||||
|
||||
expected.X = 1
|
||||
expected.Y = 1
|
||||
expected.Width = 5
|
||||
expected.Height = 5
|
||||
expected.TitleText = "foo"
|
||||
expected.TitleAlign = "center"
|
||||
expected.TitleSize = 1
|
||||
expected.Title = true
|
||||
expected.Query = "avg:system.load.1{foo} by {bar}"
|
||||
expected.Timeframe = "1d"
|
||||
expected.Type = "alert_graph"
|
||||
|
||||
w := datadog.Widget{EventTimelineWidget: expected}
|
||||
|
||||
board.Widgets = append(board.Widgets, w)
|
||||
|
||||
if err := client.UpdateScreenboard(board); err != nil {
|
||||
t.Fatalf("Updating a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actual, err := client.GetScreenboard(board.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actualWidget := actual.Widgets[0].EventTimelineWidget
|
||||
|
||||
assertEquals(t, "x", actualWidget.X, expected.X)
|
||||
assertEquals(t, "y", actualWidget.Y, expected.Y)
|
||||
assertEquals(t, "height", actualWidget.Height, expected.Height)
|
||||
assertEquals(t, "width", actualWidget.Width, expected.Width)
|
||||
assertEquals(t, "title_text", actualWidget.TitleText, expected.TitleText)
|
||||
assertEquals(t, "title_size", actualWidget.TitleSize, expected.TitleSize)
|
||||
assertEquals(t, "title_align", actualWidget.TitleAlign, expected.TitleAlign)
|
||||
assertEquals(t, "title", actualWidget.Title, expected.Title)
|
||||
assertEquals(t, "type", actualWidget.Type, expected.Type)
|
||||
assertEquals(t, "query", actualWidget.Query, expected.Query)
|
||||
assertEquals(t, "timeframe", actualWidget.Timeframe, expected.Timeframe)
|
||||
}
|
||||
|
||||
func TestAlertGraphWidget(t *testing.T) {
|
||||
board := createTestScreenboard(t)
|
||||
defer cleanUpScreenboard(t, board.Id)
|
||||
|
||||
expected := datadog.Widget{}.AlertGraphWidget
|
||||
|
||||
expected.X = 1
|
||||
expected.Y = 1
|
||||
expected.Width = 5
|
||||
expected.Height = 5
|
||||
expected.TitleText = "foo"
|
||||
expected.TitleAlign = "center"
|
||||
expected.TitleSize = 1
|
||||
expected.Title = true
|
||||
expected.VizType = ""
|
||||
expected.Timeframe = "1d"
|
||||
expected.AddTimeframe = false
|
||||
expected.AlertId = 1
|
||||
expected.Type = "alert_graph"
|
||||
|
||||
w := datadog.Widget{AlertGraphWidget: expected}
|
||||
|
||||
board.Widgets = append(board.Widgets, w)
|
||||
|
||||
if err := client.UpdateScreenboard(board); err != nil {
|
||||
t.Fatalf("Updating a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actual, err := client.GetScreenboard(board.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actualWidget := actual.Widgets[0].AlertGraphWidget
|
||||
|
||||
assertEquals(t, "x", actualWidget.X, expected.X)
|
||||
assertEquals(t, "y", actualWidget.Y, expected.Y)
|
||||
assertEquals(t, "height", actualWidget.Height, expected.Height)
|
||||
assertEquals(t, "width", actualWidget.Width, expected.Width)
|
||||
assertEquals(t, "title_text", actualWidget.TitleText, expected.TitleText)
|
||||
assertEquals(t, "title_size", actualWidget.TitleSize, expected.TitleSize)
|
||||
assertEquals(t, "title_align", actualWidget.TitleAlign, expected.TitleAlign)
|
||||
assertEquals(t, "title", actualWidget.Title, expected.Title)
|
||||
assertEquals(t, "type", actualWidget.Type, expected.Type)
|
||||
assertEquals(t, "viz_type", actualWidget.VizType, expected.VizType)
|
||||
assertEquals(t, "timeframe", actualWidget.Timeframe, expected.Timeframe)
|
||||
assertEquals(t, "add_timeframe", actualWidget.AddTimeframe, expected.AddTimeframe)
|
||||
assertEquals(t, "alert_id", actualWidget.AlertId, expected.AlertId)
|
||||
}
|
||||
|
||||
func TestHostMapWidget(t *testing.T) {
|
||||
board := createTestScreenboard(t)
|
||||
defer cleanUpScreenboard(t, board.Id)
|
||||
|
||||
expected := datadog.Widget{}.HostMapWidget
|
||||
|
||||
expected.X = 1
|
||||
expected.Y = 1
|
||||
expected.Width = 5
|
||||
expected.Height = 5
|
||||
expected.TitleText = "foo"
|
||||
expected.TitleAlign = "center"
|
||||
expected.TitleSize = 1
|
||||
expected.Title = true
|
||||
expected.Type = "check_status"
|
||||
expected.Query = "avg:system.load.1{foo} by {bar}"
|
||||
expected.Timeframe = "1d"
|
||||
expected.Legend = true
|
||||
expected.LegendSize = 5
|
||||
expected.TileDef = datadog.TileDef{}
|
||||
|
||||
w := datadog.Widget{HostMapWidget: expected}
|
||||
|
||||
board.Widgets = append(board.Widgets, w)
|
||||
|
||||
if err := client.UpdateScreenboard(board); err != nil {
|
||||
t.Fatalf("Updating a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actual, err := client.GetScreenboard(board.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actualWidget := actual.Widgets[0].HostMapWidget
|
||||
|
||||
assertEquals(t, "x", actualWidget.X, expected.X)
|
||||
assertEquals(t, "y", actualWidget.Y, expected.Y)
|
||||
assertEquals(t, "height", actualWidget.Height, expected.Height)
|
||||
assertEquals(t, "width", actualWidget.Width, expected.Width)
|
||||
assertEquals(t, "title_text", actualWidget.TitleText, expected.TitleText)
|
||||
assertEquals(t, "title_size", actualWidget.TitleSize, expected.TitleSize)
|
||||
assertEquals(t, "title_align", actualWidget.TitleAlign, expected.TitleAlign)
|
||||
assertEquals(t, "title", actualWidget.Title, expected.Title)
|
||||
assertEquals(t, "type", actualWidget.Type, expected.Type)
|
||||
assertEquals(t, "query", actualWidget.Query, expected.Query)
|
||||
assertEquals(t, "timeframe", actualWidget.Timeframe, expected.Timeframe)
|
||||
assertEquals(t, "query", actualWidget.Query, expected.Query)
|
||||
assertEquals(t, "legend", actualWidget.Legend, expected.Legend)
|
||||
assertEquals(t, "legend_size", actualWidget.LegendSize, expected.LegendSize)
|
||||
assertTileDefEquals(t, actualWidget.TileDef, expected.TileDef)
|
||||
}
|
||||
|
||||
func TestCheckStatusWidget(t *testing.T) {
|
||||
board := createTestScreenboard(t)
|
||||
defer cleanUpScreenboard(t, board.Id)
|
||||
|
||||
expected := datadog.Widget{}.CheckStatusWidget
|
||||
|
||||
expected.X = 1
|
||||
expected.Y = 1
|
||||
expected.Width = 5
|
||||
expected.Height = 5
|
||||
expected.TitleText = "foo"
|
||||
expected.TitleAlign = "center"
|
||||
expected.TitleSize = 1
|
||||
expected.Title = true
|
||||
expected.Type = "check_status"
|
||||
expected.Tags = "foo"
|
||||
expected.Timeframe = "1d"
|
||||
expected.Timeframe = "1d"
|
||||
expected.Check = "datadog.agent.up"
|
||||
expected.Group = "foo"
|
||||
expected.Grouping = "check"
|
||||
|
||||
w := datadog.Widget{CheckStatusWidget: expected}
|
||||
|
||||
board.Widgets = append(board.Widgets, w)
|
||||
|
||||
if err := client.UpdateScreenboard(board); err != nil {
|
||||
t.Fatalf("Updating a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actual, err := client.GetScreenboard(board.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actualWidget := actual.Widgets[0].CheckStatusWidget
|
||||
|
||||
assertEquals(t, "x", actualWidget.X, expected.X)
|
||||
assertEquals(t, "y", actualWidget.Y, expected.Y)
|
||||
assertEquals(t, "height", actualWidget.Height, expected.Height)
|
||||
assertEquals(t, "width", actualWidget.Width, expected.Width)
|
||||
assertEquals(t, "title_text", actualWidget.TitleText, expected.TitleText)
|
||||
assertEquals(t, "title_size", actualWidget.TitleSize, expected.TitleSize)
|
||||
assertEquals(t, "title_align", actualWidget.TitleAlign, expected.TitleAlign)
|
||||
assertEquals(t, "title", actualWidget.Title, expected.Title)
|
||||
assertEquals(t, "type", actualWidget.Type, expected.Type)
|
||||
assertEquals(t, "tags", actualWidget.Tags, expected.Tags)
|
||||
assertEquals(t, "timeframe", actualWidget.Timeframe, expected.Timeframe)
|
||||
assertEquals(t, "check", actualWidget.Check, expected.Check)
|
||||
assertEquals(t, "group", actualWidget.Group, expected.Group)
|
||||
assertEquals(t, "grouping", actualWidget.Grouping, expected.Grouping)
|
||||
}
|
||||
|
||||
func TestIFrameWidget(t *testing.T) {
|
||||
board := createTestScreenboard(t)
|
||||
defer cleanUpScreenboard(t, board.Id)
|
||||
|
||||
expected := datadog.Widget{}.IFrameWidget
|
||||
|
||||
expected.X = 1
|
||||
expected.Y = 1
|
||||
expected.Width = 5
|
||||
expected.Height = 5
|
||||
expected.TitleText = "foo"
|
||||
expected.TitleAlign = "center"
|
||||
expected.TitleSize = 1
|
||||
expected.Title = true
|
||||
expected.Url = "http://www.example.com"
|
||||
expected.Type = "iframe"
|
||||
|
||||
w := datadog.Widget{IFrameWidget: expected}
|
||||
|
||||
board.Widgets = append(board.Widgets, w)
|
||||
|
||||
if err := client.UpdateScreenboard(board); err != nil {
|
||||
t.Fatalf("Updating a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actual, err := client.GetScreenboard(board.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actualWidget := actual.Widgets[0].IFrameWidget
|
||||
|
||||
assertEquals(t, "x", actualWidget.X, expected.X)
|
||||
assertEquals(t, "y", actualWidget.Y, expected.Y)
|
||||
assertEquals(t, "height", actualWidget.Height, expected.Height)
|
||||
assertEquals(t, "width", actualWidget.Width, expected.Width)
|
||||
assertEquals(t, "title_text", actualWidget.TitleText, expected.TitleText)
|
||||
assertEquals(t, "title_size", actualWidget.TitleSize, expected.TitleSize)
|
||||
assertEquals(t, "title_align", actualWidget.TitleAlign, expected.TitleAlign)
|
||||
assertEquals(t, "title", actualWidget.Title, expected.Title)
|
||||
assertEquals(t, "url", actualWidget.Url, expected.Url)
|
||||
assertEquals(t, "type", actualWidget.Type, expected.Type)
|
||||
}
|
||||
|
||||
func TestNoteWidget(t *testing.T) {
|
||||
board := createTestScreenboard(t)
|
||||
defer cleanUpScreenboard(t, board.Id)
|
||||
|
||||
expected := datadog.Widget{}.NoteWidget
|
||||
|
||||
expected.X = 1
|
||||
expected.Y = 1
|
||||
expected.Width = 5
|
||||
expected.Height = 5
|
||||
expected.TitleText = "foo"
|
||||
expected.TitleAlign = "center"
|
||||
expected.TitleSize = 1
|
||||
expected.Title = true
|
||||
expected.Color = "green"
|
||||
expected.FontSize = 5
|
||||
expected.RefreshEvery = 60
|
||||
expected.TickPos = "foo"
|
||||
expected.TickEdge = "bar"
|
||||
expected.Html = "<strong>baz</strong>"
|
||||
expected.Tick = false
|
||||
expected.Note = "quz"
|
||||
expected.AutoRefresh = false
|
||||
|
||||
w := datadog.Widget{NoteWidget: expected}
|
||||
|
||||
board.Widgets = append(board.Widgets, w)
|
||||
|
||||
if err := client.UpdateScreenboard(board); err != nil {
|
||||
t.Fatalf("Updating a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actual, err := client.GetScreenboard(board.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actualWidget := actual.Widgets[0].NoteWidget
|
||||
|
||||
assertEquals(t, "x", actualWidget.X, expected.X)
|
||||
assertEquals(t, "y", actualWidget.Y, expected.Y)
|
||||
assertEquals(t, "height", actualWidget.Height, expected.Height)
|
||||
assertEquals(t, "width", actualWidget.Width, expected.Width)
|
||||
assertEquals(t, "title_text", actualWidget.TitleText, expected.TitleText)
|
||||
assertEquals(t, "title_size", actualWidget.TitleSize, expected.TitleSize)
|
||||
assertEquals(t, "title_align", actualWidget.TitleAlign, expected.TitleAlign)
|
||||
assertEquals(t, "title", actualWidget.Title, expected.Title)
|
||||
assertEquals(t, "color", actualWidget.Color, expected.Color)
|
||||
assertEquals(t, "front_size", actualWidget.FontSize, expected.FontSize)
|
||||
assertEquals(t, "refresh_every", actualWidget.RefreshEvery, expected.RefreshEvery)
|
||||
assertEquals(t, "tick_pos", actualWidget.TickPos, expected.TickPos)
|
||||
assertEquals(t, "tick_edge", actualWidget.TickEdge, expected.TickEdge)
|
||||
assertEquals(t, "tick", actualWidget.Tick, expected.Tick)
|
||||
assertEquals(t, "html", actualWidget.Html, expected.Html)
|
||||
assertEquals(t, "note", actualWidget.Note, expected.Note)
|
||||
assertEquals(t, "auto_refresh", actualWidget.AutoRefresh, expected.AutoRefresh)
|
||||
}
|
||||
|
||||
func TestToplistWidget(t *testing.T) {
|
||||
board := createTestScreenboard(t)
|
||||
defer cleanUpScreenboard(t, board.Id)
|
||||
|
||||
expected := datadog.Widget{}.ToplistWidget
|
||||
expected.X = 1
|
||||
expected.Y = 1
|
||||
expected.Width = 5
|
||||
expected.Height = 5
|
||||
expected.Type = "toplist"
|
||||
expected.TitleText = "foo"
|
||||
expected.TitleSize.Auto = false
|
||||
expected.TitleSize.Size = 5
|
||||
expected.TitleAlign = "center"
|
||||
expected.Title = false
|
||||
expected.Timeframe = "5m"
|
||||
expected.Legend = false
|
||||
expected.LegendSize = 5
|
||||
|
||||
w := datadog.Widget{ToplistWidget: expected}
|
||||
|
||||
board.Widgets = append(board.Widgets, w)
|
||||
|
||||
if err := client.UpdateScreenboard(board); err != nil {
|
||||
t.Fatalf("Updating a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actual, err := client.GetScreenboard(board.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actualWidget := actual.Widgets[0].ToplistWidget
|
||||
|
||||
assertEquals(t, "x", actualWidget.X, expected.X)
|
||||
assertEquals(t, "y", actualWidget.Y, expected.Y)
|
||||
assertEquals(t, "height", actualWidget.Height, expected.Height)
|
||||
assertEquals(t, "width", actualWidget.Width, expected.Width)
|
||||
assertEquals(t, "title_text", actualWidget.TitleText, expected.TitleText)
|
||||
assertEquals(t, "title_size", actualWidget.TitleSize, expected.TitleSize)
|
||||
assertEquals(t, "title_align", actualWidget.TitleAlign, expected.TitleAlign)
|
||||
assertEquals(t, "legend", actualWidget.Legend, expected.Legend)
|
||||
assertEquals(t, "legend_size", actualWidget.LegendSize, expected.LegendSize)
|
||||
}
|
||||
|
||||
func TestEventSteamWidget(t *testing.T) {
|
||||
board := createTestScreenboard(t)
|
||||
defer cleanUpScreenboard(t, board.Id)
|
||||
|
||||
expected := datadog.Widget{}.EventStreamWidget
|
||||
expected.EventSize = "1"
|
||||
expected.Width = 1
|
||||
expected.Height = 1
|
||||
expected.X = 1
|
||||
expected.Y = 1
|
||||
expected.Query = "foo"
|
||||
expected.Timeframe = "5w"
|
||||
expected.Title = false
|
||||
expected.TitleAlign = "center"
|
||||
expected.TitleSize.Auto = false
|
||||
expected.TitleSize.Size = 5
|
||||
expected.TitleText = "bar"
|
||||
expected.Type = "baz"
|
||||
|
||||
w := datadog.Widget{EventStreamWidget: expected}
|
||||
|
||||
board.Widgets = append(board.Widgets, w)
|
||||
|
||||
if err := client.UpdateScreenboard(board); err != nil {
|
||||
t.Fatalf("Updating a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actual, err := client.GetScreenboard(board.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actualWidget := actual.Widgets[0].EventStreamWidget
|
||||
|
||||
assertEquals(t, "event_size", actualWidget.EventSize, expected.EventSize)
|
||||
assertEquals(t, "width", actualWidget.Width, expected.Width)
|
||||
assertEquals(t, "height", actualWidget.Height, expected.Height)
|
||||
assertEquals(t, "x", actualWidget.X, expected.X)
|
||||
assertEquals(t, "y", actualWidget.Y, expected.Y)
|
||||
assertEquals(t, "query", actualWidget.Query, expected.Query)
|
||||
assertEquals(t, "timeframe", actualWidget.Timeframe, expected.Timeframe)
|
||||
assertEquals(t, "title", actualWidget.Title, expected.Title)
|
||||
assertEquals(t, "title_align", actualWidget.TitleAlign, expected.TitleAlign)
|
||||
assertEquals(t, "title_size", actualWidget.TitleSize, expected.TitleSize)
|
||||
assertEquals(t, "title_text", actualWidget.TitleText, expected.TitleText)
|
||||
assertEquals(t, "type", actualWidget.Type, expected.Type)
|
||||
}
|
||||
|
||||
func TestImageWidget(t *testing.T) {
|
||||
board := createTestScreenboard(t)
|
||||
defer cleanUpScreenboard(t, board.Id)
|
||||
|
||||
expected := datadog.Widget{}.ImageWidget
|
||||
|
||||
expected.Width = 1
|
||||
expected.Height = 1
|
||||
expected.X = 1
|
||||
expected.Y = 1
|
||||
expected.Title = false
|
||||
expected.TitleAlign = "center"
|
||||
expected.TitleSize.Auto = false
|
||||
expected.TitleSize.Size = 5
|
||||
expected.TitleText = "bar"
|
||||
expected.Type = "baz"
|
||||
expected.Url = "qux"
|
||||
expected.Sizing = "quuz"
|
||||
|
||||
w := datadog.Widget{ImageWidget: expected}
|
||||
|
||||
board.Widgets = append(board.Widgets, w)
|
||||
|
||||
if err := client.UpdateScreenboard(board); err != nil {
|
||||
t.Fatalf("Updating a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actual, err := client.GetScreenboard(board.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actualWidget := actual.Widgets[0].ImageWidget
|
||||
|
||||
assertEquals(t, "width", actualWidget.Width, expected.Width)
|
||||
assertEquals(t, "height", actualWidget.Height, expected.Height)
|
||||
assertEquals(t, "x", actualWidget.X, expected.X)
|
||||
assertEquals(t, "y", actualWidget.Y, expected.Y)
|
||||
assertEquals(t, "title", actualWidget.Title, expected.Title)
|
||||
assertEquals(t, "title_align", actualWidget.TitleAlign, expected.TitleAlign)
|
||||
assertEquals(t, "title_size", actualWidget.TitleSize, expected.TitleSize)
|
||||
assertEquals(t, "title_text", actualWidget.TitleText, expected.TitleText)
|
||||
assertEquals(t, "type", actualWidget.Type, expected.Type)
|
||||
assertEquals(t, "url", actualWidget.Url, expected.Url)
|
||||
assertEquals(t, "sizing", actualWidget.Sizing, expected.Sizing)
|
||||
}
|
||||
|
||||
func TestFreeTextWidget(t *testing.T) {
|
||||
board := createTestScreenboard(t)
|
||||
defer cleanUpScreenboard(t, board.Id)
|
||||
|
||||
expected := datadog.Widget{}.FreeTextWidget
|
||||
|
||||
expected.X = 1
|
||||
expected.Y = 1
|
||||
expected.Height = 10
|
||||
expected.Width = 10
|
||||
expected.Text = "Test"
|
||||
expected.FontSize = "16"
|
||||
expected.TextAlign = "center"
|
||||
|
||||
w := datadog.Widget{FreeTextWidget: expected}
|
||||
|
||||
board.Widgets = append(board.Widgets, w)
|
||||
|
||||
if err := client.UpdateScreenboard(board); err != nil {
|
||||
t.Fatalf("Updating a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actual, err := client.GetScreenboard(board.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actualWidget := actual.Widgets[0].FreeTextWidget
|
||||
|
||||
assertEquals(t, "font-size", actualWidget.FontSize, expected.FontSize)
|
||||
assertEquals(t, "height", actualWidget.Height, expected.Height)
|
||||
assertEquals(t, "width", actualWidget.Width, expected.Width)
|
||||
assertEquals(t, "x", actualWidget.X, expected.X)
|
||||
assertEquals(t, "y", actualWidget.Y, expected.Y)
|
||||
assertEquals(t, "text", actualWidget.Text, expected.Text)
|
||||
assertEquals(t, "text-align", actualWidget.TextAlign, expected.TextAlign)
|
||||
assertEquals(t, "type", actualWidget.Type, expected.Type)
|
||||
}
|
||||
|
||||
func TestTimeseriesWidget(t *testing.T) {
|
||||
board := createTestScreenboard(t)
|
||||
defer cleanUpScreenboard(t, board.Id)
|
||||
|
||||
expected := datadog.Widget{}.TimeseriesWidget
|
||||
expected.X = 1
|
||||
expected.Y = 1
|
||||
expected.Width = 20
|
||||
expected.Height = 30
|
||||
expected.Title = true
|
||||
expected.TitleAlign = "centre"
|
||||
expected.TitleSize = datadog.TextSize{Size: 16}
|
||||
expected.TitleText = "Test"
|
||||
expected.Timeframe = "1m"
|
||||
|
||||
w := datadog.Widget{TimeseriesWidget: expected}
|
||||
|
||||
board.Widgets = append(board.Widgets, w)
|
||||
if err := client.UpdateScreenboard(board); err != nil {
|
||||
t.Fatalf("Updating a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actual, err := client.GetScreenboard(board.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actualWidget := actual.Widgets[0].TimeseriesWidget
|
||||
|
||||
assertEquals(t, "height", actualWidget.Height, expected.Height)
|
||||
assertEquals(t, "width", actualWidget.Width, expected.Width)
|
||||
assertEquals(t, "x", actualWidget.X, expected.X)
|
||||
assertEquals(t, "y", actualWidget.Y, expected.Y)
|
||||
assertEquals(t, "title", actualWidget.Title, expected.Title)
|
||||
assertEquals(t, "title-align", actualWidget.TitleAlign, expected.TitleAlign)
|
||||
assertEquals(t, "title-size.size", actualWidget.TitleSize.Size, expected.TitleSize.Size)
|
||||
assertEquals(t, "title-size.auto", actualWidget.TitleSize.Auto, expected.TitleSize.Auto)
|
||||
assertEquals(t, "title-text", actualWidget.TitleText, expected.TitleText)
|
||||
assertEquals(t, "type", actualWidget.Type, expected.Type)
|
||||
assertEquals(t, "timeframe", actualWidget.Timeframe, expected.Timeframe)
|
||||
assertEquals(t, "legend", actualWidget.Legend, expected.Legend)
|
||||
assertTileDefEquals(t, actualWidget.TileDef, expected.TileDef)
|
||||
}
|
||||
|
||||
func TestQueryValueWidget(t *testing.T) {
|
||||
board := createTestScreenboard(t)
|
||||
defer cleanUpScreenboard(t, board.Id)
|
||||
|
||||
expected := datadog.Widget{}.QueryValueWidget
|
||||
expected.X = 1
|
||||
expected.Y = 1
|
||||
expected.Width = 20
|
||||
expected.Height = 30
|
||||
expected.Title = true
|
||||
expected.TitleAlign = "centre"
|
||||
expected.TitleSize = datadog.TextSize{Size: 16}
|
||||
expected.TitleText = "Test"
|
||||
expected.Timeframe = "1m"
|
||||
expected.TimeframeAggregator = "sum"
|
||||
expected.Aggregator = "min"
|
||||
expected.Query = "docker.containers.running"
|
||||
expected.MetricType = "standard"
|
||||
/* TODO: add test for conditional formats
|
||||
"conditional_formats": [{
|
||||
"comparator": ">",
|
||||
"color": "white_on_red",
|
||||
"custom_bg_color": null,
|
||||
"value": 1,
|
||||
"invert": false,
|
||||
"custom_fg_color": null}],
|
||||
*/
|
||||
expected.IsValidQuery = true
|
||||
expected.ResultCalcFunc = "raw"
|
||||
expected.Aggregator = "avg"
|
||||
expected.CalcFunc = "raw"
|
||||
|
||||
w := datadog.Widget{QueryValueWidget: expected}
|
||||
|
||||
board.Widgets = append(board.Widgets, w)
|
||||
if err := client.UpdateScreenboard(board); err != nil {
|
||||
t.Fatalf("Updating a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actual, err := client.GetScreenboard(board.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving a screenboard failed: %s", err)
|
||||
}
|
||||
|
||||
actualWidget := actual.Widgets[0].QueryValueWidget
|
||||
|
||||
assertEquals(t, "height", actualWidget.Height, expected.Height)
|
||||
assertEquals(t, "width", actualWidget.Width, expected.Width)
|
||||
assertEquals(t, "x", actualWidget.X, expected.X)
|
||||
assertEquals(t, "y", actualWidget.Y, expected.Y)
|
||||
assertEquals(t, "title", actualWidget.Title, expected.Title)
|
||||
assertEquals(t, "title-align", actualWidget.TitleAlign, expected.TitleAlign)
|
||||
assertEquals(t, "title-size.size", actualWidget.TitleSize.Size, expected.TitleSize.Size)
|
||||
assertEquals(t, "title-size.auto", actualWidget.TitleSize.Auto, expected.TitleSize.Auto)
|
||||
assertEquals(t, "title-text", actualWidget.TitleText, expected.TitleText)
|
||||
assertEquals(t, "type", actualWidget.Type, expected.Type)
|
||||
assertEquals(t, "timeframe", actualWidget.Timeframe, expected.Timeframe)
|
||||
assertEquals(t, "timeframe-aggregator", actualWidget.TimeframeAggregator, expected.TimeframeAggregator)
|
||||
assertEquals(t, "aggregator", actualWidget.Aggregator, expected.Aggregator)
|
||||
assertEquals(t, "query", actualWidget.Query, expected.Query)
|
||||
assertEquals(t, "is_valid_query", actualWidget.IsValidQuery, expected.IsValidQuery)
|
||||
assertEquals(t, "res_calc_func", actualWidget.ResultCalcFunc, expected.ResultCalcFunc)
|
||||
assertEquals(t, "aggr", actualWidget.Aggregator, expected.Aggregator)
|
||||
}
|
||||
|
||||
func assertTileDefEquals(t *testing.T, actual datadog.TileDef, expected datadog.TileDef) {
|
||||
assertEquals(t, "num-events", len(actual.Events), len(expected.Events))
|
||||
assertEquals(t, "num-requests", len(actual.Requests), len(expected.Requests))
|
||||
assertEquals(t, "viz", actual.Viz, expected.Viz)
|
||||
|
||||
for i, event := range actual.Events {
|
||||
assertEquals(t, "event-query", event.Query, expected.Events[i].Query)
|
||||
}
|
||||
|
||||
for i, request := range actual.Requests {
|
||||
assertEquals(t, "request-query", request.Query, expected.Requests[i].Query)
|
||||
assertEquals(t, "request-type", request.Type, expected.Requests[i].Type)
|
||||
}
|
||||
}
|
||||
|
||||
func assertEquals(t *testing.T, attribute string, a, b interface{}) {
|
||||
if a != b {
|
||||
t.Errorf("The two %s values '%v' and '%v' are not equal", attribute, a, b)
|
||||
}
|
||||
}
|
|
@ -1,143 +0,0 @@
|
|||
package integration
|
||||
|
||||
import (
|
||||
"github.com/zorkian/go-datadog-api"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func init() {
|
||||
client = initTest()
|
||||
}
|
||||
|
||||
func TestCreateAndDeleteScreenboard(t *testing.T) {
|
||||
expected := getTestScreenboard()
|
||||
// create the screenboard and compare it
|
||||
actual, err := client.CreateScreenboard(expected)
|
||||
if err != nil {
|
||||
t.Fatalf("Creating a screenboard failed when it shouldn't. (%s)", err)
|
||||
}
|
||||
|
||||
defer cleanUpScreenboard(t, actual.Id)
|
||||
|
||||
assertScreenboardEquals(t, actual, expected)
|
||||
|
||||
// now try to fetch it freshly and compare it again
|
||||
actual, err = client.GetScreenboard(actual.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving a screenboard failed when it shouldn't. (%s)", err)
|
||||
}
|
||||
|
||||
assertScreenboardEquals(t, actual, expected)
|
||||
|
||||
}
|
||||
|
||||
func TestShareAndRevokeScreenboard(t *testing.T) {
|
||||
expected := getTestScreenboard()
|
||||
// create the screenboard
|
||||
actual, err := client.CreateScreenboard(expected)
|
||||
if err != nil {
|
||||
t.Fatalf("Creating a screenboard failed when it shouldn't: %s", err)
|
||||
}
|
||||
|
||||
defer cleanUpScreenboard(t, actual.Id)
|
||||
|
||||
// share screenboard and verify it was shared
|
||||
var response datadog.ScreenShareResponse
|
||||
err = client.ShareScreenboard(actual.Id, &response)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to share screenboard: %s", err)
|
||||
}
|
||||
|
||||
// revoke screenboard
|
||||
err = client.RevokeScreenboard(actual.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to revoke sharing of screenboard: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateScreenboard(t *testing.T) {
|
||||
board := createTestScreenboard(t)
|
||||
defer cleanUpScreenboard(t, board.Id)
|
||||
|
||||
board.Title = "___New-Test-Board___"
|
||||
if err := client.UpdateScreenboard(board); err != nil {
|
||||
t.Fatalf("Updating a screenboard failed when it shouldn't: %s", err)
|
||||
}
|
||||
|
||||
actual, err := client.GetScreenboard(board.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving a screenboard failed when it shouldn't: %s", err)
|
||||
}
|
||||
|
||||
assertScreenboardEquals(t, actual, board)
|
||||
|
||||
}
|
||||
|
||||
func TestGetScreenboards(t *testing.T) {
|
||||
boards, err := client.GetScreenboards()
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving screenboards failed when it shouldn't: %s", err)
|
||||
}
|
||||
num := len(boards)
|
||||
|
||||
board := createTestScreenboard(t)
|
||||
defer cleanUpScreenboard(t, board.Id)
|
||||
|
||||
boards, err = client.GetScreenboards()
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving screenboards failed when it shouldn't: %s", err)
|
||||
}
|
||||
|
||||
if num+1 != len(boards) {
|
||||
t.Fatalf("Number of screenboards didn't match expected: %d != %d", len(boards), num+1)
|
||||
}
|
||||
}
|
||||
|
||||
func getTestScreenboard() *datadog.Screenboard {
|
||||
return &datadog.Screenboard{
|
||||
Title: "___Test-Board___",
|
||||
Height: "600",
|
||||
Width: "800",
|
||||
Widgets: []datadog.Widget{},
|
||||
}
|
||||
}
|
||||
|
||||
func createTestScreenboard(t *testing.T) *datadog.Screenboard {
|
||||
board := getTestScreenboard()
|
||||
board, err := client.CreateScreenboard(board)
|
||||
if err != nil {
|
||||
t.Fatalf("Creating a screenboard failed when it shouldn't: %s", err)
|
||||
}
|
||||
|
||||
return board
|
||||
}
|
||||
|
||||
func cleanUpScreenboard(t *testing.T, id int) {
|
||||
if err := client.DeleteScreenboard(id); err != nil {
|
||||
t.Fatalf("Deleting a screenboard failed when it shouldn't. Manual cleanup needed. (%s)", err)
|
||||
}
|
||||
|
||||
deletedBoard, err := client.GetScreenboard(id)
|
||||
if deletedBoard != nil {
|
||||
t.Fatal("Screenboard hasn't been deleted when it should have been. Manual cleanup needed.")
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
t.Fatal("Fetching deleted screenboard didn't lead to an error. Manual cleanup needed.")
|
||||
}
|
||||
}
|
||||
|
||||
func assertScreenboardEquals(t *testing.T, actual, expected *datadog.Screenboard) {
|
||||
if actual.Title != expected.Title {
|
||||
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)
|
||||
}
|
||||
if 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))
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package integration
|
||||
|
||||
import (
|
||||
"github.com/zorkian/go-datadog-api"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
apiKey string
|
||||
appKey string
|
||||
client *datadog.Client
|
||||
)
|
||||
|
||||
func initTest() *datadog.Client {
|
||||
apiKey = os.Getenv("DATADOG_API_KEY")
|
||||
appKey = os.Getenv("DATADOG_APP_KEY")
|
||||
|
||||
if apiKey == "" || appKey == "" {
|
||||
log.Fatal("Please make sure to set the env variables 'DATADOG_API_KEY' and 'DATADOG_APP_KEY' before running this test")
|
||||
}
|
||||
|
||||
return datadog.NewClient(apiKey, appKey)
|
||||
}
|
Loading…
Reference in New Issue