Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

greeflas
Copy link
Contributor

Hello!

While working on #403 I've noted that unit tests for Visualize() worked not correctly in some cases.
If CreateGraph() method returns less Ctor 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.

@@ -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))
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@greeflas greeflas requested a review from JacobOaks January 25, 2024 00:07
JacobOaks added a commit to JacobOaks/dig that referenced this pull request Jan 26, 2024
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.
@JacobOaks JacobOaks mentioned this pull request Jan 26, 2024
@JacobOaks
Copy link
Contributor

JacobOaks commented Jan 26, 2024

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!

JacobOaks added a commit that referenced this pull request Jan 26, 2024
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.
@greeflas
Copy link
Contributor Author

Ok, welcome!
I'll close this PR.

@greeflas greeflas closed this Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants