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

refactor(core-tests): Convert DescriptionAuthorizerService tests to java #6140

Merged
merged 2 commits into from
Jan 25, 2024

Conversation

dzhengg
Copy link
Contributor

@dzhengg dzhengg commented Jan 25, 2024

We want to refactor from groovy to java tests as much as possible. This refactors the groovy tests in DescriptionAuthorizerServiceSpec to a DescriptionAuthorizerServiceTest class in java.

Adds some test coverage on the DescriptionAuthorizerServiceTest, particularly with the metrics that it is testing, as well as adding a test for the happy path.

Also refactors some of the mocking in the DescriptionAuthorizerServiceTest. It has a AccountDefinitionSecretManager as a dependency, and rather than mocking that class, the test was mocking the dependencies of that class. This led to an unnecessary level of testing/mocking for a unit test, because the only way to setup the right mocking values was to mock the dependency of the dependency. Rather than do this, it's better to just setup the secretManager as a mock itself.

Part of this refactor is to add some missing tests for the DefaultAccountSecurityPolicy class. These tests never existed in the first place, and because DefaultAccountSecurityPolicy is down the dependency chain from AccountDefinitionSecretManager (which wasn't properly mocked in DescriptionAuthorizerServiceTest), the code in this class was being tested in the DescriptionAuthorizerServiceTest class. To simplify the mocking and testing code, it's better to have test this code in a self contained testing class.

Richard Timpson added 2 commits January 24, 2024 16:18
We want to refactor from groovy to java tests as much as possible. This refactors the groovy tests in DescriptionAuthorizerServiceSpec to a DescriptionAuthorizerServiceTest class in java.
Adds some test coverage on the DescriptionAuthorizerServiceTest, particularly with the metrics that it is testing, as well as adding a test for the happy path.

Also refactors some of the mocking in the DescriptionAuthorizerServiceTest. It has a AccountDefinitionSecretManager as a dependency, and rather than mocking that class, the test was mocking the dependencies of that class. This led to an unnecessary level of testing/mocking for a unit test, because the only way to setup the right mocking values was to mock the dependency of the dependency. Rather than do this, it's better to just setup the secretManager as a mock itself.

Part of this refactor is to add some missing tests for the DefaultAccountSecurityPolicy class. These tests never existed in the first place, and because DefaultAccountSecurityPolicy is down the dependency chain from AccountDefinitionSecretManager (which wasn't properly mocked in DescriptionAuthorizerServiceTest), the code in this class was being tested in the DescriptionAuthorizerServiceTest class. To simplify the mocking and testing code, it's better to have test this code in a self contained testing class.
@dzhengg dzhengg requested a review from cfieber as a code owner January 25, 2024 00:24
@dbyron-sf dbyron-sf added the ready to merge Approved and ready for a merge label Jan 25, 2024
@mergify mergify bot added the auto merged Merged automatically by a bot label Jan 25, 2024
@mergify mergify bot merged commit 069140b into spinnaker:master Jan 25, 2024
16 checks passed
@dzhengg dzhengg deleted the refactor-tests branch January 25, 2024 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto merged Merged automatically by a bot ready to merge Approved and ready for a merge target-release/1.34
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants