Skip to content

Commit

Permalink
[#6097] improve(CLI): Add --quiet option to the Gravition CLI
Browse files Browse the repository at this point in the history
fix some issues.
  • Loading branch information
Abyss-lord committed Jan 13, 2025
1 parent 2854dc8 commit 4eba703
Show file tree
Hide file tree
Showing 14 changed files with 480 additions and 729 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public class CommandEntities {
VALID_ENTITIES.add(TOPIC);
VALID_ENTITIES.add(FILESET);
VALID_ENTITIES.add(ROLE);
VALID_ENTITIES.add(MODEL);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
Expand Down Expand Up @@ -164,14 +163,14 @@ void testCreateCatalogCommand() {
doReturn(mockCreate)
.when(commandLine)
.newCreateCatalog(
eq(GravitinoCommandLine.DEFAULT_URL),
eq(false),
eq(false),
eq("metalake_demo"),
eq("catalog"),
eq("postgres"),
eq("comment"),
eq(map));
GravitinoCommandLine.DEFAULT_URL,
false,
false,
"metalake_demo",
"catalog",
"postgres",
"comment",
map);
doReturn(mockCreate).when(mockCreate).validate();
commandLine.handleCommandLine();
verify(mockCreate).handle();
Expand Down Expand Up @@ -212,20 +211,14 @@ void testDeleteCatalogCommand() {
doReturn(mockDelete)
.when(commandLine)
.newDeleteCatalog(
eq(GravitinoCommandLine.DEFAULT_URL),
eq(false),
eq(false),
eq(false),
eq("metalake_demo"),
eq("catalog"));
GravitinoCommandLine.DEFAULT_URL, false, false, false, "metalake_demo", "catalog");
doReturn(mockDelete).when(mockDelete).validate();
commandLine.handleCommandLine();
verify(mockDelete).handle();
}

@Test
void testDeleteCatalogForceCommand() {
Main.useExit = false;
DeleteCatalog mockDelete = mock(DeleteCatalog.class);
when(mockCommandLine.hasOption(GravitinoOptions.METALAKE)).thenReturn(true);
when(mockCommandLine.getOptionValue(GravitinoOptions.METALAKE)).thenReturn("metalake_demo");
Expand All @@ -240,12 +233,7 @@ void testDeleteCatalogForceCommand() {
doReturn(mockDelete)
.when(commandLine)
.newDeleteCatalog(
eq(GravitinoCommandLine.DEFAULT_URL),
eq(false),
eq(false),
eq(true),
eq("metalake_demo"),
eq("catalog"));
GravitinoCommandLine.DEFAULT_URL, false, false, true, "metalake_demo", "catalog");
doReturn(mockDelete).when(mockDelete).validate();
commandLine.handleCommandLine();
verify(mockDelete).handle();
Expand All @@ -270,13 +258,13 @@ void testSetCatalogPropertyCommand() {
doReturn(mockSetProperty)
.when(commandLine)
.newSetCatalogProperty(
eq(GravitinoCommandLine.DEFAULT_URL),
eq(false),
eq(false),
eq("metalake_demo"),
eq("catalog"),
eq("property"),
eq("value"));
GravitinoCommandLine.DEFAULT_URL,
false,
false,
"metalake_demo",
"catalog",
"property",
"value");
doReturn(mockSetProperty).when(mockSetProperty).validate();
commandLine.handleCommandLine();
verify(mockSetProperty).handle();
Expand Down Expand Up @@ -356,12 +344,7 @@ void testRemoveCatalogPropertyCommand() {
doReturn(mockRemoveProperty)
.when(commandLine)
.newRemoveCatalogProperty(
eq(GravitinoCommandLine.DEFAULT_URL),
eq(false),
eq(false),
eq("metalake_demo"),
eq("catalog"),
eq("property"));
GravitinoCommandLine.DEFAULT_URL, false, false, "metalake_demo", "catalog", "property");
doReturn(mockRemoveProperty).when(mockRemoveProperty).validate();
commandLine.handleCommandLine();
verify(mockRemoveProperty).handle();
Expand Down Expand Up @@ -417,12 +400,12 @@ void testUpdateCatalogCommentCommand() {
doReturn(mockUpdateComment)
.when(commandLine)
.newUpdateCatalogComment(
eq(GravitinoCommandLine.DEFAULT_URL),
eq(false),
eq(false),
eq("metalake_demo"),
eq("catalog"),
eq("new comment"));
GravitinoCommandLine.DEFAULT_URL,
false,
false,
"metalake_demo",
"catalog",
"new comment");
doReturn(mockUpdateComment).when(mockUpdateComment).validate();
commandLine.handleCommandLine();
verify(mockUpdateComment).handle();
Expand All @@ -446,12 +429,7 @@ void testUpdateCatalogNameCommand() {
doReturn(mockUpdateName)
.when(commandLine)
.newUpdateCatalogName(
eq(GravitinoCommandLine.DEFAULT_URL),
eq(false),
eq(false),
eq("metalake_demo"),
eq("catalog"),
eq("new_name"));
GravitinoCommandLine.DEFAULT_URL, false, false, "metalake_demo", "catalog", "new_name");
doReturn(mockUpdateName).when(mockUpdateName).validate();
commandLine.handleCommandLine();
verify(mockUpdateName).handle();
Expand Down Expand Up @@ -503,12 +481,7 @@ void testEnableCatalogCommand() {
doReturn(mockEnable)
.when(commandLine)
.newCatalogEnable(
eq(GravitinoCommandLine.DEFAULT_URL),
eq(false),
eq(false),
eq("metalake_demo"),
eq("catalog"),
eq(false));
GravitinoCommandLine.DEFAULT_URL, false, false, "metalake_demo", "catalog", false);
doReturn(mockEnable).when(mockEnable).validate();
commandLine.handleCommandLine();
verify(mockEnable).handle();
Expand All @@ -531,12 +504,7 @@ void testEnableCatalogCommandWithRecursive() {
doReturn(mockEnable)
.when(commandLine)
.newCatalogEnable(
eq(GravitinoCommandLine.DEFAULT_URL),
eq(false),
eq(false),
eq("metalake_demo"),
eq("catalog"),
eq(true));
GravitinoCommandLine.DEFAULT_URL, false, false, "metalake_demo", "catalog", true);
doReturn(mockEnable).when(mockEnable).validate();
commandLine.handleCommandLine();
verify(mockEnable).handle();
Expand Down Expand Up @@ -583,12 +551,7 @@ void testCatalogWithDisableAndEnableOptions() {
assertThrows(RuntimeException.class, commandLine::handleCommandLine);
verify(commandLine, never())
.newCatalogEnable(
eq(GravitinoCommandLine.DEFAULT_URL),
eq(false),
eq(false),
eq("metalake_demo"),
eq("catalog"),
eq(false));
GravitinoCommandLine.DEFAULT_URL, false, false, "metalake_demo", "catalog", false);
verify(commandLine, never())
.newCatalogDisable(
GravitinoCommandLine.DEFAULT_URL, false, false, "melake_demo", "catalog");
Expand Down
Loading

0 comments on commit 4eba703

Please sign in to comment.