-
-
Notifications
You must be signed in to change notification settings - Fork 147
feat: Add ability to ignore interface{} population with SetIgnoreInterface() #123
Conversation
This reverts commit e78f28e.
Codecov Report
@@ Coverage Diff @@
## master #123 +/- ##
==========================================
- Coverage 93.87% 92.17% -1.70%
==========================================
Files 11 11
Lines 1289 1086 -203
==========================================
- Hits 1210 1001 -209
- Misses 43 46 +3
- Partials 36 39 +3
Continue to review full report at Codecov.
|
…e of numbers. Good for reliable testing of 0 values.
Hi @nashikb Thanks for the PR, I was so busy lately, haven't seen this repo for a while. type Person struct {
Metadata interface{} `faker:"-"`
} |
This works for It could be worth at least considering ignoring |
I see that makes sense. I wonder if we can add a test-case but using 3rd party library that contains the interface as you explained. Just to making sure. |
I think, let's merge this. |
Of course. We've been using this tweak in our tests since October '20 with no issues, so I'm pretty confident a merge-down will work just fine. As for an external use case, that does make sense; but my concern was adding a dependency on faker tests that could silently break. Also, using a struct without 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.
Alright, thanks for the PR
@nashikb |
Running my tests with GO111MODULE=off works fine off of master (hitting master via go.mod and the v3 path in the go.mod is tough). My tests use 100s of repeated randomizations of structs, so I'm pretty confident nothing's amiss. (famous last words) Once there's a release I'll immediately test again and delete my fork. Thanks! |
How's the release going? :-) |
https://github.com/bxcodec/faker/releases/tag/v3.6.0 released here. Anyway, if you have time, mind adding some docs or examples? It's okay if you're busy. I'll try to look up on it this weekend |
I've switched over and all my tests are passing, so it looks good to me. I'll look at a quick drawup on the reasoning and examples. |
After putting together this very artificial example, I realize that the testing harnesses I'm working with are fairly esoteric and particular to conversions to JSON wrappers like grpc-gateway. This is an example testify test that shows how ignoring interfaces can be useful for faking and comparing partial structures net interface{}es.
|
This PR adds a flag that tells faker to ignore the population of interface{} types.
This is useful when populating complex structures for Marshal testing, where you don't have the control or ability to use a non-interface{}. This makes testing complex structure marshaling a LOT simpler, since otherwise you would have to faker every element in the structure above and beside an interface{}.
The default behavior is to not ignore interface{}, so no behavior changes should be seen.
A test has been added.
Thanks!