forked from hyperledger-cacti/cacti
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(connector-besu): migrate get-past-logs-endpoint to Jest
Primary Changes ------------------ 1. Updated the migrate get-past-logs-endpoint test to use Jest 2. Updated the ci.yaml TAPE_TEST_PATTERN to incorporate the same Fixes hyperledger-cacti#3505 Signed-off-by: Akshitha1020 <[email protected]>
- Loading branch information
1 parent
aa0108b
commit f93bee4
Showing
11 changed files
with
259 additions
and
220 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
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
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
145 changes: 77 additions & 68 deletions
145
...ctus-cmd-api-server/src/test/typescript/unit/grpc-proto-gen-ts-client-healthcheck.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 |
---|---|---|
@@ -1,88 +1,97 @@ | ||
import test, { Test } from "tape-promise/tape"; | ||
|
||
import "jest-extended"; | ||
import * as grpc from "@grpc/grpc-js"; | ||
import { RuntimeError } from "run-time-error-cjs"; | ||
|
||
import { LogLevelDesc } from "@hyperledger/cactus-common"; | ||
|
||
import { ApiServer, ConfigService } from "../../../main/typescript/public-api"; | ||
import { | ||
ApiServer, | ||
ConfigService, | ||
ICactusApiServerOptions, | ||
} from "../../../main/typescript/public-api"; | ||
import { AuthorizationProtocol } from "../../../main/typescript/public-api"; | ||
import { default_service } from "../../../main/typescript/public-api"; | ||
import { health_check_response_pb } from "../../../main/typescript/public-api"; | ||
import { empty } from "../../../main/typescript/public-api"; | ||
import { RuntimeError } from "run-time-error-cjs"; | ||
|
||
const testCase = "API server: runs gRPC TS-proto web services"; | ||
const logLevel: LogLevelDesc = "TRACE"; | ||
const logLevel: LogLevelDesc = "INFO"; | ||
|
||
test(testCase, async (t: Test) => { | ||
const configService = new ConfigService(); | ||
const apiSrvOpts = await configService.newExampleConfig(); | ||
apiSrvOpts.authorizationProtocol = AuthorizationProtocol.NONE; | ||
apiSrvOpts.configFile = ""; | ||
apiSrvOpts.logLevel = logLevel; | ||
apiSrvOpts.apiCorsDomainCsv = "*"; | ||
apiSrvOpts.apiPort = 0; | ||
apiSrvOpts.grpcPort = 0; | ||
apiSrvOpts.crpcPort = 0; | ||
apiSrvOpts.cockpitPort = 0; | ||
apiSrvOpts.grpcMtlsEnabled = false; | ||
apiSrvOpts.apiTlsEnabled = false; | ||
apiSrvOpts.plugins = []; | ||
const config = await configService.newExampleConfigConvict(apiSrvOpts); | ||
describe("ApiServer", () => { | ||
let apiServer: ApiServer; | ||
let config: ICactusApiServerOptions; | ||
let apiClient: default_service.org.hyperledger.cactus.cmd_api_server.DefaultServiceClient; | ||
|
||
const apiServer = new ApiServer({ | ||
config: config.getProperties(), | ||
afterAll(async () => { | ||
await apiServer.shutdown(); | ||
}); | ||
test.onFinish(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"); | ||
beforeAll(async () => { | ||
const configService = new ConfigService(); | ||
const apiSrvOpts = await configService.newExampleConfig(); | ||
apiSrvOpts.authorizationProtocol = AuthorizationProtocol.NONE; | ||
apiSrvOpts.configFile = ""; | ||
apiSrvOpts.logLevel = logLevel; | ||
apiSrvOpts.apiCorsDomainCsv = "*"; | ||
apiSrvOpts.apiPort = 0; | ||
apiSrvOpts.grpcPort = 0; | ||
apiSrvOpts.crpcPort = 0; | ||
apiSrvOpts.cockpitPort = 0; | ||
apiSrvOpts.grpcMtlsEnabled = false; | ||
apiSrvOpts.apiTlsEnabled = false; | ||
apiSrvOpts.plugins = []; | ||
const convictCfg = await configService.newExampleConfigConvict(apiSrvOpts); | ||
config = convictCfg.getProperties(); | ||
|
||
const addressInfoGrpc = (await startResponse).addressInfoGrpc; | ||
const { address, port } = addressInfoGrpc; | ||
const grpcHostAndPort = `${address}:${port}`; | ||
apiServer = new ApiServer({ | ||
config, | ||
}); | ||
|
||
const apiClient = | ||
new default_service.org.hyperledger.cactus.cmd_api_server.DefaultServiceClient( | ||
grpcHostAndPort, | ||
grpc.credentials.createInsecure(), | ||
); | ||
t.ok(apiClient, "apiClient truthy OK"); | ||
const apiServerStart = apiServer.start(); | ||
await expect(apiServerStart).toResolve(); | ||
const addressInfoGrpc = (await apiServerStart).addressInfoGrpc; | ||
const { address, port } = addressInfoGrpc; | ||
const grpcHostAndPort = `${address}:${port}`; | ||
|
||
const responsePromise = | ||
new Promise<health_check_response_pb.org.hyperledger.cactus.cmd_api_server.HealthCheckResponsePB>( | ||
(resolve, reject) => { | ||
apiClient.GetHealthCheckV1( | ||
new empty.google.protobuf.Empty(), | ||
( | ||
error: grpc.ServiceError | null, | ||
response?: health_check_response_pb.org.hyperledger.cactus.cmd_api_server.HealthCheckResponsePB, | ||
) => { | ||
if (error) { | ||
reject(error); | ||
} else if (response) { | ||
resolve(response); | ||
} else { | ||
throw new RuntimeError("No error, nor response received."); | ||
} | ||
}, | ||
); | ||
}, | ||
); | ||
apiClient = | ||
new default_service.org.hyperledger.cactus.cmd_api_server.DefaultServiceClient( | ||
grpcHostAndPort, | ||
grpc.credentials.createInsecure(), | ||
); | ||
expect(apiClient).toBeTruthy(); | ||
}); | ||
|
||
await t.doesNotReject(responsePromise, "No error in healthcheck OK"); | ||
const res = await responsePromise; | ||
test("runs gRPC TS-proto web services", async () => { | ||
type HealthCheckResponsePB = | ||
health_check_response_pb.org.hyperledger.cactus.cmd_api_server.HealthCheckResponsePB; | ||
|
||
const resHc = res?.toObject(); | ||
const grpcReq = new Promise<HealthCheckResponsePB>((resolve, reject) => { | ||
apiClient.GetHealthCheckV1( | ||
new empty.google.protobuf.Empty(), | ||
(error: grpc.ServiceError | null, response?: HealthCheckResponsePB) => { | ||
if (error) { | ||
reject(error); | ||
} else if (response) { | ||
resolve(response); | ||
} else { | ||
reject(new RuntimeError("No error, nor response received.")); | ||
} | ||
}, | ||
); | ||
}); | ||
|
||
t.ok(resHc, `healthcheck response truthy OK`); | ||
t.ok(resHc?.createdAt, `resHc.createdAt truthy OK`); | ||
t.ok(resHc?.memoryUsage, `resHc.memoryUsage truthy OK`); | ||
t.ok(resHc?.memoryUsage?.rss, `resHc.memoryUsage.rss truthy OK`); | ||
t.ok(resHc?.success, `resHc.success truthy OK`); | ||
t.end(); | ||
await expect(grpcReq).resolves.toMatchObject({ | ||
toObject: expect.toBeFunction(), | ||
}); | ||
|
||
const resPb = await grpcReq; | ||
const res = resPb.toObject(); | ||
|
||
expect(res).toMatchObject({ | ||
createdAt: expect.toBeDateString(), | ||
memoryUsage: expect.objectContaining({ | ||
rss: expect.toBeNumber(), | ||
}), | ||
success: true, | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.