@@ -53,9 +53,16 @@ function createPlugin(
53
53
{
54
54
required = [ ] ,
55
55
optional = [ ] ,
56
+ requiredOSPlugin = [ ] ,
56
57
server = true ,
57
58
ui = true ,
58
- } : { required ?: string [ ] ; optional ?: string [ ] ; server ?: boolean ; ui ?: boolean } = { }
59
+ } : {
60
+ required ?: string [ ] ;
61
+ optional ?: string [ ] ;
62
+ requiredOSPlugin ?: string [ ] ;
63
+ server ?: boolean ;
64
+ ui ?: boolean ;
65
+ } = { }
59
66
) {
60
67
return new PluginWrapper ( {
61
68
path : 'some-path' ,
@@ -65,6 +72,7 @@ function createPlugin(
65
72
configPath : 'path' ,
66
73
opensearchDashboardsVersion : '7.0.0' ,
67
74
requiredPlugins : required ,
75
+ requiredOpenSearchPlugins : requiredOSPlugin ,
68
76
optionalPlugins : optional ,
69
77
requiredBundles : [ ] ,
70
78
server,
@@ -187,7 +195,7 @@ test('correctly orders plugins and returns exposed values for "setup" and "start
187
195
}
188
196
const plugins = new Map ( [
189
197
[
190
- createPlugin ( 'order-4' , { required : [ 'order-2' ] } ) ,
198
+ createPlugin ( 'order-4' , { required : [ 'order-2' ] , requiredOSPlugin : [ 'test-plugin' ] } ) ,
191
199
{
192
200
setup : { 'order-2' : 'added-as-2' } ,
193
201
start : { 'order-2' : 'started-as-2' } ,
@@ -244,6 +252,17 @@ test('correctly orders plugins and returns exposed values for "setup" and "start
244
252
startContextMap . get ( plugin . name )
245
253
) ;
246
254
255
+ const opensearch = startDeps . opensearch ;
256
+ opensearch . client . asInternalUser . cat . plugins . mockResolvedValueOnce ( {
257
+ body : [
258
+ {
259
+ name : 'node-1' ,
260
+ component : 'test-plugin' ,
261
+ version : 'v1' ,
262
+ } ,
263
+ ] ,
264
+ } as any ) ;
265
+
247
266
expect ( [ ...( await pluginsSystem . setupPlugins ( setupDeps ) ) ] ) . toMatchInlineSnapshot ( `
248
267
Array [
249
268
Array [
@@ -517,4 +536,71 @@ describe('start', () => {
517
536
const log = logger . get . mock . results [ 0 ] . value as jest . Mocked < Logger > ;
518
537
expect ( log . info ) . toHaveBeenCalledWith ( `Starting [2] plugins: [order-1,order-0]` ) ;
519
538
} ) ;
539
+
540
+ it ( 'validates opensearch plugin installation' , async ( ) => {
541
+ [
542
+ createPlugin ( 'order-1' , { requiredOSPlugin : [ 'test-plugin' ] } ) ,
543
+ createPlugin ( 'order-2' ) ,
544
+ ] . forEach ( ( plugin , index ) => {
545
+ jest . spyOn ( plugin , 'setup' ) . mockResolvedValue ( `setup-as-${ index } ` ) ;
546
+ jest . spyOn ( plugin , 'start' ) . mockResolvedValue ( `started-as-${ index } ` ) ;
547
+ pluginsSystem . addPlugin ( plugin ) ;
548
+ } ) ;
549
+
550
+ const opensearch = startDeps . opensearch ;
551
+ opensearch . client . asInternalUser . cat . plugins . mockResolvedValueOnce ( {
552
+ body : [
553
+ {
554
+ name : 'node-1' ,
555
+ component : 'test-plugin' ,
556
+ version : 'v1' ,
557
+ } ,
558
+ ] ,
559
+ } as any ) ;
560
+ await pluginsSystem . setupPlugins ( setupDeps ) ;
561
+ await pluginsSystem . startPlugins ( startDeps ) ;
562
+ expect ( opensearch . client . asInternalUser . cat . plugins ) . toHaveBeenCalledTimes ( 1 ) ;
563
+ } ) ;
564
+
565
+ it ( 'validates opensearch plugin installation and errors out when plugin is not installed' , async ( ) => {
566
+ [
567
+ createPlugin ( 'id-1' , { requiredOSPlugin : [ 'missing-opensearch-dep' ] } ) ,
568
+ createPlugin ( 'id-2' ) ,
569
+ ] . forEach ( ( plugin , index ) => {
570
+ jest . spyOn ( plugin , 'setup' ) . mockResolvedValue ( `setup-as-${ index } ` ) ;
571
+ jest . spyOn ( plugin , 'start' ) . mockResolvedValue ( `started-as-${ index } ` ) ;
572
+ pluginsSystem . addPlugin ( plugin ) ;
573
+ } ) ;
574
+ const opensearch = startDeps . opensearch ;
575
+ opensearch . client . asInternalUser . cat . plugins . mockResolvedValueOnce ( {
576
+ body : [
577
+ {
578
+ name : 'node-1' ,
579
+ component : 'test-plugin1' ,
580
+ version : 'v1' ,
581
+ } ,
582
+ ] ,
583
+ } as any ) ;
584
+ await pluginsSystem . setupPlugins ( setupDeps ) ;
585
+
586
+ await expect ( pluginsSystem . startPlugins ( startDeps ) ) . rejects . toMatchInlineSnapshot (
587
+ `[Error: Plugin "id-1" has a dependency on OpenSearch data source plugin "missing-opensearch-dep" which needs to be installed.]`
588
+ ) ;
589
+ } ) ;
590
+
591
+ it ( 'validates opensearch plugin installation and does not errors out when there is no dependency' , async ( ) => {
592
+ [ createPlugin ( 'id-1' ) , createPlugin ( 'id-2' ) ] . forEach ( ( plugin , index ) => {
593
+ jest . spyOn ( plugin , 'setup' ) . mockResolvedValue ( `setup-as-${ index } ` ) ;
594
+ jest . spyOn ( plugin , 'start' ) . mockResolvedValue ( `started-as-${ index } ` ) ;
595
+ pluginsSystem . addPlugin ( plugin ) ;
596
+ } ) ;
597
+ const opensearch = startDeps . opensearch ;
598
+ opensearch . client . asInternalUser . cat . plugins . mockResolvedValueOnce ( {
599
+ body : [ ] ,
600
+ } as any ) ;
601
+ await pluginsSystem . setupPlugins ( setupDeps ) ;
602
+ const pluginsStart = await pluginsSystem . startPlugins ( startDeps ) ;
603
+ expect ( pluginsStart ) . toBeInstanceOf ( Map ) ;
604
+ expect ( opensearch . client . asInternalUser . cat . plugins ) . toHaveBeenCalledTimes ( 1 ) ;
605
+ } ) ;
520
606
} ) ;
0 commit comments