From f312d3614c688a69e5e5f6882dbee91d4d5eefa9 Mon Sep 17 00:00:00 2001 From: suyukuoacn Date: Tue, 15 Sep 2020 11:43:20 -0700 Subject: [PATCH] fix(test-tooling): getContainerInfo methods lookup criteria Fixes #265 Signed-off-by: suyukuoacn --- .../src/main/typescript/besu/besu-test-ledger.ts | 14 +++++++++----- .../typescript/fabric/fabric-test-ledger-v1.ts | 7 ++++++- .../typescript/http-echo/http-echo-container.ts | 7 ++++++- .../main/typescript/quorum/quorum-test-ledger.ts | 7 ++++++- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/packages/cactus-test-tooling/src/main/typescript/besu/besu-test-ledger.ts b/packages/cactus-test-tooling/src/main/typescript/besu/besu-test-ledger.ts index 7f5c244234..05e3e07075 100644 --- a/packages/cactus-test-tooling/src/main/typescript/besu/besu-test-ledger.ts +++ b/packages/cactus-test-tooling/src/main/typescript/besu/besu-test-ledger.ts @@ -11,14 +11,14 @@ export interface IBesuTestLedgerConstructorOptions { containerImageVersion?: string; containerImageName?: string; rpcApiHttpPort?: number; - envVars?: string[] + envVars?: string[]; } export const BESU_TEST_LEDGER_DEFAULT_OPTIONS = Object.freeze({ containerImageVersion: "latest", containerImageName: "hyperledger/cactus-besu-all-in-one", rpcApiHttpPort: 8545, - envVars: ["BESU_NETWORK=dev"] + envVars: ["BESU_NETWORK=dev"], }); export const BESU_TEST_LEDGER_OPTIONS_JOI_SCHEMA: Joi.Schema = Joi.object().keys( @@ -42,6 +42,7 @@ export class BesuTestLedger implements ITestLedger { public readonly envVars: string[]; private container: Container | undefined; + private containerId: string | undefined; constructor(public readonly options: IBesuTestLedgerConstructorOptions = {}) { if (!options) { @@ -55,8 +56,7 @@ export class BesuTestLedger implements ITestLedger { BESU_TEST_LEDGER_DEFAULT_OPTIONS.containerImageName; this.rpcApiHttpPort = options.rpcApiHttpPort || BESU_TEST_LEDGER_DEFAULT_OPTIONS.rpcApiHttpPort; - this.envVars = - options.envVars || BESU_TEST_LEDGER_DEFAULT_OPTIONS.envVars; + this.envVars = options.envVars || BESU_TEST_LEDGER_DEFAULT_OPTIONS.envVars; this.validateConstructorOptions(); } @@ -159,6 +159,7 @@ export class BesuTestLedger implements ITestLedger { eventEmitter.once("start", async (container: Container) => { this.container = container; + this.containerId = container.id; try { await this.waitForHealthCheck(); resolve(container); @@ -220,7 +221,10 @@ export class BesuTestLedger implements ITestLedger { const image = this.getContainerImageName(); const containerInfos = await docker.listContainers({}); - const aContainerInfo = containerInfos.find((ci) => ci.Image === image); + let aContainerInfo; + if (this.containerId !== undefined) { + aContainerInfo = containerInfos.find((ci) => ci.Id === this.containerId); + } if (aContainerInfo) { return aContainerInfo; diff --git a/packages/cactus-test-tooling/src/main/typescript/fabric/fabric-test-ledger-v1.ts b/packages/cactus-test-tooling/src/main/typescript/fabric/fabric-test-ledger-v1.ts index 94bc499a15..5336b17089 100644 --- a/packages/cactus-test-tooling/src/main/typescript/fabric/fabric-test-ledger-v1.ts +++ b/packages/cactus-test-tooling/src/main/typescript/fabric/fabric-test-ledger-v1.ts @@ -40,6 +40,7 @@ export class FabricTestLedgerV1 implements ITestLedger { public readonly opsApiHttpPort: number; private container: Container | undefined; + private containerId: string | undefined; constructor( public readonly options: IFabricTestLedgerV1ConstructorOptions = {} @@ -114,6 +115,7 @@ export class FabricTestLedgerV1 implements ITestLedger { eventEmitter.once("start", async (container: Container) => { this.container = container; + this.containerId = container.id; try { await this.waitForHealthCheck(); resolve(container); @@ -175,7 +177,10 @@ export class FabricTestLedgerV1 implements ITestLedger { const image = this.getContainerImageName(); const containerInfos = await docker.listContainers({}); - const aContainerInfo = containerInfos.find((ci) => ci.Image === image); + let aContainerInfo; + if (this.containerId !== undefined) { + aContainerInfo = containerInfos.find((ci) => ci.Id === this.containerId); + } if (aContainerInfo) { return aContainerInfo; diff --git a/packages/cactus-test-tooling/src/main/typescript/http-echo/http-echo-container.ts b/packages/cactus-test-tooling/src/main/typescript/http-echo/http-echo-container.ts index fe7958ed9c..5f80c3cb30 100644 --- a/packages/cactus-test-tooling/src/main/typescript/http-echo/http-echo-container.ts +++ b/packages/cactus-test-tooling/src/main/typescript/http-echo/http-echo-container.ts @@ -32,6 +32,7 @@ export class HttpEchoContainer implements ITestLedger { public readonly httpPort: number; private container: Container | undefined; + private containerId: string | undefined; constructor( public readonly options: IHttpEchoContainerConstructorOptions = {} @@ -98,6 +99,7 @@ export class HttpEchoContainer implements ITestLedger { eventEmitter.once("start", async (container: Container) => { this.container = container; + this.containerId = container.id; const host: string = "127.0.0.1"; const hostPort = await this.getPublicHttpPort(); try { @@ -152,7 +154,10 @@ export class HttpEchoContainer implements ITestLedger { const image = this.getImageName(); const containerInfos = await docker.listContainers({}); - const aContainerInfo = containerInfos.find((ci) => ci.Image === image); + let aContainerInfo; + if (this.containerId !== undefined) { + aContainerInfo = containerInfos.find((ci) => ci.Id === this.containerId); + } if (aContainerInfo) { return aContainerInfo; diff --git a/packages/cactus-test-tooling/src/main/typescript/quorum/quorum-test-ledger.ts b/packages/cactus-test-tooling/src/main/typescript/quorum/quorum-test-ledger.ts index 7025bb2c2a..e2ef61ecf2 100644 --- a/packages/cactus-test-tooling/src/main/typescript/quorum/quorum-test-ledger.ts +++ b/packages/cactus-test-tooling/src/main/typescript/quorum/quorum-test-ledger.ts @@ -39,6 +39,7 @@ export class QuorumTestLedger implements ITestLedger { public readonly rpcApiHttpPort: number; private container: Container | undefined; + private containerId: string | undefined; constructor( public readonly options: IQuorumTestLedgerConstructorOptions = {} @@ -166,6 +167,7 @@ export class QuorumTestLedger implements ITestLedger { eventEmitter.once("start", async (container: Container) => { this.container = container; + this.containerId = container.id; try { await this.waitForHealthCheck(); resolve(container); @@ -233,7 +235,10 @@ export class QuorumTestLedger implements ITestLedger { const image = this.getContainerImageName(); const containerInfos = await docker.listContainers({}); - const aContainerInfo = containerInfos.find((ci) => ci.Image === image); + let aContainerInfo; + if (this.containerId !== undefined) { + aContainerInfo = containerInfos.find((ci) => ci.Id === this.containerId); + } if (aContainerInfo) { return aContainerInfo;