Skip to content

Commit

Permalink
Updated tests to use GravitinoCommandLine instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
VigneshSK17 committed Jan 11, 2025
1 parent 0fddfa5 commit ce4dcb5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,11 @@ private void handlePropertiesCommand() {

/** Handles the "UPDATE" command. */
private void handleUpdateCommand() {
if (line.hasOption(GravitinoOptions.ENABLE) && line.hasOption(GravitinoOptions.DISABLE)) {
System.err.println(ErrorMessages.INVALID_ENABLE_DISABLE);
Main.exit(-1);
}
if (line.hasOption(GravitinoOptions.ENABLE)) {
boolean enableMetalake = line.hasOption(GravitinoOptions.ALL);
boolean disable = line.hasOption(GravitinoOptions.DISABLE);
gravitinoCommandLine
.newCatalogEnable(url, ignore, metalake, catalog, enableMetalake)
.newCatalogEnable(url, ignore, metalake, catalog, disable, enableMetalake)
.validate()
.handle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,10 @@ private void handleMetalakeCommand() {
break;

case CommandActions.UPDATE:
if (line.hasOption(GravitinoOptions.ENABLE) && line.hasOption(GravitinoOptions.DISABLE)) {
System.err.println(ErrorMessages.INVALID_ENABLE_DISABLE);
Main.exit(-1);
}
if (line.hasOption(GravitinoOptions.ENABLE)) {
boolean enableAllCatalogs = line.hasOption(GravitinoOptions.ALL);
newMetalakeEnable(url, ignore, metalake, enableAllCatalogs).validate().handle();
boolean disable = line.hasOption(GravitinoOptions.DISABLE);
newMetalakeEnable(url, ignore, metalake, disable, enableAllCatalogs).validate().handle();
}
if (line.hasOption(GravitinoOptions.DISABLE)) {
newMetalakeDisable(url, ignore, metalake).validate().handle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,12 +513,30 @@ void testDisableCatalogCommand() {
@SuppressWarnings("DefaultCharset")
void testCatalogWithDisableAndEnableOptions() {
Main.useExit = false;
CatalogEnable mockCatalogEnable =
when(mockCommandLine.hasOption(GravitinoOptions.METALAKE)).thenReturn(true);
when(mockCommandLine.getOptionValue(GravitinoOptions.METALAKE)).thenReturn("metalake_demo");
when(mockCommandLine.hasOption(GravitinoOptions.NAME)).thenReturn(true);
when(mockCommandLine.getOptionValue(GravitinoOptions.NAME)).thenReturn("catalog");
when(mockCommandLine.hasOption(GravitinoOptions.DISABLE)).thenReturn(true);
when(mockCommandLine.hasOption(GravitinoOptions.ENABLE)).thenReturn(true);

GravitinoCommandLine commandLine =
spy(
new CatalogEnable(
GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "catalog", true, false));
new GravitinoCommandLine(
mockCommandLine, mockOptions, CommandEntities.CATALOG, CommandActions.UPDATE));

assertThrows(RuntimeException.class, mockCatalogEnable::validate);
assertThrows(
RuntimeException.class,
() ->
commandLine
.newCatalogEnable(
GravitinoCommandLine.DEFAULT_URL,
false,
"metalake_demo",
"catalog",
true,
false)
.validate());
String errOutput = new String(errContent.toByteArray(), StandardCharsets.UTF_8).trim();
Assertions.assertEquals(ErrorMessages.INVALID_ENABLE_DISABLE, errOutput);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,23 @@ void testDisableMetalakeCommand() {
@SuppressWarnings("DefaultCharset")
void testMetalakeWithDisableAndEnableOptions() {
Main.useExit = false;
MetalakeEnable mockMetalakeEnable =
when(mockCommandLine.hasOption(GravitinoOptions.METALAKE)).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 MetalakeEnable(
GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", true, false));
new GravitinoCommandLine(
mockCommandLine, mockOptions, CommandEntities.METALAKE, CommandActions.UPDATE));

assertThrows(RuntimeException.class, mockMetalakeEnable::validate);
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);
}
Expand Down

0 comments on commit ce4dcb5

Please sign in to comment.