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

awsbase: Add unit testing for session code base #9

Merged
merged 13 commits into from
Oct 2, 2019

Conversation

nywilken
Copy link
Contributor

@nywilken nywilken commented Aug 2, 2019

The changes within this branch are a fast past at extending the testing with the awsbase pkg. In its present state it adds some basic checks for the GetSession* logic using some of the existing AWS mocks. During this exercise I've started work in looking through the tests and code structure to determine how authentication is flowing. While looking for any special edge cases or chaining that is occurring to better understand the coverage of the authentication testing already in place. This PR is merely a starting step, and anyone reviewing this code is welcome to provide feedback, improvement suggestions.

Relates #4
Relates #5
Relates #7

Goals:

  • Test all AWS supported GetSession use cases
  • Test AWS authentication precedence as documented for the AWS Terraform Provider
  • Enable Travis CI on master and new pull-requests (make lint && make test)

This change splits out the httptest.Server creation from the
GetMockedAwsApiSession function so that the test server can be used
for mocking other API responses.

Tests before change
```
> go test ./...
ok      github.com/hashicorp/aws-sdk-go-base    1.814s
```

Tests after change
```
> go test ./...
ok      github.com/hashicorp/aws-sdk-go-base    1.575s
```
@hashicorp-cla
Copy link

hashicorp-cla commented Aug 2, 2019

CLA assistant check
All committers have signed the CLA.

session.go Outdated
@@ -33,40 +33,7 @@ func GetSessionOptions(c *Config) (*session.Options, error) {
return nil, err
}

// Call Get to check for credential provider. If nothing found, we'll get an
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking through the chain of events there appears to be an error check for the "NoCredentialProviders" error within the call to GetCredentials which then gets bubbled up here. So I removed this call for now and validated that with the current testing in place nothing breaks. This still needs some additional validation 🤷‍♂️

session.go Outdated

if err == nil {
return sess, accountID, partition, nil
if err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy path - return if there is an error. Otherwise continue happily down the path of normal execution.

session_test.go Outdated
t.Fatalf("GetSessionOptions(c) resulted in an error %s", err)
}

if opts == nil && tc.hasError == false {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Open question: What is the best way to validate the returned session?

@aeschright aeschright self-assigned this Aug 2, 2019
@nywilken nywilken added the tests label Aug 2, 2019
awsauth_test.go Outdated Show resolved Hide resolved
@aeschright aeschright marked this pull request as ready for review October 2, 2019 18:44
@aeschright aeschright merged commit cf17a84 into master Oct 2, 2019
@aeschright aeschright deleted the td-awsbase-package-testing branch October 2, 2019 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants