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 112a0bc
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions aws/cwatch/mock/mock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package mock

import (
"sync"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"
"github.com/nyaruka/gocommon/aws/cwatch"
)

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 26 in aws/cwatch/mock/mock.go

View check run for this annotation

Codecov / codecov/patch

aws/cwatch/mock/mock.go#L19-L26

Added lines #L19 - L26 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 33 in aws/cwatch/mock/mock.go

View check run for this annotation

Codecov / codecov/patch

aws/cwatch/mock/mock.go#L29-L33

Added lines #L29 - L33 were not covered by tests
}

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

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

View check run for this annotation

Codecov / codecov/patch

aws/cwatch/mock/mock.go#L36-L38

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

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

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

View check run for this annotation

Codecov / codecov/patch

aws/cwatch/mock/mock.go#L41-L42

Added lines #L41 - L42 were not covered by tests
}

var _ cwatch.CWService = (*MockCWService)(nil)

0 comments on commit 112a0bc

Please sign in to comment.