File: hosts_test.go

package info (click to toggle)
golang-github-zorkian-go-datadog-api 2.30.0-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 1,616 kB
  • sloc: makefile: 28; sh: 13
file content (49 lines) | stat: -rw-r--r-- 1,280 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package integration

import (
	"fmt"
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
	"github.com/zorkian/go-datadog-api"
)

func TestHost_Mute(t *testing.T) {
	muteAction := getTestMuteAction()
	hostname := "test.host"
	muteResp, err := client.MuteHost(hostname, muteAction)
	if err != nil {
		t.Fatalf("Failed to mute host: %s, err: %s", hostname, err)
	}

	defer func() {
		unmuteResp, err := client.UnmuteHost(hostname)
		if err != nil {
			t.Fatalf("Failed to cleanup mute on host: %s, err: %s", hostname, err)
		}
		assert.Equal(t, "Unmuted", unmuteResp.Action)
		assert.Equal(t, hostname, unmuteResp.Hostname)
	}()

	assert.Equal(t, "Muted", muteResp.Action)
	assert.Equal(t, hostname, muteResp.Hostname)
	assert.Equal(t, "Muting this host for a test!", muteResp.Message)

}

func getTestMuteAction() *datadog.HostActionMute {
	return &datadog.HostActionMute{
		Message:  datadog.String("Muting this host for a test!"),
		EndTime:  datadog.String(fmt.Sprint(time.Now().Unix() + 100)),
		Override: datadog.Bool(false),
	}
}

// Just checking HTTP status is 2XX because numbers of active and up hosts are hard to fix.
func TestHostTotals(t *testing.T) {
	_, err := client.GetHostTotals()
	if err != nil {
		t.Fatalf("Failed to get hosts totals, err: %s", err)
	}
}