forked from spaceapegames/go-wavefront
-
Notifications
You must be signed in to change notification settings - Fork 12
/
cloud_integrations_test.go
164 lines (137 loc) · 4.04 KB
/
cloud_integrations_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package wavefront
import (
"io"
"net/http"
"net/url"
"testing"
)
type MockCloudIntegrationClient struct {
Client
T *testing.T
}
type MockCrudCloudIntegrationClient struct {
Client
method string
T *testing.T
}
type MockCloudIntegrationClientExtId struct {
Client
method string
T *testing.T
}
func (m *MockCloudIntegrationClient) Do(req *http.Request) (io.ReadCloser, error) {
return testDo(m.T, req, "./fixtures/search-cloud-integrations-response.json", "POST", &SearchParams{})
}
func (m *MockCloudIntegrationClientExtId) Do(req *http.Request) (io.ReadCloser, error) {
var testType string
return testDo(m.T, req, "./fixtures/aws-ext-id-cloud-integrations-response.json", m.method, &testType)
}
func (m *MockCrudCloudIntegrationClient) Do(req *http.Request) (io.ReadCloser, error) {
return testDo(m.T, req, "./fixtures/crud-cloud-integrations-response.json", m.method, &CloudIntegration{})
}
func TestCloudIntegration_Search(t *testing.T) {
baseurl, _ := url.Parse("http://testing.wavefront.com")
c := &CloudIntegrations{
client: &MockCloudIntegrationClient{
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
debug: true,
},
T: t,
},
}
cloudIntegrations, err := c.Find(nil)
if err != nil {
t.Fatal(err)
}
if len(cloudIntegrations) != 4 {
t.Errorf("Expected to get 4 integrations got, %d", len(cloudIntegrations))
}
cloudWatch := cloudIntegrations[1]
if cloudWatch.Service != "CLOUDWATCH" {
t.Errorf("Expected Cloudwatch Integration, got %s", cloudWatch.Service)
}
if cloudWatch.LastErrorEvent == nil {
t.Errorf("Expected error on cloudwatch integration")
}
}
func TestCloudIntegrations_AwsExternalID(t *testing.T) {
baseurl, _ := url.Parse("http://testing.wavefront.com")
c := &CloudIntegrations{
client: &MockCloudIntegrationClientExtId{
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
debug: true,
},
T: t,
},
}
c.client.(*MockCloudIntegrationClientExtId).method = "POST"
extId, err := c.CreateAwsExternalID()
if err != nil {
t.Fatal(err)
}
if extId != "EXTERNAL-ID" {
t.Errorf("Expected ext-id of EXTERNAL-ID, got %s", extId)
}
c.client.(*MockCloudIntegrationClientExtId).method = "GET"
err = c.VerifyAwsExternalID("EXTERNAL-ID")
if err != nil {
t.Fatal(err)
}
c.client.(*MockCloudIntegrationClientExtId).method = "DELETE"
err = c.DeleteAwsExternalID(&extId)
if err != nil {
t.Fatal(err)
}
if extId != "" {
t.Errorf("Expected ext-id would be blank, got %s", extId)
}
}
func TestCloudIntegrations_CRUD(t *testing.T) {
baseurl, _ := url.Parse("http://testing.wavefront.com")
c := &CloudIntegrations{
client: &MockCrudCloudIntegrationClient{
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
debug: true,
},
T: t,
},
}
c.client.(*MockCrudCloudIntegrationClient).method = "GET"
cloudIntegration := &CloudIntegration{}
err := c.Get(cloudIntegration)
if err == nil {
t.Errorf("Expected error missing CloudIntegration ID")
}
cloudIntegration.Id = "12345678-1234-5678-9101-12345678910111"
if err = c.Get(cloudIntegration); err != nil {
t.Fatal(err)
}
assertEqual(t, "CLOUDWATCH", cloudIntegration.Service)
assertEqual(t, "12345678-1234-5678-9101-12345678910111", cloudIntegration.Id)
assertEqual(t, false, cloudIntegration.InTrash)
assertEqual(t, "^aws.(ecs|rds|billing|instance|efs|datasync).*)$",
cloudIntegration.CloudWatch.MetricFilterRegex)
assertEqual(t, "arn:aws:iam::123456789012:role/example-arn",
cloudIntegration.CloudWatch.BaseCredentials.RoleARN)
c.client.(*MockCrudCloudIntegrationClient).method = "PUT"
cloudIntegration.Name = "TESTING INTEGRATION"
err = c.Update(cloudIntegration)
if err != nil {
t.Fatal(err)
}
c.client.(*MockCrudCloudIntegrationClient).method = "DELETE"
err = c.Delete(cloudIntegration, false)
if err != nil {
t.Fatal(err)
}
assertEqual(t, "", cloudIntegration.Id)
}