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

Tests for the brokers package #9

Merged
merged 10 commits into from
Aug 15, 2023
Merged

Tests for the brokers package #9

merged 10 commits into from
Aug 15, 2023

Conversation

denisonbarbosa
Copy link
Member

This adds mock utilities in testutils and adds tests for the brokers package, for both manager.go and broker.go

UDENG-1065

@denisonbarbosa denisonbarbosa requested a review from a team as a code owner August 4, 2023 15:27
@denisonbarbosa denisonbarbosa requested review from a team and removed request for a team August 7, 2023 11:43
Copy link
Contributor

@GabrielNagy GabrielNagy left a comment

Choose a reason for hiding this comment

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

Great work, I'm not very familiar with the project so my comments are a bit on the surface level. My only major point is related to the level of mocking in the tests which feels a bit redundant to me but maybe I'm not getting the bigger picture.

.gitignore Show resolved Hide resolved
internal/testutils/dbus.go Show resolved Hide resolved
internal/testutils/dbus.go Outdated Show resolved Hide resolved
internal/brokers/broker_test.go Outdated Show resolved Hide resolved
internal/testutils/broker.go Outdated Show resolved Hide resolved
internal/testutils/broker.go Outdated Show resolved Hide resolved
internal/testutils/broker.go Outdated Show resolved Hide resolved
internal/testutils/broker.go Outdated Show resolved Hide resolved
internal/testutils/broker.go Outdated Show resolved Hide resolved
internal/testutils/broker.go Outdated Show resolved Hide resolved
Copy link
Member

@didrocks didrocks left a comment

Choose a reason for hiding this comment

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

I feel this PR really needs work and care. See the various comments on how to simpify the code by itself (I think we shouldn’t split objects to split them)

Basically, it seems you didn’t use coverage to drive the tests to do. For instance, the part for validating fields and types are clearly not covered, while the mock in some shape should deliver those invalid layouts (to ensure we do our check and return an error early).

For instance, invalid fields, invalid types returned in fields, qrcode type are not covered. Some other functions like setting a default broker is not covered either. To me, and now that we have worked quite on a bunch of PRs, I think that using coverage for tests and checking what is covered/not covered is a given in our practices.

In addition to this remarks, I think that we should have multiple mock brokers attached and set for users. That way, we ensure that the requests are directed to the correct brokers (this needs chaining multiple calls though).

Also, the API protection is in 2 sense: Ensuring that we are not calling IsAuthorized twice without cancelling and triggering an error as a test case (I’m unsure the code itself protects against that btw).

So yeah, I really feel you should take the time to rethink the testing strategy and have something which covers the whole brokers package, and think about test cases for validation, multiplexing requests (multiple brokers) and all those use cases.

You should remove the example brokers too (only exposing them via an env variable for our manual testing purposes for now, no need to cover their creation).

I did stop the review after a while, because I feel this is going to change a lot and I feel this was not necessary anymore with the amount of remarks I had on missing assertions and so on). Tell me if anything is not clear

.gitignore Show resolved Hide resolved
internal/testutils/broker.go Outdated Show resolved Hide resolved
internal/testutils/broker.go Outdated Show resolved Hide resolved
internal/testutils/broker.go Show resolved Hide resolved
internal/testutils/broker.go Outdated Show resolved Hide resolved
@@ -0,0 +1,4 @@
- local
- Broker
- broker foo
Copy link
Member

Choose a reason for hiding this comment

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

I think broker foo and bar are only temporary. I would have multiple dbus broker instead with their respective configuration too.

Copy link
Member Author

Choose a reason for hiding this comment

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

You guys are still using the local brokers to run some local tests, so that's why I kept them. I can comment the code with a //TODO so that it's still there for manual tests and it does not show on the tests if that's ok.

Copy link
Member

Choose a reason for hiding this comment

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

See my comment about global env variables

internal/brokers/broker_test.go Outdated Show resolved Hide resolved
internal/brokers/broker_test.go Outdated Show resolved Hide resolved
internal/brokers/broker_test.go Outdated Show resolved Hide resolved
internal/brokers/broker_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@GabrielNagy GabrielNagy left a comment

Choose a reason for hiding this comment

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

LGTM, nice improvement! My comments are all minor.

internal/brokers/broker_test.go Outdated Show resolved Hide resolved
internal/brokers/broker_test.go Outdated Show resolved Hide resolved
internal/brokers/broker_test.go Outdated Show resolved Hide resolved
internal/brokers/broker_test.go Outdated Show resolved Hide resolved
internal/testutils/dbus.go Outdated Show resolved Hide resolved
internal/brokers/manager_test.go Outdated Show resolved Hide resolved
internal/brokers/manager_test.go Outdated Show resolved Hide resolved
internal/testutils/broker.go Outdated Show resolved Hide resolved
internal/testutils/dbus.go Outdated Show resolved Hide resolved
@denisonbarbosa
Copy link
Member Author

denisonbarbosa commented Aug 10, 2023

In addition to these remarks, I think that we should have multiple mock brokers attached and set for users. That way, we ensure that the requests are directed to the correct brokers (this needs chaining multiple calls though).

@didrocks I can't see where we can fit this outside of an integration tests scope. Maybe we can pair real quick on it for some discussion?
The other remarks were attended to.

internal/brokers/broker.go Outdated Show resolved Hide resolved
internal/brokers/broker_test.go Outdated Show resolved Hide resolved
internal/brokers/broker_test.go Outdated Show resolved Hide resolved
internal/brokers/broker_test.go Outdated Show resolved Hide resolved
internal/brokers/broker_test.go Show resolved Hide resolved
internal/brokers/manager_test.go Outdated Show resolved Hide resolved
internal/brokers/manager_test.go Outdated Show resolved Hide resolved
internal/brokers/manager_test.go Show resolved Hide resolved
internal/testutils/broker.go Outdated Show resolved Hide resolved
@@ -0,0 +1,4 @@
- local
- Broker
- broker foo
Copy link
Member

Choose a reason for hiding this comment

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

See my comment about global env variables

Copy link
Member

@didrocks didrocks left a comment

Choose a reason for hiding this comment

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

as seen together, some additional comments, I should have resolved every addressed points. We just skimmed together over the golden files but they should be checked carefully by the next reviewer :)

internal/brokers/manager_test.go Show resolved Hide resolved
internal/brokers/manager.go Show resolved Hide resolved
internal/brokers/manager_test.go Show resolved Hide resolved
internal/brokers/broker_test.go Show resolved Hide resolved
internal/brokers/export_test.go Outdated Show resolved Hide resolved
internal/brokers/manager_test.go Show resolved Hide resolved
internal/brokers/manager.go Outdated Show resolved Hide resolved
internal/brokers/manager.go Outdated Show resolved Hide resolved
Copy link
Contributor

@GabrielNagy GabrielNagy left a comment

Choose a reason for hiding this comment

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

Everything looks correct to me, went thru all test cases & golden files and couldn't find any complaints. Great work!

@denisonbarbosa denisonbarbosa merged commit 6a86c8c into main Aug 15, 2023
3 checks passed
@denisonbarbosa denisonbarbosa deleted the broker-tests branch August 15, 2023 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants