@@ -26,7 +26,7 @@ export class PluginTester {
2626 modifiedConfigs : ResourceConfig [ ] ,
2727 validateModify ?: ( plans : PlanResponseData [ ] ) => Promise < void > | void ,
2828 }
29- } ) : Promise < void > {
29+ } ) : Promise < void > {
3030 configs = configs . filter ( ( c ) => ! c . os || c . os . includes ( getPlatformOs ( ) ) ) ;
3131 const ids = configs
3232 . map ( ( c ) => `${ c . type } ${ c . name ? `.${ c . name } ` : '' } ` )
@@ -51,13 +51,15 @@ export class PluginTester {
5151 throw new Error ( `The plugin does not support the following configs supplied:\n ${ JSON . stringify ( unsupportedConfigs , null , 2 ) } \n Initialize result: ${ JSON . stringify ( initializeResult ) } ` )
5252 }
5353
54- configs = configs . filter ( ( c ) => initializeResult . resourceDefinitions . find ( ( rd ) => rd . type === c . type ) ?. operatingSystems ?. includes ( os . platform ( ) as OS ) ) ;
54+ // configs = configs.filter((c) => initializeResult.resourceDefinitions.find((rd) => rd.type === c.type)?.operatingSystems?.includes(os.platform() as OS));
5555
5656 console . info ( chalk . cyan ( 'Testing validate...' ) )
57- const validate = await plugin . validate ( { configs : configs . map ( ( c ) => {
58- const { coreParameters, parameters } = splitUserConfig ( c )
59- return { core : coreParameters , parameters } ;
60- } ) } ) ;
57+ const validate = await plugin . validate ( {
58+ configs : configs . map ( ( c ) => {
59+ const { coreParameters, parameters } = splitUserConfig ( c )
60+ return { core : coreParameters , parameters } ;
61+ } )
62+ } ) ;
6163
6264 const invalidConfigs = validate . resourceValidations . filter ( ( v ) => ! v . isValid )
6365 if ( invalidConfigs . length > 0 ) {
@@ -68,7 +70,7 @@ export class PluginTester {
6870 const plans = [ ] ;
6971 for ( const config of configs ) {
7072 const { coreParameters, parameters } = splitUserConfig ( config ) ;
71-
73+
7274 plans . push ( await plugin . plan ( {
7375 core : coreParameters ,
7476 desired : parameters ,
@@ -127,7 +129,7 @@ export class PluginTester {
127129 const modifyPlans = [ ] ;
128130 for ( const config of options . testModify . modifiedConfigs ) {
129131 const { coreParameters, parameters } = splitUserConfig ( config ) ;
130-
132+
131133 modifyPlans . push ( await modifyPlugin . plan ( {
132134 core : coreParameters ,
133135 desired : parameters ,
@@ -167,6 +169,59 @@ ${JSON.stringify(modifyPlans, null, 2)}`)
167169 }
168170 }
169171
172+ static async install ( pluginPath : string , configs : ResourceConfig [ ] ) {
173+ const plugin = new PluginProcess ( pluginPath ) ;
174+
175+ try {
176+ console . info ( chalk . cyan ( 'Testing initialization...' ) )
177+ const initializeResult = await plugin . initialize ( ) ;
178+
179+ const unsupportedConfigs = configs . filter ( ( c ) =>
180+ ! initializeResult . resourceDefinitions . some ( ( rd ) => rd . type === c . type )
181+ )
182+ if ( unsupportedConfigs . length > 0 ) {
183+ throw new Error ( `The plugin does not support the following configs supplied:\n ${ JSON . stringify ( unsupportedConfigs , null , 2 ) } \n Initialize result: ${ JSON . stringify ( initializeResult ) } ` )
184+ }
185+
186+ // configs = configs.filter((c) => initializeResult.resourceDefinitions.find((rd) => rd.type === c.type)?.operatingSystems?.includes(os.platform() as OS));
187+
188+ console . info ( chalk . cyan ( 'Testing validate...' ) )
189+ const validate = await plugin . validate ( {
190+ configs : configs . map ( ( c ) => {
191+ const { coreParameters, parameters } = splitUserConfig ( c )
192+ return { core : coreParameters , parameters } ;
193+ } )
194+ } ) ;
195+
196+ const invalidConfigs = validate . resourceValidations . filter ( ( v ) => ! v . isValid )
197+ if ( invalidConfigs . length > 0 ) {
198+ throw new Error ( `The following configs did not validate:\n ${ JSON . stringify ( invalidConfigs , null , 2 ) } ` )
199+ }
200+
201+ console . info ( chalk . cyan ( 'Testing plan...' ) )
202+ const plans = [ ] ;
203+ for ( const config of configs ) {
204+ const { coreParameters, parameters } = splitUserConfig ( config ) ;
205+
206+ plans . push ( await plugin . plan ( {
207+ core : coreParameters ,
208+ desired : parameters ,
209+ isStateful : false ,
210+ state : undefined ,
211+ } ) ) ;
212+ }
213+
214+ console . info ( chalk . cyan ( 'Testing apply...' ) )
215+ for ( const plan of plans ) {
216+ await plugin . apply ( {
217+ planId : plan . planId
218+ } ) ;
219+ }
220+ } finally {
221+ plugin . kill ( ) ;
222+ }
223+ }
224+
170225 static async uninstall ( pluginPath : string , configs : ResourceConfig [ ] , options ?: {
171226 validateDestroy ?: ( plans : PlanResponseData [ ] ) => Promise < void > | void
172227 } ) {
@@ -179,7 +234,7 @@ ${JSON.stringify(modifyPlans, null, 2)}`)
179234 const plans = [ ] ;
180235 for ( const config of configs ) {
181236 const { coreParameters, parameters } = splitUserConfig ( config ) ;
182-
237+
183238 plans . push ( await destroyPlugin . plan ( {
184239 core : coreParameters ,
185240 isStateful : true ,
@@ -213,7 +268,9 @@ ${JSON.stringify(modifyPlans, null, 2)}`)
213268 for ( const type of typeSet ) {
214269 const sameTypeConfigs = configs . filter ( ( c ) => c . type === type ) ;
215270 if ( sameTypeConfigs . length > 1 ) {
216- sameTypeConfigs . forEach ( ( c , idx ) => { c . name = c . name ?? idx . toString ( ) } ) ;
271+ sameTypeConfigs . forEach ( ( c , idx ) => {
272+ c . name = c . name ?? idx . toString ( )
273+ } ) ;
217274 }
218275
219276 configsWithNames . push ( ...sameTypeConfigs ) ;
0 commit comments