-
Notifications
You must be signed in to change notification settings - Fork 1k
Conversation
419855f
to
8f12cdb
Compare
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've not reviewed in detail, but this seems fundamentally 💯 sane. however, we definitely want to use subtests for this! if you've not used them before, just grep for t.Run(
in the project - we use them all over the place, plenty of examples to go from.
cmd/dep/glide_importer_test.go
Outdated
defer sm.Release() | ||
|
||
for name, testCase := range testCases { | ||
t.Logf("Running test case: %s", name) |
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.
Ideal situation for using subtests, here 😄
Cool, thanks for the review! I haven't used sub tests, but I'll read up and
push a fix for that.
Cheers
…On Wed, 26 Jul 2017 at 14:20 sam boyer ***@***.***> wrote:
***@***.**** requested changes on this pull request.
i've not reviewed in detail, but this seems fundamentally 💯 sane.
however, we definitely want to use subtests for this! if you've not used
them before, just grep for t.Run( in the project - we use them all over
the place, plenty of examples to go from.
------------------------------
In cmd/dep/glide_importer_test.go
<#897 (comment)>:
> + },
+ projectRoot: testGlideProjectRoot,
+ expectConvertErr: true,
+ },
+ }
+
+ h := test.NewHelper(t)
+ defer h.Cleanup()
+
+ ctx := newTestContext(h)
+ sm, err := ctx.SourceManager()
+ h.Must(err)
+ defer sm.Release()
+
+ for name, testCase := range testCases {
+ t.Logf("Running test case: %s", name)
Ideal situation for using subtests, here 😄
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#897 (review)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AA0QLDJ2urO9inf6S5ldAPB-7v_wcMAzks5sRv3CgaJpZM4OiuFK>
.
|
I've make the changes this morning. But wondering if something is up with CI for the |
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.
gettin pretty close, just a few issues.
cmd/dep/glide_importer_test.go
Outdated
projectRoot gps.ProjectRoot | ||
sourceRepo string | ||
notExpectedProjectRoot *gps.ProjectRoot | ||
expectedConstraint string |
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.
nit: in Go-land, i've learned we apparently prefer "want" to "expect".
cmd/dep/godep_importer_test.go
Outdated
expectConvertErr bool | ||
matchPairedVersion bool | ||
projectRoot gps.ProjectRoot | ||
notExpectedProjectRoot *gps.ProjectRoot |
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.
why does this need to be a pointer?
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'm having it as a pointer to represent that it's not set. So that we can distinguish between:
- A project root
"github.com/a/b/c"
- An empty project root
""
- A test case that does not have a
notExpectedProjectRoot
test case
In other words: If it's nil
it won't be part of the test case, while making it possible to have any other value when we use it for testing.
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.
hmm. the basic argument makes sense, though it still seems like a bit of a code smell. i can't come up with a specific objection, though, so i'm OK to move ahead with it.
internal/gps/identifier.go
Outdated
@@ -40,6 +40,11 @@ import ( | |||
// the type system when a path-ish string must have particular semantics. | |||
type ProjectRoot string | |||
|
|||
// ProjectRootPtr takes a ProjectRoot value and returns a pointer. | |||
func ProjectRootPtr(p ProjectRoot) *ProjectRoot { |
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.
if we must have this (and i'm not clear on why we do), can it at least not be exported?
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 remove this and make it an unexported part of the tests. Since it's not used outside the tests I think this is not providing value to any part of the implementation.
I'll move it to the test files.
internal/gps/version.go
Outdated
@@ -198,6 +198,11 @@ func (r Revision) identical(c Constraint) bool { | |||
return r == r2 | |||
} | |||
|
|||
// RevisionPtr takes a revision value and return it's pointer. | |||
func RevisionPtr(r Revision) *Revision { |
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.
same question as with ProjectRootPtr()
Thanks, I have updated the tests according to the review feedback! |
cmd/dep/godep_importer_test.go
Outdated
@@ -53,7 +236,7 @@ func TestGodepConfig_Import(t *testing.T) { | |||
t.Fatal("Expected the lock to be generated") | |||
} | |||
|
|||
goldenFile := "godep/expected_import_output.txt" | |||
goldenFile := "godep/want_import_output.txt" | |||
got := verboseOutput.String() |
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.
Filename change 😬 seems to be causing the test to fail. No such file exists. I think it's fine to keep it expected_import_output.txt
.
cmd/dep/godep_importer_test.go
Outdated
@@ -395,3 +338,13 @@ func equalImports(a, b []godepPackage) bool { | |||
|
|||
return true | |||
} | |||
|
|||
// projectRootPtr takes a ProjectRoot value and returns a pointer. | |||
func projectRootPtr(p gps.ProjectRoot) *gps.ProjectRoot { |
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.
Here's how you can deal with these string types (gps.Revision and gps.ProjectRoot) without introducing these helper functions:
- Change the want/got in the testcase matrix from pointers to the struct type, e.g.
*gps.Revision
togps.Revision
. - Update the assignments to not use
projectRootPtr
/revisionPtr
. - Update the asserts to compare the want testcase value against the empty string, instead of nil, e.g.
if testCase.notWantedProjectRoot != "" {
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 can do that, if you'd like me to. The reason I have it this way is to be able to represent the difference between e.g. an empty notWantedProjectRoot
(""
) and a test case without a project root (nil
). Otherwise we could not test for the case where notWantedProjectRoot
is empty.
Let me know which approach you'd like and I'll adjust accordingly.
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'm on the fence - ordinarily, i'd say that we've tried to architect around situations where the zero could have multiple interpretations. but the importers are tricky, because we're converting other systems' semantics into our own, so it's harder to maintain invariants like that. at the same time, it is just a single, confined test pattern, so i don't know that it really matters too much.
either way, it's your call, @carolynvs 😄
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've laid out in the comments an alternative way to simplify the test cases and remove these helper functions. Let me know if they make sense.
I don't mean to hate on them, but if we can reorganize the tests to not need them, that would make me happy. 😀
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! I'll adjust the tests according to your comments @carolynvs. Will to that within a week, I'm currently on vacation. Thanks for the feedback!
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.
Sorry this took me so long to look at!
cmd/dep/glide_importer_test.go
Outdated
p.Ident().ProjectRoot) | ||
} | ||
|
||
if p.Ident().Source != testCase.sourceRepo { |
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.
nit: Can we rename this to wantSourceRepo
? Just to be consistent with the other fields in the test case.
cmd/dep/godep_importer_test.go
Outdated
}, | ||
}, | ||
projectRoot: gps.ProjectRoot("github.com/sdboyer/deptest"), | ||
notWantedProjectRoot: projectRootPtr(gps.ProjectRoot("github.com/sdboyer/deptest/foo")), |
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.
Between the check for an Constraint
entry for projectRoot
and the check on wantLockCount
, I would be quite happy to remove notWantedProjectRoot
entirely. It will effectively test what the importer cared about: consolidating multiple subpackages into a single entry for the root package.
Then we can remove projectRootPtr
as well. Sound good?
cmd/dep/glide_importer_test.go
Outdated
t.Fatalf("Expected locked version to be '%s', got %s", testCase.wantVersion, ver) | ||
} | ||
|
||
if testCase.wantRevision != nil { |
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.
Since we only check wantRevision
when matchPairedVersion
is set, how about simplifying it to a Revision
struct, not pointer. Then revisionPtr
can be removed as well.
cmd/dep/godep_importer_test.go
Outdated
@@ -395,3 +338,13 @@ func equalImports(a, b []godepPackage) bool { | |||
|
|||
return true | |||
} | |||
|
|||
// projectRootPtr takes a ProjectRoot value and returns a pointer. | |||
func projectRootPtr(p gps.ProjectRoot) *gps.ProjectRoot { |
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've laid out in the comments an alternative way to simplify the test cases and remove these helper functions. Let me know if they make sense.
I don't mean to hate on them, but if we can reorganize the tests to not need them, that would make me happy. 😀
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.
Wahoo! Thank you for applying some cleansing fire to our tests. 🔥
What does this do / why do we need it?
The current tests for the importers (like godep or glide) have lots of similarities. Using table based tests would reduce code and make it easier to add more test cases.
What should your reviewer look out for in this PR?
I'm adding
gps.ProjectRootPtr()
as well asgps.RevisionPtr()
functions. They are helpers to make it easy to create pointers toProjectRoot
/Revision
easily. Since they are only used for tests at the moment, it may be better that I just create them in my_test.go
file for now. Suggestions welcome.Do you need help or clarification on anything?
I'm not entirely satisfied with the amount of lines that ended up in the for loop for the test cases. Ideally I'd use something like
testify/assert
to reduce the line count, increase readability and make test failure output more descriptive. But I'm not sure that importing dependencies into the project is desirable. Please advice.To do
godep
glide
Possibly move helpers to their own file. CurrentlyintPtr()
lives ingodep_importer_test.go
, which is not desirableWhich issue(s) does this PR fix?
fixes #824