-
Notifications
You must be signed in to change notification settings - Fork 23
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 mocks and unit tests to http and msgraph packages #2
Conversation
- added OAuth2 credentials a config values
Added a mocks package that mocks out the functionality of some the interfaces needed by the oauth handlers. This allows testing of each error check within the oauth handler functions. I also added github.com/jarcoal/httpmock as a dependecy to test both the oauth code to token exchange and each of the calls that will be made out to the microsoft graph API. The tests cover how all errors are encountered for the oauth connection. They also ensure that access token refreshing happens when the token is expired. This tests to make sure the golang oauth client works out of the box for this plugin.
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.
Overall 👍, just a couple nits, and suggested #3 as a separate PR.
Also @cpurta please sign the CLA in the link above. |
@cpurta |
Signed the CLA yesterday and now seeing the bot recognize that. Also just merge the |
This includes moving all of the tests to their own subpackages to allow for a cleaner workspace. Move all the mock interfaces to the test_http package as they are only needed there currently. Update mock interfaces to use github.com/stretchr/testify/mock to conform to Mattermost mock standards. Also addresses any naming convention comments in this commit as well.
Per @cpoile we are migrating the mocked interfaces from stretchr/testify/mock to instead be generated and used via gomock. I have added a new makefile target to generate the mock interfaces using mockgen. In addition I have generated those mocks to be used in the unit tests in the test_http package. All of those unit tests have been updated to use the generated mocks as well.
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.
Nice @cpurta, looks better now! I made a comment about the design and what the mocks are really testing. Once that's solved, this should be good to go.
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.
Generally, looks good, just a few nits. I'll wait until @cpoile is happy with the gomock changes, then will do one final pass?
@cpurta Also, as soon as you want to let us know the PR is ready for another review, hit the |
Refactored the mocks to be a part of the testcase struct and then pass those to a `setupMocks` function which allow for custom mock behavior. This sigificantly reduces the code for setup and allows for more customizable mocks. Also addressing some of @levb comments on package names for the test folders and naming convention.
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.
Awesome, looking better, almost there. :)
Let me know if you have any questions (I'm always on MM).
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.
Thanks @cpurta!
Just a couple more cases of not needed test cases fields.
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.
Awesome, thanks @cpurta!
@levb Final pass? |
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.
LGTM!
…a single user" by added additional logging (#245) * [MI-2664]:Fixed issue #244 on ms calender to add additional logging (#2) * [MI-2664]:Fixed issue #244 on ms calender to add additional logging * [MI-2664]:Added comment for skipping user * [MI-2664]:Fixed unit test cases * [MI-2664]:Fix lint errors * [MI-2664]:Added conditional logging * [MI-2664]:Added constants for limit * [MI-2664]:Fixed review comments * [MI-2664]:Fixed review comments * [MI-2687]:Fixed review comments given by mattermost team on issue#244 of mscalender plugin (#3) * [MI-2687]:Fixed review comments given by mattermost team on issue #244 of mscalender plugin * [MI-2687]:Fixed unit test cases * [MI-2687]:Fixed review fixes * [MI-2705]:Added summary for status sync job (#4) * [MI-2705]:Added summary for status sync job * [MI-2705]:Fixed review comments * Fixed lint errors (#243) * [MI-2705]:Fixed review comments * [MI-2705]:Fixed review comments --------- Co-authored-by: Manoj Malik <[email protected]> * [MM-244]:Fixed lint errors * [MM-244]:Added a check for summary to be nill * [MM-244]:Added addtional check for user error * [MM-244]:Fixed lint errors * [MM-244]:Fixed review comments --------- Co-authored-by: Manoj Malik <[email protected]>
Added a mocks package that mocks out the functionality of some the
interfaces needed by the oauth handlers. This allows testing of each
error check within the oauth handler functions. I also added
github.com/jarcoal/httpmock as a dependecy to test both the oauth code
to token exchange and each of the calls that will be made out to the
microsoft graph API.
The tests cover how all errors are encountered for the oauth connection.
They also ensure that access token refreshing happens when the token is
expired. This tests to make sure the golang oauth client works out of
the box for this plugin.
This will also resolve #3