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 mocks and unit tests to http and msgraph packages #2

Merged
merged 14 commits into from
Nov 21, 2019

Conversation

cpurta
Copy link
Contributor

@cpurta cpurta commented Nov 12, 2019

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

Lev Brouk and others added 6 commits October 31, 2019 06:24
- 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.
Copy link
Contributor

@levb levb left a 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.

server/http/http.go Show resolved Hide resolved
server/http/oauth2_complete_test.go Outdated Show resolved Hide resolved
server/http/oauth2_complete_test.go Outdated Show resolved Hide resolved
server/http/oauth2_complete_test.go Outdated Show resolved Hide resolved
server/http/oauth2_complete_test.go Outdated Show resolved Hide resolved
@levb levb requested a review from cpoile November 13, 2019 14:24
@levb levb added the 2: Dev Review Requires review by a core committer label Nov 13, 2019
@levb
Copy link
Contributor

levb commented Nov 13, 2019

Also @cpurta please sign the CLA in the link above.

@levb levb added this to the 0.1.0 milestone Nov 13, 2019
@levb
Copy link
Contributor

levb commented Nov 13, 2019

@cpurta dev has been merged, so you can re-base/re-point to master now.

@cpurta cpurta changed the base branch from dev to master November 13, 2019 16:44
@cpurta
Copy link
Contributor Author

cpurta commented Nov 13, 2019

Signed the CLA yesterday and now seeing the bot recognize that. Also just merge the master into my branch and everything is looking up to date.

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.
@hanzei hanzei added Do Not Merge Should not be merged until this label is removed and removed Do Not Merge Should not be merged until this label is removed labels Nov 13, 2019
Chris Purta added 2 commits November 14, 2019 13:05
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.
@hanzei hanzei requested a review from levb November 15, 2019 04:49
Copy link
Member

@cpoile cpoile left a 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.

server/http/test_http/oauth2_complete_test.go Outdated Show resolved Hide resolved
@levb levb added Do Not Merge/Awaiting PR Awaiting another pull request before merging (e.g. server changes) and removed Do Not Merge/Awaiting PR Awaiting another pull request before merging (e.g. server changes) labels Nov 18, 2019
Copy link
Contributor

@levb levb left a 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?

server/http/test_http/mock_response_writer.go Outdated Show resolved Hide resolved
server/http/test_http/oauth2_complete_test.go Outdated Show resolved Hide resolved
server/http/test_http/oauth2_complete_test.go Outdated Show resolved Hide resolved
server/http/test_http/oauth2_complete_test.go Outdated Show resolved Hide resolved
server/http/test_http/oauth2_complete_test.go Outdated Show resolved Hide resolved
@cpoile
Copy link
Member

cpoile commented Nov 18, 2019

@cpurta Also, as soon as you want to let us know the PR is ready for another review, hit the refresh symbol next to our names in the top right -- that will ping us through the Mattermost Github plugin that it's time to take another look. :)

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.
@cpurta cpurta requested review from levb and cpoile November 19, 2019 18:04
Copy link
Member

@cpoile cpoile left a 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).

server/http/testhttp/oauth2_complete_test.go Outdated Show resolved Hide resolved
server/http/testhttp/oauth2_connect_test.go Outdated Show resolved Hide resolved
@cpurta cpurta requested a review from cpoile November 20, 2019 17:29
Copy link
Member

@cpoile cpoile left a 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.

server/http/testhttp/oauth2_complete_test.go Outdated Show resolved Hide resolved
server/http/testhttp/oauth2_complete_test.go Outdated Show resolved Hide resolved
server/http/testhttp/oauth2_connect_test.go Outdated Show resolved Hide resolved
server/http/testhttp/oauth2_connect_test.go Outdated Show resolved Hide resolved
@cpurta cpurta requested a review from cpoile November 21, 2019 16:51
Copy link
Member

@cpoile cpoile left a comment

Choose a reason for hiding this comment

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

Awesome, thanks @cpurta!

@cpoile
Copy link
Member

cpoile commented Nov 21, 2019

@levb Final pass?

Copy link
Contributor

@levb levb left a comment

Choose a reason for hiding this comment

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

LGTM!

@levb levb added 4: Reviews Complete All reviewers have approved the pull request and removed 2: Dev Review Requires review by a core committer labels Nov 21, 2019
@levb levb merged commit 5bd5bd2 into mattermost:master Nov 21, 2019
mickmister pushed a commit that referenced this pull request Mar 22, 2023
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use github.com/stretchr/testify/mock for unit tests
4 participants