-
Notifications
You must be signed in to change notification settings - Fork 520
Split-up git test into unit and integration parts #1017
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
Conversation
pkg/git/git_test.go
Outdated
|
||
err := testRepo.sut.Push(Master) | ||
require.Nil(t, err) | ||
func (r *repoMock) CommitObject(plumbing.Hash) (*object.Commit, error) { |
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.
TL;DR: I'd highly recommend counterfeiter
(or something similar) over implementing the fakes yourself.
Instead of implementing the fakes yourself, you could use counterfeiter
(& go generate
).
E.g. this allows you to just run go generate ./...
and it will create / update the fake for you. The fake then has nice methods to check on call counts and call args, stub whole method calls, inject fake return values, and those kinda things. When you are generating fakes for exported interfaces/funcs it will also add a compile time assertion to check if the fake actually implements the interface (to avoid drift). However, you can also fake unexported stuff just fine.
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.
Okay cool, I'm now using the counterfeiter
generated mocks. The thing is that we now have to provide two additional methods to overwrite the inner
and worktree
to avoid making them public... I also cannot use the same package because I will get a cyclic import if I do so...
This is ready for review, too :) |
This looks great from my feeble testing understanding, but I'd like to leave @hoegaarden and @hasheddan as final approvers here. /hold unhold once they approve |
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.
Glad to see the use of counterfeiter
here :)
/lgtm
/hold cancel |
Had to rebase on top of the latest master branch. |
We now use a dedicated file-name pattern for integration tests and unit tests. The unit tests introduce a new layer of mockability via the public `Repository` and `Worktree` interfaces. These interfaces are used inside the tests to spy on the method call. Signed-off-by: Sascha Grunert <[email protected]>
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hasheddan, justaugustus, saschagrunert The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
We now use a dedicated file-name pattern for integration tests and unit
tests. The unit tests introduce a new layer of mockability via the
public
Repository
andWorktree
interfaces. These interfaces areused inside the tests to spy on the method call.
Needs #1014