Skip to content

Commit

Permalink
fix(test-tooling): getContainerInfo methods lookup criteria
Browse files Browse the repository at this point in the history
Fixes #265

Signed-off-by: suyukuoacn <su-yu.kuo@accenture.com>
  • Loading branch information
suyukuoacn authored and petermetz committed Oct 6, 2020
1 parent e591aab commit 7456967
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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) {
Expand All @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7456967

Please sign in to comment.