Skip to content

Commit

Permalink
fix merge issue and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmclean committed Oct 17, 2024
1 parent a7c2a88 commit 055678b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 92 deletions.
5 changes: 2 additions & 3 deletions clients/cli/src/main/java/org/apache/gravitino/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void main(String[] args) {
return;
}
String command = resolveCommand(line);
String entity = resolveEntity(line, command != null);
String entity = resolveEntity(line);
GravitinoCommandLine commandLine = new GravitinoCommandLine(line, options, entity, command);
commandLine.handleCommandLine();
} catch (ParseException exp) {
Expand Down Expand Up @@ -76,13 +76,12 @@ protected static String resolveCommand(CommandLine line) {
* Determines the entity to act upon based on the command line input.
*
* @param line Parsed command line object.
* @param command true if command is an argument
* @return The entity, e.g. metakalake, catalog, schema, table, etc.
*/
protected static String resolveEntity(CommandLine line) {
/* As the bare first argument. */
String[] args = line.getArgs();

if (args.length > 0) {
String entity = args[0];
if (CommandEntities.isValidEntity(entity)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,48 +66,7 @@ public void entityNotFound() throws Exception {
}

@Test
<<<<<<< HEAD
public void justName() throws Exception, MissingArgumentException {
String[] args = {"--name"};

assertThrows(MissingArgumentException.class, () -> new DefaultParser().parse(options, args));
}

@Test
public void catalogFromCommandLineOption() throws Exception {
String[] args = {"--catalog", "catalogA"};
CommandLine commandLine = new DefaultParser().parse(options, args);
FullName fullName = new FullName(commandLine);

String catalogName = fullName.getCatalogName();
assertEquals("catalogA", catalogName);
}

@Test
public void schemaFromCommandLineOption() throws Exception {
String[] args = {"--schema", "schemaA"};
CommandLine commandLine = new DefaultParser().parse(options, args);
FullName fullName = new FullName(commandLine);

String schemaName = fullName.getSchemaName();
assertEquals("schemaA", schemaName);
}

@Test
public void tableFromCommandLineOption() throws Exception {
String[] args = {"--table", "tableA"};
CommandLine commandLine = new DefaultParser().parse(options, args);
FullName fullName = new FullName(commandLine);

String tableName = fullName.getTableName();
assertEquals("tableA", tableName);
}

@Test
public void malformedMissingEntityName() throws Exception {
=======
public void malformedName() throws Exception {
>>>>>>> CLI
String[] args = {"--name", "metalake.catalog"};
CommandLine commandLine = new DefaultParser().parse(options, args);
FullName fullName = new FullName(commandLine);
Expand Down
53 changes: 5 additions & 48 deletions clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,20 @@ public void withTwoArgsOnly() throws ParseException {

String command = Main.resolveCommand(line);
assertEquals(CommandActions.DETAILS, command);
String entity = Main.resolveEntity(line, true);
String entity = Main.resolveEntity(line);
assertEquals(CommandEntities.METALAKE, entity);
}

@Test
public void defaultToDetails() throws ParseException {
Options options = new GravitinoOptions().options();
CommandLineParser parser = new DefaultParser();
String[] args = {"--metalake", "metalake_demo"};
String[] args = {"metalake", "--name", "metalake_demo"};
CommandLine line = parser.parse(options, args);

String command = Main.resolveCommand(line);
assertEquals(CommandActions.DETAILS, command);
String entity = Main.resolveEntity(line, false);
String entity = Main.resolveEntity(line);
assertEquals(CommandEntities.METALAKE, entity);
}

Expand Down Expand Up @@ -104,59 +104,16 @@ public void parseError() throws UnsupportedEncodingException {
assertTrue(outContent.toString().contains("usage:")); // Expect help output
}

@Test
public void catalogWithTwoArgs() throws ParseException {
Options options = new GravitinoOptions().options();
CommandLineParser parser = new DefaultParser();
String[] args = {"catalog", "details", "--name", "metalake_demo.catalog_postgres"};
CommandLine line = parser.parse(options, args);

String command = Main.resolveCommand(line);
assertEquals(CommandActions.DETAILS, command);
String entity = Main.resolveEntity(line, true);
assertEquals(CommandEntities.CATALOG, entity);
}

@Test
public void catalogWithOneArg() throws ParseException {
Options options = new GravitinoOptions().options();
CommandLineParser parser = new DefaultParser();
String[] args = {"catalog", "--command", "details", "--name", "metalake_demo.catalog_postgres"};
CommandLine line = parser.parse(options, args);

String command = Main.resolveCommand(line);
assertEquals(CommandActions.DETAILS, command);
String entity = Main.resolveEntity(line, true);
assertEquals(CommandEntities.CATALOG, entity);
}

@Test
public void catalogWithEntity() throws ParseException {
Options options = new GravitinoOptions().options();
CommandLineParser parser = new DefaultParser();
String[] args = {
"--entity", "catalog", "--command", "details", "--name", "metalake_demo.catalog_postgres"
};
CommandLine line = parser.parse(options, args);

String command = Main.resolveCommand(line);
assertEquals(CommandActions.DETAILS, command);
String entity = Main.resolveEntity(line, false);
assertEquals(CommandEntities.CATALOG, entity);
}

@Test
public void catalogWithNoName() throws ParseException {
Options options = new GravitinoOptions().options();
CommandLineParser parser = new DefaultParser();
String[] args = {
"catalog", "details", "--metalake", "metalake_demo", "--catalog", "catalog_postgres"
};
String[] args = {"catalog", "--details", "--name", "metalake_demo.catalog_postgres"};
CommandLine line = parser.parse(options, args);

String command = Main.resolveCommand(line);
assertEquals(CommandActions.DETAILS, command);
String entity = Main.resolveEntity(line, true);
String entity = Main.resolveEntity(line);
assertEquals(CommandEntities.CATALOG, entity);
}
}

0 comments on commit 055678b

Please sign in to comment.