Skip to content

Commit

Permalink
Merge 30dc630 into 35e7744
Browse files Browse the repository at this point in the history
  • Loading branch information
cep21 committed Jul 28, 2019
2 parents 35e7744 + 30dc630 commit 4725ee0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pager.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ var _ error = &multiErr{}

// Error returns a combined error string
func (m *multiErr) Error() string {
ret := "Multiple errors: "
ret := "multiple errors: "
for i, e := range m.err {
if i != 0 {
ret += ","
Expand Down
7 changes: 7 additions & 0 deletions pager_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ func (m *memoryCloudWatchClient) GetMetricStatistics(input *cloudwatch.GetMetric
func (m *memoryCloudWatchClient) PutMetricDataWithContext(ctx aws.Context, in *cloudwatch.PutMetricDataInput, opts ...request.Option) (*cloudwatch.PutMetricDataOutput, error) {
m.mu.Lock()
defer m.mu.Unlock()
if len(in.GoString()) > putMetricDataKBRequestSizeLimit*2 {
// Simulate large request errors
// Multiply by two (arbitrary value) since it's allowed to be a bit bigger (will be gzip)
return nil, &awsRequestSizeError{
size: len(in.GoString()),
}
}
m.in = append(m.in, in)
if len(m.in) == m.errOnCall {
return nil, m.err
Expand Down
47 changes: 46 additions & 1 deletion pager_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package cwpagedmetricput

import (
"errors"
"reflect"
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/stretchr/testify/require"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudwatch"
)

Expand Down Expand Up @@ -58,3 +60,46 @@ func Test_clearInvalidUnits(t *testing.T) {
})
}
}

func Test_consolidateErr(t *testing.T) {
tests := []struct {
name string
args []error
validate func(error)
}{
{
name: "nil",
args: nil,
validate: func(err error) {
require.NoError(t, err)
},
},
{
name: "single",
args: []error{errors.New("single")},
validate: func(err error) {
require.Equal(t, "single", err.Error())
},
},
{
name: "manynil",
args: []error{nil, nil},
validate: func(err error) {
require.NoError(t, err)
},
},
{
name: "many",
args: []error{errors.New("first"), errors.New("second")},
validate: func(err error) {
require.Equal(t, "multiple errors: first,second", err.Error())
},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
tt.validate(consolidateErr(tt.args))
})
}
}

0 comments on commit 4725ee0

Please sign in to comment.