1
1
import path from "path" ;
2
- import test , { Test } from "tape-promise/tape" ;
3
2
import { v4 as uuidv4 } from "uuid" ;
4
-
3
+ import "jest-extended" ;
5
4
import { LogLevelDesc } from "@hyperledger/cactus-common" ;
6
-
7
5
import {
8
6
ApiServer ,
9
7
AuthorizationProtocol ,
@@ -15,47 +13,59 @@ import {
15
13
} from "@hyperledger/cactus-core-api" ;
16
14
17
15
const logLevel : LogLevelDesc = "TRACE" ;
18
-
19
- test ( "can import plugins at runtime (CLI)" , async ( t : Test ) => {
20
- const pluginsPath = path . join (
21
- __dirname , // start at the current file's path
22
- "../../../../../../" , // walk back up to the project root
23
- ".tmp/test/cmd-api-server/runtime-plugin-imports_test" , // the dir path from the root
24
- uuidv4 ( ) , // then a random directory to ensure proper isolation
25
- ) ;
26
- const pluginManagerOptionsJson = JSON . stringify ( { pluginsPath } ) ;
27
-
28
- const configService = new ConfigService ( ) ;
29
- const apiServerOptions = await configService . newExampleConfig ( ) ;
30
- apiServerOptions . authorizationProtocol = AuthorizationProtocol . NONE ;
31
- apiServerOptions . pluginManagerOptionsJson = pluginManagerOptionsJson ;
32
- apiServerOptions . configFile = "" ;
33
- apiServerOptions . apiCorsDomainCsv = "*" ;
34
- apiServerOptions . apiPort = 0 ;
35
- apiServerOptions . cockpitPort = 0 ;
36
- apiServerOptions . grpcPort = 0 ;
37
- apiServerOptions . apiTlsEnabled = false ;
38
- apiServerOptions . plugins = [
39
- {
40
- packageName : "@hyperledger/cactus-plugin-keychain-memory" ,
41
- type : PluginImportType . Local ,
42
- action : PluginImportAction . Install ,
43
- options : {
44
- instanceId : uuidv4 ( ) ,
45
- keychainId : uuidv4 ( ) ,
46
- logLevel,
16
+ const testCase = "can import plugins at runtime (CLI)" ;
17
+ describe ( testCase , ( ) => {
18
+ let apiServer : ApiServer ;
19
+ test ( testCase , async ( ) => {
20
+ const pluginsPath = path . join (
21
+ __dirname , // start at the current file's path
22
+ "../../../../../../" , // walk back up to the project root
23
+ ".tmp/test/cmd-api-server/runtime-plugin-imports_test" , // the dir path from the root
24
+ uuidv4 ( ) , // then a random directory to ensure proper isolation
25
+ ) ;
26
+ const pluginManagerOptionsJson = JSON . stringify ( { pluginsPath } ) ;
27
+ const configService = new ConfigService ( ) ;
28
+ const apiServerOptions = await configService . newExampleConfig ( ) ;
29
+ apiServerOptions . authorizationProtocol = AuthorizationProtocol . NONE ;
30
+ apiServerOptions . pluginManagerOptionsJson = pluginManagerOptionsJson ;
31
+ apiServerOptions . configFile = "" ;
32
+ apiServerOptions . apiCorsDomainCsv = "*" ;
33
+ apiServerOptions . apiPort = 0 ;
34
+ apiServerOptions . cockpitPort = 0 ;
35
+ apiServerOptions . grpcPort = 0 ;
36
+ apiServerOptions . apiTlsEnabled = false ;
37
+ apiServerOptions . plugins = [
38
+ {
39
+ packageName : "@hyperledger/cactus-plugin-keychain-memory" ,
40
+ type : PluginImportType . Local ,
41
+ action : PluginImportAction . Install ,
42
+ options : {
43
+ instanceId : uuidv4 ( ) ,
44
+ keychainId : uuidv4 ( ) ,
45
+ logLevel,
46
+ } ,
47
47
} ,
48
- } ,
49
- ] ;
50
- const config = await configService . newExampleConfigConvict ( apiServerOptions ) ;
48
+ ] ;
49
+ const config = await configService . newExampleConfigConvict (
50
+ apiServerOptions ,
51
+ ) ;
51
52
52
- const apiServer = new ApiServer ( {
53
- config : config . getProperties ( ) ,
53
+ apiServer = new ApiServer ( {
54
+ config : config . getProperties ( ) ,
55
+ } ) ;
56
+ apiServerOptions . plugins = [
57
+ {
58
+ packageName : "@hyperledger/cactus-plugin-keychain-memory" ,
59
+ type : PluginImportType . Local ,
60
+ action : PluginImportAction . Install ,
61
+ options : {
62
+ instanceId : uuidv4 ( ) ,
63
+ keychainId : uuidv4 ( ) ,
64
+ logLevel,
65
+ } ,
66
+ } ,
67
+ ] ;
68
+ await expect ( apiServer . start ( ) ) . not . toReject ( ) ;
54
69
} ) ;
55
-
56
- await t . doesNotReject (
57
- apiServer . start ( ) ,
58
- "failed to start API server with dynamic plugin imports configured for it..." ,
59
- ) ;
60
- test . onFinish ( ( ) => apiServer . shutdown ( ) ) ;
70
+ afterAll ( async ( ) => await apiServer . shutdown ( ) ) ;
61
71
} ) ;
0 commit comments