-
Notifications
You must be signed in to change notification settings - Fork 413
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
Move generated ExpecterTest to mocks directory #454
Conversation
Codecov Report
@@ Coverage Diff @@
## master #454 +/- ##
===========================================
- Coverage 70.76% 45.81% -24.95%
===========================================
Files 7 40 +33
Lines 1293 1997 +704
===========================================
Hits 915 915
- Misses 325 1029 +704
Partials 53 53
Continue to review full report at Codecov.
|
@LandonTClipp As far as I can see the command |
mocks/pkg/fixtures/ExpecterTest.go
Outdated
@@ -1,18 +1,26 @@ | |||
// Code generated by mockery. DO NOT EDIT. | |||
// Code generated by mockery v1.0.0. DO NOT EDIT. |
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.
This looks like you used the wrong version to generate the mocks...strange.
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.
Agreed, could you verify what mockery you're using to build the mocks? These version strings should be disabled so this is telling me that your mockery probably wasn't reading the config properly. (maybe we should re-introduce the version numbers?)
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.
I hadn't used the Makefile, fixed now
@Gevrai I think the mocks are generated correctly (but I might be wrong, please post details if you are sure). The issue here is that you combine the generated mocks and the fixtures in an unusual way for this repo IMO. All generator tests have their expected output in the generator test itself. I think the best way forward is to just update the expecter test to behave the same as other tests, and I'll look into it later and try to move these fixed strings to separate files. The problem with what you did (I think) is that you say that you expect the generated code to be equal to the mock file, but the mock file itself is generated by the generator, so this test doesn't really validate anything. I might be wrong though... |
Oh, my bad I didn't think those were autogenerated anymore, when doing I saw that there were some other tests reading from expected file (
I would kind of want to keep the unit tests for the autogenerated expecter (file now at I would be strongly in favor having the fixed string in separate files, maybe even some kind of setup were we can have a full test defined in a file as
You are right, for the future at least. I didn't run regenerate the directory on my side so for now so it is indeed validating that the output is valid, but that would be overwritten as soon as the directory is regenerated... |
pkg/generator_test.go
Outdated
@@ -240,7 +240,7 @@ func NewRequester(t testing.TB) *Requester { | |||
} | |||
|
|||
func (s *GeneratorSuite) TestGeneratorExpecterComplete() { | |||
expectedBytes, err := ioutil.ReadFile(getFixturePath("mocks", "expecter.go")) | |||
expectedBytes, err := ioutil.ReadFile(getMocksPath("ExpecterTest.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.
The thing I agree with @grongor here is that it's odd to be asserting the output of mockery with the output of mockery (you see what I mean?). You are generating ExepcterTest.go
in the mocks
package, then you generate it again in this test and assert that it's the same. It's not necessarily wrong to do it this way, but none of the other tests do it this way (see TestGeneratorFunction
below).
Although, I can see an argument to be made that because the Expecter
interface is so verbose in the generated code, that cluttering the tests with expected code would be too much. But I think that for this case, we really should have the expected code as a raw string in the test.
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.
I think we should stick with how the tests are done for now (strings directly in the test), but definitely look for improvements later on. As you mentioned, asserting mockery with mockeries output isn't correct, but we definitely can improve the readability of the tests, maybe even the way @Gevrai described. But it definitely is out of the scope of this, and it's a bigger decision that should be done correctly (so that we don't face it again in a year, hopefully :D ).
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.
I do really like the idea of keeping unit tests for the generated mocks (mocks/pkg/fixtures/ExpecterTest_test.go
), that can probably stay. I think we should have more of these unit tests on the generated mocks as another layer.
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.
@Gevrai let me know if you could make the change (expected output as a string literal in the test). We can get it merged once that's settled. Thanks!
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.
Hey sorry! Things got in the way a bit, I'll have it done this evening.
Just to make sure
- Keep test in mocks/pkg/fixtures/ExpecterTest_test.go
- Inline generated expecter check instead of reading from file
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.
No worries thanks again for the contributions. Yeah those two points should be it! (and the merge conflicts that just popped up)
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.
Done, should be good now.
FYI I've changed the name of the interface (ExpecterTest -> Expecter) for coherence with others, and added the expecter to be generated by Makefile so that the unit tests have something to run on!
fe03e28
to
f9cad3c
Compare
f9cad3c
to
cde38d9
Compare
branch rebased |
Thanks @Gevrai you read my mind. |
Description
Fixes the location of the
--expecter
tests mocks, as requested in #396 (comment)Type of change
Test files moved to correct location, new behaviour change for users.
Version of Golang used when building/testing:
How Has This Been Tested?
Tested with
go test ./...
on full projectChecklist