-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
uptimerobot_integration_test.go
73 lines (64 loc) · 1.37 KB
/
uptimerobot_integration_test.go
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// +build integration
package uptimerobot
import (
"log"
"os"
"testing"
"github.com/google/go-cmp/cmp"
)
var client Client
func init() {
key := os.Getenv("UPTIMEROBOT_API_KEY")
if key == "" {
log.Fatal("'UPTIMEROBOT_API_KEY' must be set for integration tests")
}
client = New(key)
debug := os.Getenv("UPTIMEROBOT_DEBUG")
if debug != "" {
client.Debug = os.Stdout
}
}
func exampleMonitor(name string) Monitor {
return Monitor{
FriendlyName: name,
URL: "http://example.com/" + name,
Type: TypeHTTP,
SubType: SubTypeHTTP,
Port: 80,
}
}
func TestCreateGetIntegration(t *testing.T) {
t.Parallel()
mon := exampleMonitor("create_test")
ID, err := client.CreateMonitor(mon)
if err != nil {
t.Fatal(err)
}
defer client.DeleteMonitor(ID)
got, err := client.GetMonitor(ID)
if !cmp.Equal(ID, got.ID) {
t.Error(cmp.Diff(ID, got.ID))
}
}
func TestDeleteIntegration(t *testing.T) {
t.Parallel()
toDelete := exampleMonitor("delete_test")
ID, err := client.CreateMonitor(toDelete)
if err != nil {
t.Fatal(err)
}
if err = client.DeleteMonitor(ID); err != nil {
t.Error(err)
}
_, err = client.GetMonitor(ID)
if err == nil {
t.Error("want error getting deleted check, but got nil")
}
}
func TestAccountDetailsIntegration(t *testing.T) {
t.Parallel()
_, err := client.GetAccountDetails()
if err != nil {
t.Error(err)
}
}