forked from hyperledger-cacti/cacti
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cmd-api-server): enable version selection in plugins
cactus-cmd-api-server can now import plugins specifying the npm package version as a plugin option cmd-api-server: add missing dependency bluebird closes hyperledger-cacti#839 and hyperledger-cacti#840 Signed-off-by: Elena Izaguirre <e.izaguirre.equiza@accenture.com>
- Loading branch information
1 parent
6deed6d
commit d5855a6
Showing
4 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
.../src/test/typescript/integration/plugin-import-with-npm-install-version-selection.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import path from "path"; | ||
import test, { Test } from "tape-promise/tape"; | ||
import { v4 as uuidv4 } from "uuid"; | ||
import { LogLevelDesc } from "@hyperledger/cactus-common"; | ||
import { PluginImportType } from "@hyperledger/cactus-core-api"; | ||
import { | ||
ApiServer, | ||
AuthorizationProtocol, | ||
ConfigService, | ||
} from "@hyperledger/cactus-cmd-api-server"; | ||
|
||
const logLevel: LogLevelDesc = "TRACE"; | ||
|
||
test("can install plugins at runtime with specified version based on imports", async (t: Test) => { | ||
const pluginsPath = path.join( | ||
__dirname, | ||
"../../../../../../", // walk back up to the project root | ||
".tmp/test/test-cmd-api-server/plugin-import-with-npm-install_test/", // the dir path from the root | ||
uuidv4(), // then a random directory to ensure proper isolation | ||
); | ||
const pluginManagerOptionsJson = JSON.stringify({ pluginsPath }); | ||
|
||
const configService = new ConfigService(); | ||
|
||
const apiServerOptions = configService.newExampleConfig(); | ||
apiServerOptions.pluginManagerOptionsJson = pluginManagerOptionsJson; | ||
apiServerOptions.authorizationProtocol = AuthorizationProtocol.NONE; | ||
apiServerOptions.configFile = ""; | ||
apiServerOptions.apiCorsDomainCsv = "*"; | ||
apiServerOptions.apiPort = 0; | ||
apiServerOptions.cockpitPort = 0; | ||
apiServerOptions.grpcPort = 0; | ||
apiServerOptions.apiTlsEnabled = false; | ||
apiServerOptions.plugins = [ | ||
{ | ||
packageName: "@hyperledger/cactus-plugin-keychain-memory", | ||
type: PluginImportType.Local, | ||
options: { | ||
instanceId: uuidv4(), | ||
keychainId: uuidv4(), | ||
logLevel, | ||
version: "0.9.0", | ||
}, | ||
}, | ||
]; | ||
const config = configService.newExampleConfigConvict(apiServerOptions); | ||
|
||
const apiServer = new ApiServer({ | ||
config: config.getProperties(), | ||
}); | ||
|
||
const startResponse = apiServer.start(); | ||
await t.doesNotReject( | ||
startResponse, | ||
"failed to start API server with dynamic plugin imports configured for it...", | ||
); | ||
t.ok(startResponse, "startResponse truthy OK"); | ||
|
||
const packageFilePath = path.join( | ||
pluginsPath, | ||
apiServerOptions.plugins[0].options.instanceId, | ||
"package.json", | ||
); | ||
const { dependencies } = await import(packageFilePath); | ||
t.strictEquals( | ||
dependencies[`${apiServerOptions.plugins[0].packageName}`], | ||
apiServerOptions.plugins[0].options.version, | ||
); | ||
|
||
test.onFinish(() => apiServer.shutdown()); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters