@@ -98,15 +98,28 @@ void shouldReturnInvalidCurrentContext() {
9898
9999 @ Test
100100 void shouldNotDeleteByNameWhenNotAuthenticated () {
101+ CommandLine cmd = new CommandLine (delete );
102+ StringWriter sw = new StringWriter ();
103+ cmd .setErr (new PrintWriter (sw ));
104+
101105 when (configService .isCurrentContextValid ()).thenReturn (true );
102106 when (loginService .doAuthenticate (any (), anyBoolean ())).thenReturn (false );
103107
108+ int code = cmd .execute ("topic" , "myTopic" );
109+ assertEquals (1 , code );
110+ }
111+
112+ @ Test
113+ void shouldNotDeleteWhenFileNotFound () {
104114 CommandLine cmd = new CommandLine (delete );
105115 StringWriter sw = new StringWriter ();
106116 cmd .setErr (new PrintWriter (sw ));
107117
108- int code = cmd .execute ("topic" , "myTopic" );
109- assertEquals (1 , code );
118+ when (configService .isCurrentContextValid ()).thenReturn (true );
119+ when (loginService .doAuthenticate (any (), anyBoolean ())).thenReturn (true );
120+
121+ int code = cmd .execute ("-f" , "src/test/resources/topics/unknown.yml" );
122+ assertEquals (2 , code );
110123 }
111124
112125 @ Test
@@ -120,9 +133,9 @@ void shouldNotDeleteByFileWhenYmlFileNotFound() {
120133 StringWriter sw = new StringWriter ();
121134 cmd .setErr (new PrintWriter (sw ));
122135
123- int code = cmd .execute ("-f" , "topic " );
136+ int code = cmd .execute ("-f" , "src/test/resources/topics-empty " );
124137 assertEquals (2 , code );
125- assertTrue (sw .toString ().contains ("Could not find YAML or YML files in topic directory." ));
138+ assertTrue (sw .toString ().contains ("Could not find YAML or YML files in topics-empty directory." ));
126139 }
127140
128141 @ Test
@@ -152,7 +165,7 @@ void shouldNotDeleteByFileWhenInvalidResources() {
152165 .when (resourceService )
153166 .validateAllowedResources (any (), any ());
154167
155- int code = cmd .execute ("-f" , "topic" , "-n" , "namespace" );
168+ int code = cmd .execute ("-f" , "src/test/resources/topics/ topic.yml " , "-n" , "namespace" );
156169 assertEquals (2 , code );
157170 assertTrue (sw .toString ().contains ("The server does not have resource type(s) Topic." ));
158171 }
@@ -195,7 +208,7 @@ void shouldNotDeleteByFileWhenNamespaceMismatch() {
195208 StringWriter sw = new StringWriter ();
196209 cmd .setErr (new PrintWriter (sw ));
197210
198- int code = cmd .execute ("-f" , "topic" , "-n" , "namespaceMismatch" );
211+ int code = cmd .execute ("-f" , "src/test/resources/topics/ topic.yml " , "-n" , "namespaceMismatch" );
199212 assertEquals (2 , code );
200213 assertTrue (sw .toString ()
201214 .contains ("Namespace mismatch between Kafkactl configuration and YAML resource(s): "
@@ -237,7 +250,7 @@ void shouldDeleteByFile() {
237250 StringWriter sw = new StringWriter ();
238251 cmd .setOut (new PrintWriter (sw ));
239252
240- int code = cmd .execute ("-f" , "topic" , "-n" , "namespace" );
253+ int code = cmd .execute ("-f" , "src/test/resources/topics/ topic.yml " , "-n" , "namespace" );
241254 assertEquals (0 , code );
242255 }
243256
@@ -276,7 +289,7 @@ void shouldDeleteOneVersionByFile() {
276289 StringWriter sw = new StringWriter ();
277290 cmd .setOut (new PrintWriter (sw ));
278291
279- int code = cmd .execute ("-f" , "topic" , "-n" , "namespace" );
292+ int code = cmd .execute ("-f" , "src/test/resources/topics/ topic.yml " , "-n" , "namespace" );
280293 assertEquals (0 , code );
281294 }
282295
@@ -364,7 +377,7 @@ void shouldNotDeleteByFileWhenInDryRunMode() {
364377 StringWriter sw = new StringWriter ();
365378 cmd .setOut (new PrintWriter (sw ));
366379
367- int code = cmd .execute ("-f" , "topic" , "--dry-run" , "-n" , "namespace" );
380+ int code = cmd .execute ("-f" , "src/test/resources/topics/ topic.yml " , "--dry-run" , "-n" , "namespace" );
368381 assertEquals (0 , code );
369382 assertTrue (sw .toString ().contains ("Dry run execution." ));
370383 }
@@ -402,7 +415,7 @@ void shouldNotDeleteByFileWhenFail() {
402415
403416 CommandLine cmd = new CommandLine (delete );
404417
405- int code = cmd .execute ("-f" , "topic" , "-n" , "namespace" );
418+ int code = cmd .execute ("-f" , "src/test/resources/topics/ topic.yml " , "-n" , "namespace" );
406419 assertEquals (1 , code );
407420 }
408421
@@ -431,7 +444,7 @@ void shouldNotDeleteByFileWhenHttpClientResponseException() {
431444
432445 CommandLine cmd = new CommandLine (delete );
433446
434- int code = cmd .execute ("-f" , "topic" , "-n" , "namespace" );
447+ int code = cmd .execute ("-f" , "src/test/resources/topics/ topic.yml " , "-n" , "namespace" );
435448 assertEquals (1 , code );
436449 verify (formatService ).displayError (exception , cmd .getCommandSpec ());
437450 }
0 commit comments