From b7ec4abe84e05fc13acdd53f77a10738e780c244 Mon Sep 17 00:00:00 2001 From: Norbert Kwizera Date: Fri, 13 Dec 2024 13:10:58 +0200 Subject: [PATCH] Add MockCWService for testing --- aws/cwatch/mock.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 aws/cwatch/mock.go diff --git a/aws/cwatch/mock.go b/aws/cwatch/mock.go new file mode 100644 index 0000000..0091659 --- /dev/null +++ b/aws/cwatch/mock.go @@ -0,0 +1,43 @@ +package cwatch + +import ( + "sync" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/cloudwatch/types" +) + +type MockCWService struct { + namespace string + deployment types.Dimension + Batcher []types.MetricDatum + + Stopped bool +} + +func NewMockCWService(accessKey, secretKey, region, namespace, deployment string) (*MockCWService, error) { + mockCW := MockCWService{ + namespace: namespace, + deployment: types.Dimension{Name: aws.String("Deployment"), Value: aws.String(deployment)}, + Batcher: nil, + } + + return &mockCW, nil +} + +func (s *MockCWService) Queue(d types.MetricDatum) { + if s.Stopped { + return + } + s.Batcher = append(s.Batcher, d) +} + +func (s *MockCWService) StartQueue(wg *sync.WaitGroup) { + s.Batcher = []types.MetricDatum{} +} + +func (s *MockCWService) StopQueue() { + s.Stopped = true +} + +var _ CWService = (*MockCWService)(nil)