Skip to content

Commit

Permalink
add MockOptionErr to expose mocking out an options error
Browse files Browse the repository at this point in the history
  • Loading branch information
vancluever committed Oct 4, 2021
1 parent 79c4376 commit d07ba63
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 2 additions & 6 deletions awsutil/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ import (
const testOptionErr = "test option error"
const testBadClientType = "badclienttype"

func testWithOptionError(_ *options) error {
return errors.New(testOptionErr)
}

func testWithBadClientType(o *options) error {
o.withClientType = testBadClientType
return nil
Expand All @@ -35,7 +31,7 @@ func TestCredentialsConfigIAMClient(t *testing.T) {
{
name: "options error",
credentialsConfig: &CredentialsConfig{},
opts: []Option{testWithOptionError},
opts: []Option{MockOptionErr(errors.New(testOptionErr))},
requireErr: fmt.Sprintf("error reading options: %s", testOptionErr),
},
{
Expand Down Expand Up @@ -93,7 +89,7 @@ func TestCredentialsConfigSTSClient(t *testing.T) {
{
name: "options error",
credentialsConfig: &CredentialsConfig{},
opts: []Option{testWithOptionError},
opts: []Option{MockOptionErr(errors.New(testOptionErr))},
requireErr: fmt.Sprintf("error reading options: %s", testOptionErr),
},
{
Expand Down
7 changes: 7 additions & 0 deletions awsutil/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import (
"github.com/aws/aws-sdk-go/service/sts/stsiface"
)

// MockOptionErr provides a mock option error for use with testing.
func MockOptionErr(withErr error) Option {
return func(_ *options) error {
return withErr
}
}

// MockIAM provides a way to mock the AWS IAM API.
type MockIAM struct {
iamiface.IAMAPI
Expand Down

0 comments on commit d07ba63

Please sign in to comment.