forked from signalfx/signalfx-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws_cloudwatch_integration_test.go
135 lines (108 loc) · 5.23 KB
/
aws_cloudwatch_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
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
package signalfx
import (
"context"
"net/http"
"testing"
"github.com/signalfx/signalfx-go/integration"
"github.com/stretchr/testify/assert"
)
func TestCreateAWSCloudWatchIntegration(t *testing.T) {
teardown := setup()
defer teardown()
mux.HandleFunc("/v2/integration", verifyRequest(t, "POST", true, http.StatusOK, nil, "integration/create_aws_success.json"))
result, err := client.CreateAWSCloudWatchIntegration(context.Background(), &integration.AwsCloudWatchIntegration{
Type: "AWSCloudWatch",
})
assert.NoError(t, err, "Unexpected error creating integration")
assert.Equal(t, "string", result.Name, "Name does not match")
assert.Equal(t, int64(600000), result.PollRate, "PollRate does not match")
}
func TestGetAWSCloudWatchIntegration(t *testing.T) {
teardown := setup()
defer teardown()
mux.HandleFunc("/v2/integration/id", verifyRequest(t, "GET", true, http.StatusOK, nil, "integration/create_aws_success.json"))
result, err := client.GetAWSCloudWatchIntegration(context.Background(), "id")
assert.NoError(t, err, "Unexpected error getting integration")
assert.Equal(t, "string", result.Name, "Name does not match")
}
func TestUpdateAWSCloudWatchIntegration(t *testing.T) {
teardown := setup()
defer teardown()
mux.HandleFunc("/v2/integration/id", verifyRequest(t, "PUT", true, http.StatusOK, nil, "integration/create_aws_success.json"))
cwIntegration := integration.AwsCloudWatchIntegration{
NamespaceSyncRules: []*integration.AwsNameSpaceSyncRule{
{
Namespace: "AWS/SomeNewNamespace",
},
},
Services: []integration.AwsService{"AWS/AnotherNewNamespace"},
Type: "AWSCloudWatch",
}
result, err := client.UpdateAWSCloudWatchIntegration(context.Background(), "id", &cwIntegration)
assert.NoError(t, err, "Unexpected error creating integration")
assert.Equal(t, "string", result.Name, "Name does not match")
assert.Equal(t, integration.AwsService("AWS/SomeNewNamespace"), result.NamespaceSyncRules[0].Namespace,
"NamespaceSyncRules[0].Namespace does not match")
assert.Equal(t, integration.AwsService("AWS/AnotherNewNamespace"), result.Services[0], "Services[0] does not match")
}
func TestUpdateAWSCloudWatchIntegrationMetricStatsToSync(t *testing.T) {
teardown := setup()
defer teardown()
mux.HandleFunc("/v2/integration/id", verifyRequest(t, "PUT", true, http.StatusOK, nil, "integration/create_aws_metric_stats_to_sync_success.json"))
metricStatsToSync := map[string]map[string][]string{
"AWS/EC2": {
"NetworkPacketsIn": []string{"p95", "p99"},
},
"AWS/ECS": {
"CPUReservation": []string{"mean"},
"CPUUtilization": []string{"upper", "mean", "p95", "p99", "p99.5"},
},
}
result, err := client.UpdateAWSCloudWatchIntegration(context.Background(), "id", &integration.AwsCloudWatchIntegration{
Type: "AWSCloudWatch",
MetricStatsToSync: metricStatsToSync,
})
assert.NoError(t, err, "Unexpected error creating integration")
assert.Equal(t, metricStatsToSync, result.MetricStatsToSync, "MetricStatsToSync does not match")
}
func TestUpdateAWSCloudWatchIntegrationMetricStreams(t *testing.T) {
teardown := setup()
defer teardown()
mux.HandleFunc("/v2/integration/id", verifyRequest(t, "PUT", true, http.StatusOK, nil, "integration/create_aws_metric_streams_success.json"))
result, err := client.UpdateAWSCloudWatchIntegration(context.Background(), "id", &integration.AwsCloudWatchIntegration{
Type: "AWSCloudWatch",
MetricStreamsSyncState: "ENABLED",
})
assert.NoError(t, err, "Unexpected error creating integration")
assert.Equal(t, "ENABLED", result.MetricStreamsSyncState, "MetricStreamsSyncState does not match")
}
func TestUpdateAWSCloudWatchIntegrationLogsSyncState(t *testing.T) {
teardown := setup()
defer teardown()
mux.HandleFunc("/v2/integration/id", verifyRequest(t, "PUT", true, http.StatusOK, nil, "integration/create_aws_logs_sync_state_success.json"))
result, err := client.UpdateAWSCloudWatchIntegration(context.Background(), "id", &integration.AwsCloudWatchIntegration{
Type: "AWSCloudWatch",
LogsSyncState: "ENABLED",
})
assert.NoError(t, err, "Unexpected error creating integration")
assert.Equal(t, "ENABLED", result.LogsSyncState, "LogsSyncState does not match")
}
func TestCreateAWSCloudWatchIntegrationCustomNamespacesOnly(t *testing.T) {
teardown := setup()
defer teardown()
mux.HandleFunc("/v2/integration", verifyRequest(t, "POST", true, http.StatusOK, nil, "integration/create_aws_custom_namespaces_only.json"))
result, err := client.CreateAWSCloudWatchIntegration(context.Background(), &integration.AwsCloudWatchIntegration{
Type: "AWSCloudWatch",
})
assert.NoError(t, err, "Unexpected error creating integration")
assert.Equal(t, true, result.SyncCustomNamespacesOnly, "SyncCustomNamespacesOnly does not match")
assert.Equal(t, []*integration.AwsCustomNameSpaceSyncRule{{Namespace: "AWS/Foo"}, {Namespace: "AWS/Bar"}},
result.CustomNamespaceSyncRules, "CustomNamespaceSyncRules does not match")
}
func TestDeleteAWSCloudWatchIntegration(t *testing.T) {
teardown := setup()
defer teardown()
mux.HandleFunc("/v2/integration/id", verifyRequest(t, "DELETE", true, http.StatusNoContent, nil, ""))
err := client.DeleteAWSCloudWatchIntegration(context.Background(), "id")
assert.NoError(t, err, "Unexpected error creating integration")
}