-
Notifications
You must be signed in to change notification settings - Fork 209
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
Improve visualize tests #404
Conversation
visualize_test.go
Outdated
@@ -449,6 +449,8 @@ func assertCtorEqual(t *testing.T, expected *dot.Ctor, ctor *dot.Ctor) { | |||
} | |||
|
|||
func assertCtorsEqual(t *testing.T, expected []*dot.Ctor, ctors []*dot.Ctor) { | |||
assert.Len(t, ctors, len(expected)) |
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.
Thanks for catching this!
In fact, one step better would probably be making this a require.Len
so we stop the test immediately and not panic in the following loop if len(ctors) > len(expected)
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.
PR uber-go#404 attempted to improve the tests in `visualize_test.go` by requiring length equality on the expected/actual ctors. During CI, this actually uncovered a test failure: ``` --- FAIL: TestDotGraph (0.02s) --- FAIL: TestDotGraph/create_graph_with_one_constructor_and_as_interface_option (0.00s) visualize_test.go:453: Error Trace: visualize_test.go:453 visualize_test.go:117 Error: "[]" should have 1 item(s), but has 0 Test: TestDotGraph/create_graph_with_one_constructor_and_as_interface_option ``` This is because, in this specific test case, the provide was never actually provided because of an error during provide (`t5 did not implement io.Reader`). This commit: * Changes all of the provides that are expected to pass to `RequireProvide` which will fail if the provide fails. * Modifies `t5` to implement `io.Reader`. * Change the test case to expect the provider to only provide the interface in the `fx.As` (`fx.As` does not also provide the actual type) * Add the len check from uber-go#404.
Hey @greeflas, CI uncovered an error running this PR. This is actually due to some incorrect testing logic written by us. Since I don't have permission to update this PR, I have created a separate PR that supersedes this one (it includes your change and fixes the broken test): #405. Thanks for uncovering this issue! |
PR #404 attempted to improve the tests in `visualize_test.go` by requiring length equality on the expected/actual ctors. During CI, this actually uncovered a test failure: ``` --- FAIL: TestDotGraph (0.02s) --- FAIL: TestDotGraph/create_graph_with_one_constructor_and_as_interface_option (0.00s) visualize_test.go:453: Error Trace: visualize_test.go:453 visualize_test.go:117 Error: "[]" should have 1 item(s), but has 0 Test: TestDotGraph/create_graph_with_one_constructor_and_as_interface_option ``` This is because, in this specific test case, the provide was never actually provided because of an error during provide (`t5 did not implement io.Reader`). This commit: * Changes all of the provides that are expected to pass to `RequireProvide` which will fail if the provide fails. * Modifies `t5` to implement `io.Reader`. * Change the test case to expect the provider to only provide the interface in the `fx.As` (`fx.As` does not also provide the actual type) * Add the len check from #404.
Ok, welcome! |
Hello!
While working on #403 I've noted that unit tests for
Visualize()
worked not correctly in some cases.If
CreateGraph()
method returns lessCtor
elements than expected (and vice versa) - tests will pass.So I fixed assert function and found new bug shown by
create graph with one constructor and as interface option
scenario.