64
64
import java .io .BufferedReader ;
65
65
import java .io .ByteArrayInputStream ;
66
66
import java .io .ByteArrayOutputStream ;
67
+ import java .io .FileNotFoundException ;
67
68
import java .io .IOException ;
68
69
import java .io .InputStream ;
69
70
import java .io .StringReader ;
@@ -280,9 +281,17 @@ void installPlugin(String pluginUrl, Path home) throws Exception {
280
281
installPlugin (pluginUrl , home , skipJarHellCommand );
281
282
}
282
283
284
+ void installPlugins (final List <String > pluginUrls , final Path home ) throws Exception {
285
+ installPlugins (pluginUrls , home , skipJarHellCommand );
286
+ }
287
+
283
288
void installPlugin (String pluginUrl , Path home , InstallPluginCommand command ) throws Exception {
284
- Environment env = TestEnvironment .newEnvironment (Settings .builder ().put ("path.home" , home ).build ());
285
- command .execute (terminal , pluginUrl , false , env );
289
+ installPlugins (pluginUrl == null ? List .of () : List .of (pluginUrl ), home , command );
290
+ }
291
+
292
+ void installPlugins (final List <String > pluginUrls , final Path home , final InstallPluginCommand command ) throws Exception {
293
+ final Environment env = TestEnvironment .newEnvironment (Settings .builder ().put ("path.home" , home ).build ());
294
+ command .execute (terminal , pluginUrls , false , env );
286
295
}
287
296
288
297
void assertPlugin (String name , Path original , Environment env ) throws IOException {
@@ -382,7 +391,7 @@ void assertInstallCleaned(Environment env) throws IOException {
382
391
public void testMissingPluginId () throws IOException {
383
392
final Tuple <Path , Environment > env = createEnv (fs , temp );
384
393
final UserException e = expectThrows (UserException .class , () -> installPlugin (null , env .v1 ()));
385
- assertTrue (e .getMessage (), e .getMessage ().contains ("plugin id is required" ));
394
+ assertTrue (e .getMessage (), e .getMessage ().contains ("at least one plugin id is required" ));
386
395
}
387
396
388
397
public void testSomethingWorks () throws Exception {
@@ -393,6 +402,37 @@ public void testSomethingWorks() throws Exception {
393
402
assertPlugin ("fake" , pluginDir , env .v2 ());
394
403
}
395
404
405
+ public void testMultipleWorks () throws Exception {
406
+ Tuple <Path , Environment > env = createEnv (fs , temp );
407
+ Path pluginDir = createPluginDir (temp );
408
+ String fake1PluginZip = createPluginUrl ("fake1" , pluginDir );
409
+ String fake2PluginZip = createPluginUrl ("fake2" , pluginDir );
410
+ installPlugins (List .of (fake1PluginZip , fake2PluginZip ), env .v1 ());
411
+ assertPlugin ("fake1" , pluginDir , env .v2 ());
412
+ assertPlugin ("fake2" , pluginDir , env .v2 ());
413
+ }
414
+
415
+ public void testDuplicateInstall () throws Exception {
416
+ Tuple <Path , Environment > env = createEnv (fs , temp );
417
+ Path pluginDir = createPluginDir (temp );
418
+ String pluginZip = createPluginUrl ("fake" , pluginDir );
419
+ final UserException e = expectThrows (UserException .class , () -> installPlugins (List .of (pluginZip , pluginZip ), env .v1 ()));
420
+ assertThat (e , hasToString (containsString ("duplicate plugin id [" + pluginZip + "]" )));
421
+ }
422
+
423
+ public void testTransaction () throws Exception {
424
+ Tuple <Path , Environment > env = createEnv (fs , temp );
425
+ Path pluginDir = createPluginDir (temp );
426
+ String pluginZip = createPluginUrl ("fake" , pluginDir );
427
+ final FileNotFoundException e =
428
+ expectThrows (FileNotFoundException .class , () -> installPlugins (List .of (pluginZip , pluginZip + "does-not-exist" ), env .v1 ()));
429
+ assertThat (e , hasToString (containsString ("does-not-exist" )));
430
+ final Path fakeInstallPath = env .v2 ().pluginsFile ().resolve ("fake" );
431
+ // fake should have been removed when the file not found exception occurred
432
+ assertFalse (Files .exists (fakeInstallPath ));
433
+ assertInstallCleaned (env .v2 ());
434
+ }
435
+
396
436
public void testInstallFailsIfPreviouslyRemovedPluginFailed () throws Exception {
397
437
Tuple <Path , Environment > env = createEnv (fs , temp );
398
438
Path pluginDir = createPluginDir (temp );
@@ -769,7 +809,7 @@ Build.Flavor buildFlavor() {
769
809
};
770
810
771
811
final Environment environment = createEnv (fs , temp ).v2 ();
772
- final T exception = expectThrows (clazz , () -> flavorCommand .execute (terminal , "x-pack" , false , environment ));
812
+ final T exception = expectThrows (clazz , () -> flavorCommand .execute (terminal , List . of ( "x-pack" ) , false , environment ));
773
813
assertThat (exception , hasToString (containsString (expectedMessage )));
774
814
}
775
815
@@ -830,7 +870,7 @@ private void installPlugin(MockTerminal terminal, boolean isBatch) throws Except
830
870
writePluginSecurityPolicy (pluginDir , "setFactory" );
831
871
}
832
872
String pluginZip = createPlugin ("fake" , pluginDir ).toUri ().toURL ().toString ();
833
- skipJarHellCommand .execute (terminal , pluginZip , isBatch , env .v2 ());
873
+ skipJarHellCommand .execute (terminal , List . of ( pluginZip ) , isBatch , env .v2 ());
834
874
}
835
875
836
876
void assertInstallPluginFromUrl (
0 commit comments