-
Notifications
You must be signed in to change notification settings - Fork 36
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
Conversation
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 ```
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
99ecdfb
to
dcb8992
Compare
75e7341
to
f305c19
Compare
…ls flow Add -v to CI test run for better debugging
Rename AWS metadata 'endpoint' for clarity
f305c19
to
86893be
Compare
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:
make lint && make test
)