Skip to content

Commit 9cf4121

Browse files
authored
[ZEPPELIN-6254] Add test case in file interpreter
### What is this PR for? Added test cases to the file interpreter to increase test coverage. ### What type of PR is it? Improvement ### Todos * command is null * use unknown command * no such directory/file ### What is the Jira issue? https://issues.apache.org/jira/browse/ZEPPELIN-6254 ### How should this be tested? Run test in file interpreter ### Screenshots (if appropriate) ### Questions: * Does the license files need to update? No * Is there breaking changes for older versions? No * Does this needs documentation? No Closes #4994 from proceane/feature/ZEPPELIN-6254. Signed-off-by: Philipp Dallig <philipp.dallig@gmail.com>
1 parent 9a8ea36 commit 9cf4121

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

file/src/test/java/org/apache/zeppelin/file/HDFSFileInterpreterTest.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,56 @@ void test() {
133133

134134
t.close();
135135
}
136+
137+
@Test
138+
void testCommandIsNull() {
139+
HDFSFileInterpreter t = new MockHDFSFileInterpreter(new Properties());
140+
t.open();
141+
142+
InterpreterResult result = t.interpret(null, null);
143+
assertEquals(InterpreterResult.Type.TEXT, result.message().get(0).getType());
144+
assertEquals("No command", result.message().get(0).getData());
145+
146+
t.close();
147+
}
148+
149+
@Test
150+
void testUnknownCommand() {
151+
HDFSFileInterpreter t = new MockHDFSFileInterpreter(new Properties());
152+
t.open();
153+
154+
InterpreterResult result = t.interpret("unknown", null);
155+
assertEquals(InterpreterResult.Type.TEXT, result.message().get(0).getType());
156+
assertEquals("Unknown command", result.message().get(0).getData());
157+
158+
t.close();
159+
}
160+
161+
@Test
162+
void testNoSuchDirectory() {
163+
HDFSFileInterpreter t = new MockHDFSFileInterpreter(new Properties());
164+
t.open();
165+
166+
InterpreterResult result = t.interpret("cd /tmp/ida8c06540_date040315", null);
167+
assertEquals(InterpreterResult.Type.TEXT, result.message().get(0).getType());
168+
assertEquals("/tmp/ida8c06540_date040315: No such directory",
169+
result.message().get(0).getData());
170+
171+
t.close();
172+
}
173+
174+
@Test
175+
void testNoSuchFile() {
176+
HDFSFileInterpreter t = new MockHDFSFileInterpreter(new Properties());
177+
t.open();
178+
179+
InterpreterResult result = t.interpret("ls -l /does/not/exist", null);
180+
assertEquals(InterpreterResult.Type.TEXT, result.message().get(0).getType());
181+
assertEquals("No such File or directory", result.message().get(0).getData());
182+
183+
t.close();
184+
}
185+
136186
}
137187

138188
/**

0 commit comments

Comments
 (0)