-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmonitoring_test.go
44 lines (38 loc) · 1.25 KB
/
monitoring_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
package gokini
import (
"testing"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/aws/aws-sdk-go/service/cloudwatch/cloudwatchiface"
)
type mockCloudWatch struct {
cloudwatchiface.CloudWatchAPI
metricData []*cloudwatch.MetricDatum
}
func (m *mockCloudWatch) PutMetricData(input *cloudwatch.PutMetricDataInput) (*cloudwatch.PutMetricDataOutput, error) {
m.metricData = append(m.metricData, input.MetricData...)
return &cloudwatch.PutMetricDataOutput{}, nil
}
func TestCloudWatchMonitoring(t *testing.T) {
mockCW := &mockCloudWatch{}
cwService := &cloudWatchMonitoringService{
Namespace: "testCloudWatchMonitoring",
KinesisStream: "cloudwatch_monitoring",
WorkerID: "abc123",
ResolutionSec: 1,
Session: session.New(),
svc: mockCW,
shardMetrics: map[string]*cloudWatchMetrics{},
}
cwService.incrRecordsProcessed("00001", 10)
err := cwService.flush()
if err != nil {
t.Errorf("Received error sending data to cloudwatch %s", err)
}
if len(mockCW.metricData) < 1 {
t.Fatal("Expected at least one metric to be sent to cloudwatch")
}
if *mockCW.metricData[0].Value != float64(10) {
t.Errorf("Expected metric value to be 10.0, got %f", *mockCW.metricData[0].Value)
}
}