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 ab724df commit 7421f1a
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions aws/cwatch/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,36 @@ type CWService interface {
}

var _ CWService = (*Service)(nil)

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 98 in aws/cwatch/service.go

View check run for this annotation

Codecov / codecov/patch

aws/cwatch/service.go#L91-L98

Added lines #L91 - L98 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 105 in aws/cwatch/service.go

View check run for this annotation

Codecov / codecov/patch

aws/cwatch/service.go#L101-L105

Added lines #L101 - L105 were not covered by tests
}

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

Check warning on line 109 in aws/cwatch/service.go

View check run for this annotation

Codecov / codecov/patch

aws/cwatch/service.go#L108-L109

Added lines #L108 - L109 were not covered by tests
}

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

Check warning on line 113 in aws/cwatch/service.go

View check run for this annotation

Codecov / codecov/patch

aws/cwatch/service.go#L112-L113

Added lines #L112 - L113 were not covered by tests
}

0 comments on commit 7421f1a

Please sign in to comment.