Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(cmd-api-server): migrate import from github test to Jest #3426

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ jobs:
JEST_TEST_COVERAGE_PATH: ./code-coverage-ts/cactus-cmd-api-server
JEST_TEST_CODE_COVERAGE_ENABLED: true
TAPE_TEST_PATTERN: >-
--files={./packages/cactus-cmd-api-server/src/test/typescript/integration/plugin-import-from-github.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/integration/plugin-import-without-install.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/integration/remote-plugin-imports.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/config/self-signed-certificate-generator/certificates-work-for-mutual-tls.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/config/self-signed-certificate-generator/generates-working-certificates.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/grpc-js-proto-loader-client-healthcheck.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/grpc-proto-gen-ts-client-healthcheck.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/grpc-proto-gen-ts-client-m-tls-enabled.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/plugins/install-basic-plugin-consortium-manual.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/plugins/install-basic-plugin-keychain-memory.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/plugins/install-basic-plugin-ledger-connector-fabric-0-7-0.test.ts}
--files={./packages/cactus-cmd-api-server/src/test/typescript/unit/config/self-signed-certificate-generator/certificates-work-for-mutual-tls.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/config/self-signed-certificate-generator/generates-working-certificates.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/grpc-js-proto-loader-client-healthcheck.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/grpc-proto-gen-ts-client-healthcheck.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/grpc-proto-gen-ts-client-m-tls-enabled.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/plugins/install-basic-plugin-consortium-manual.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/plugins/install-basic-plugin-keychain-memory.test.ts,./packages/cactus-cmd-api-server/src/test/typescript/unit/plugins/install-basic-plugin-ledger-connector-fabric-0-7-0.test.ts}
TAPE_TEST_RUNNER_DISABLED: false
runs-on: ubuntu-22.04
steps:
Expand Down
3 changes: 0 additions & 3 deletions .taprc
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ files:
- ./packages/cactus-test-tooling/src/test/typescript/integration/besu/besu-test-ledger/constructor-validates-options.test.ts
- ./packages/cactus-test-plugin-htlc-eth-besu/src/test/typescript/integration/plugin-htlc-eth-besu/get-single-status-endpoint.test.ts
- ./packages/cactus-test-plugin-htlc-eth-besu/src/test/typescript/integration/plugin-htlc-eth-besu/openapi/openapi-validation.test.ts
- ./packages/cactus-cmd-api-server/src/test/typescript/integration/remote-plugin-imports.test.ts
- ./packages/cactus-cmd-api-server/src/test/typescript/integration/plugin-import-from-github.test.ts
- ./packages/cactus-cmd-api-server/src/test/typescript/integration/plugin-import-without-install.test.ts
- ./packages/cactus-cmd-api-server/src/test/typescript/unit/plugins/install-basic-plugin-keychain-memory.test.ts
- ./packages/cactus-cmd-api-server/src/test/typescript/unit/plugins/install-basic-plugin-ledger-connector-fabric-0-7-0.test.ts
- ./packages/cactus-cmd-api-server/src/test/typescript/unit/plugins/install-basic-plugin-consortium-manual.test.ts
Expand Down
3 changes: 0 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ module.exports = {
`./packages/cactus-test-plugin-htlc-eth-besu/src/test/typescript/integration/plugin-htlc-eth-besu/get-single-status-endpoint.test.ts`,
`./packages/cactus-test-plugin-htlc-eth-besu/src/test/typescript/integration/plugin-htlc-eth-besu/get--status-endpoint-invalid.test.ts`,
`./packages/cactus-test-plugin-htlc-eth-besu/src/test/typescript/integration/plugin-htlc-eth-besu/openapi/openapi-validation.test.ts`,
`./packages/cactus-cmd-api-server/src/test/typescript/integration/remote-plugin-imports.test.ts`,
`./packages/cactus-cmd-api-server/src/test/typescript/integration/plugin-import-from-github.test.ts`,
`./packages/cactus-cmd-api-server/src/test/typescript/integration/plugin-import-without-install.test.ts`,
`./packages/cactus-cmd-api-server/src/test/typescript/unit/plugins/install-basic-plugin-keychain-memory.test.ts`,
`./packages/cactus-cmd-api-server/src/test/typescript/unit/plugins/install-basic-plugin-ledger-connector-fabric-0-7-0.test.ts`,
`./packages/cactus-cmd-api-server/src/test/typescript/unit/plugins/install-basic-plugin-consortium-manual.test.ts`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,86 +1,91 @@
import path from "path";
import test, { Test } from "tape-promise/tape";
import { v4 as uuidv4 } from "uuid";
import { readFile } from "fs/promises";
import { LogLevelDesc } from "@hyperledger/cactus-common";
import { randomUUID } from "node:crypto";
import path from "node:path";
import { readFile } from "node:fs/promises";

import "jest-extended";
import { LoggerProvider, LogLevelDesc } from "@hyperledger/cactus-common";
import {
PluginImportAction,
PluginImportType,
} from "@hyperledger/cactus-core-api";
import {
ApiServer,
AuthorizationProtocol,
ConfigService,
} from "../../../main/typescript/public-api";
import { ConfigService } from "../../../main/typescript/config/config-service";
import { AuthorizationProtocol } from "../../../main/typescript/config/authorization-protocol";
import { ApiServer } from "../../../main/typescript/api-server";

const logLevel: LogLevelDesc = "TRACE";
describe("ApiServer", () => {
let apiServer: ApiServer;

const logLevel: LogLevelDesc = "INFO";

const log = LoggerProvider.getOrCreate({
label: "plugin-import-from-github.test.ts",
level: logLevel,
});

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-from-github_test/", // the dir path from the root
uuidv4(), // then a random directory to ensure proper isolation
randomUUID(), // then a random directory to ensure proper isolation
);
const pluginManagerOptionsJson = JSON.stringify({ pluginsPath });

const configService = new ConfigService();

const apiServerOptions = await configService.newExampleConfig();
apiServerOptions.pluginManagerOptionsJson = pluginManagerOptionsJson;
apiServerOptions.authorizationProtocol = AuthorizationProtocol.NONE;
apiServerOptions.configFile = "";
apiServerOptions.apiCorsDomainCsv = "*";
apiServerOptions.apiPort = 0;
apiServerOptions.cockpitPort = 0;
apiServerOptions.grpcPort = 0;
apiServerOptions.crpcPort = 0;
apiServerOptions.apiTlsEnabled = false;
apiServerOptions.plugins = [
{
packageName: "@hyperledger/cactus-dummy-package",
type: PluginImportType.Local,
action: PluginImportAction.Install,
options: {
instanceId: uuidv4(),
keychainId: uuidv4(),
logLevel,
packageSrc:
"https://gitpkg.now.sh/hyperledger/cactus/packages/cactus-cmd-api-server/src/test/resources/cactus-dummy-package?main",
},
},
];
const config = await configService.newExampleConfigConvict(apiServerOptions);

const apiServer = new ApiServer({
config: config.getProperties(),
afterAll(async () => {
await apiServer.shutdown();
});

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");
it("can install plugins at runtime from GitHub", async () => {
const apiSrvOpts = await configService.newExampleConfig();
apiSrvOpts.pluginManagerOptionsJson = pluginManagerOptionsJson;
apiSrvOpts.authorizationProtocol = AuthorizationProtocol.NONE;
apiSrvOpts.configFile = "";
apiSrvOpts.apiCorsDomainCsv = "*";
apiSrvOpts.apiPort = 0;
apiSrvOpts.cockpitPort = 0;
apiSrvOpts.grpcPort = 0;
apiSrvOpts.crpcPort = 0;
apiSrvOpts.apiTlsEnabled = false;
apiSrvOpts.plugins = [
{
packageName: "@hyperledger/cactus-dummy-package",
type: PluginImportType.Local,
action: PluginImportAction.Install,
options: {
instanceId: randomUUID(),
keychainId: randomUUID(),
logLevel,
packageSrc:
"https://gitpkg.now.sh/hyperledger/cactus/packages/cactus-cmd-api-server/src/test/resources/cactus-dummy-package?main",
},
},
];
const config = await configService.newExampleConfigConvict(apiSrvOpts);

const packageFilePath = path.join(
pluginsPath,
apiServerOptions.plugins[0].options.instanceId,
"node_modules",
`${apiServerOptions.plugins[0].packageName}`,
"package.json",
);
apiServer = new ApiServer({
config: config.getProperties(),
});

const pkgJsonStr = await readFile(packageFilePath, "utf-8");
const { name, version } = JSON.parse(pkgJsonStr);
const startPromise = apiServer.start();
await expect(startPromise).toResolve();
await expect(startPromise).toBeTruthy();
await expect((await startPromise).addressInfoApi).toBeTruthy();
await expect((await startPromise).addressInfoCrpc).toBeTruthy();
await expect((await startPromise).addressInfoGrpc).toBeTruthy();

t.comment(name);
t.comment(version);
t.strictEquals(
name,
apiServerOptions.plugins[0].packageName,
`Package name strictly equal to ${apiServerOptions.plugins[0].packageName}`,
);
const packageFilePath = path.join(
pluginsPath,
apiSrvOpts.plugins[0].options.instanceId,
"node_modules",
`${apiSrvOpts.plugins[0].packageName}`,
"package.json",
);

const pkgJsonStr = await readFile(packageFilePath, "utf-8");
const { name, version } = JSON.parse(pkgJsonStr);

test.onFinish(() => apiServer.shutdown());
log.debug("installed package name on file-system:", name);
log.debug("installed package version on file-system:", version);
expect(name).toEqual(apiSrvOpts.plugins[0].packageName);
});
});
Loading
Loading