Skip to content

Commit

Permalink
Add MockCWService for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Dec 13, 2024
1 parent c89192c commit 69cdba3
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions aws/cwatch/mock.go
Original file line number Diff line number Diff line change
@@ -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

Check warning on line 25 in aws/cwatch/mock.go

View check run for this annotation

Codecov / codecov/patch

aws/cwatch/mock.go#L18-L25

Added lines #L18 - L25 were not covered by tests
}

func (s *MockCWService) Queue(d types.MetricDatum) {
if s.Stopped {
return
}
s.Batcher = append(s.Batcher, d)

Check warning on line 32 in aws/cwatch/mock.go

View check run for this annotation

Codecov / codecov/patch

aws/cwatch/mock.go#L28-L32

Added lines #L28 - L32 were not covered by tests
}

func (s *MockCWService) StartQueue(wg *sync.WaitGroup) {
s.Batcher = []types.MetricDatum{}

Check warning on line 36 in aws/cwatch/mock.go

View check run for this annotation

Codecov / codecov/patch

aws/cwatch/mock.go#L35-L36

Added lines #L35 - L36 were not covered by tests
}

func (s *MockCWService) StopQueue() {
s.Stopped = true

Check warning on line 40 in aws/cwatch/mock.go

View check run for this annotation

Codecov / codecov/patch

aws/cwatch/mock.go#L39-L40

Added lines #L39 - L40 were not covered by tests
}

var _ CWService = (*MockCWService)(nil)

0 comments on commit 69cdba3

Please sign in to comment.