-
Notifications
You must be signed in to change notification settings - Fork 391
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
[#6136] refactor: move check for enable and disable within validate (CLI) #6163
Open
VigneshSK17
wants to merge
3
commits into
apache:main
Choose a base branch
from
VigneshSK17:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,10 +21,8 @@ | |
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertThrows; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
@@ -46,8 +44,8 @@ | |
import org.apache.gravitino.cli.commands.SetMetalakeProperty; | ||
import org.apache.gravitino.cli.commands.UpdateMetalakeComment; | ||
import org.apache.gravitino.cli.commands.UpdateMetalakeName; | ||
import org.junit.Assert; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
|
@@ -386,7 +384,7 @@ void testEnableMetalakeCommand() { | |
mockCommandLine, mockOptions, CommandEntities.METALAKE, CommandActions.UPDATE)); | ||
doReturn(mockEnable) | ||
.when(commandLine) | ||
.newMetalakeEnable(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", false); | ||
.newMetalakeEnable(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", false, false); | ||
doReturn(mockEnable).when(mockEnable).validate(); | ||
commandLine.handleCommandLine(); | ||
verify(mockEnable).handle(); | ||
|
@@ -405,7 +403,7 @@ void testEnableMetalakeCommandWithRecursive() { | |
mockCommandLine, mockOptions, CommandEntities.METALAKE, CommandActions.UPDATE)); | ||
doReturn(mockEnable) | ||
.when(commandLine) | ||
.newMetalakeEnable(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", true); | ||
.newMetalakeEnable(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", false, true); | ||
doReturn(mockEnable).when(mockEnable).validate(); | ||
commandLine.handleCommandLine(); | ||
verify(mockEnable).handle(); | ||
|
@@ -435,20 +433,23 @@ void testDisableMetalakeCommand() { | |
void testMetalakeWithDisableAndEnableOptions() { | ||
Main.useExit = false; | ||
when(mockCommandLine.hasOption(GravitinoOptions.METALAKE)).thenReturn(true); | ||
when(mockCommandLine.getOptionValue(CommandEntities.METALAKE)).thenReturn("metalake_demo"); | ||
when(mockCommandLine.hasOption(GravitinoOptions.ENABLE)).thenReturn(true); | ||
when(mockCommandLine.getOptionValue(GravitinoOptions.METALAKE)).thenReturn("metalake_demo"); | ||
when(mockCommandLine.hasOption(GravitinoOptions.DISABLE)).thenReturn(true); | ||
when(mockCommandLine.hasOption(GravitinoOptions.ENABLE)).thenReturn(true); | ||
|
||
GravitinoCommandLine commandLine = | ||
spy( | ||
new GravitinoCommandLine( | ||
mockCommandLine, mockOptions, CommandEntities.METALAKE, CommandActions.UPDATE)); | ||
|
||
Assert.assertThrows(RuntimeException.class, commandLine::handleCommandLine); | ||
verify(commandLine, never()) | ||
.newMetalakeEnable(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", false); | ||
verify(commandLine, never()) | ||
.newMetalakeEnable(GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", false); | ||
assertTrue(errContent.toString().contains(ErrorMessages.INVALID_ENABLE_DISABLE)); | ||
assertThrows( | ||
RuntimeException.class, | ||
() -> | ||
commandLine | ||
.newMetalakeEnable( | ||
GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", true, false) | ||
.validate()); | ||
String errOutput = new String(errContent.toByteArray(), StandardCharsets.UTF_8).trim(); | ||
Assertions.assertEquals(ErrorMessages.INVALID_ENABLE_DISABLE, errOutput); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, I'm not sure these changes are required. |
||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 not sure why you have changed this test in this way. Can you explain the changes?
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.
My understanding is that I should detect if there's a RuntimeException when trying to enable and disable a catalog at the same time and then check if the error message is INVALID_ENABLE_DISABLE.
Is there an alternative to simplify this test or is am I misunderstanding the intent of these tests?
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.
So why change existing working tests that are needed? Did you mean to add a new test instead?
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.
Oh I see what you mean.
The reason why is because to check if both flags are true, I pass the disable flag's result into EnableCatalogCommand as a required parameter.
Is this the proper standard or not? Apologies for dragging this on for so long.