Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit testing for IsAWSErr() and IsAWSErrExtended(), prevent missing OrigErr() panic #16

Merged
merged 2 commits into from
Oct 30, 2019

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Oct 30, 2019

Reference: hashicorp/terraform-provider-aws#10670

This was originally to just add unit testing to match testing added to the Terraform AWS Provider codebase, but discovered and fixed a panic condition in IsAWSErrExtended().

In the future these functions will be updated to support Go 1.13 error wrapping via errors.As() so we can easily add error context without losing the error type checking, however this is waiting for github.com/hashicorp/terraform to begin releases via Go 1.13.

…ng OrigErr() panic

Reference: hashicorp/terraform-provider-aws#10670

This was originally to just add unit testing to match testing added to the Terraform AWS Provider codebase, but discovered and fixed a panic condition in `IsAWSErrExtended()`.

In the future these functions will be updated to support Go 1.13 error wrapping via `errors.As()` so we can easily add error context without losing the error type checking, however this is waiting for github.com/hashicorp/terraform to begin releases via Go 1.13.
@bflad bflad added the bug Something isn't working label Oct 30, 2019
Err error
Code string
Message string
Expected bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see Expected set on most of the test cases, are you relying on a default behavior?

Copy link
Contributor Author

@bflad bflad Oct 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Go, each type has an associated zero value and for bool it is false. I'm not sure I necessarily have good reference of linters that check for this specifically or documentation for whether or not its idiomatic to rely on zero values in composite literals other than maybe this section of Effective Go. If we'd prefer explicitly writing out Expected: false, in places though, can certainly update this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's consistent so I think this is ok. I have a general preference for explicit defaults -- but I'm still getting used to the Go testing framework, so I'm not going to be pushy about what that should look like.

awserr.go Outdated Show resolved Hide resolved
Copy link
Contributor

@aeschright aeschright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a couple of style questions inline but otherwise this is fine.

@bflad bflad requested a review from aeschright October 30, 2019 20:29
Copy link
Contributor

@aeschright aeschright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@bflad bflad merged commit 91fe567 into master Oct 30, 2019
@bflad bflad deleted the b-IsAwsErrExtended-panic branch October 30, 2019 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants