-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(test-tooling): env injenction for Besu, Fabric, Quorum AIOs
The Fabric, Quorum and Besu test ledger classes are now capable of injecting arbitrary environment variables into their containers which will help us in the future to update the supply chain app example (and other examples as well) to push their host environment variables into the containers they run internally. The hope with this is that it will make it possible for people in restricted environments (corporate firewalls/proxies) to run the example as well. Fixes #1580 Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
- Loading branch information
Showing
7 changed files
with
125 additions
and
6 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
packages/cactus-test-tooling/src/main/typescript/common/env-map-to-docker.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,19 @@ | ||
import { Checks } from "@hyperledger/cactus-common"; | ||
|
||
/** | ||
* Converts an ES6 Map of environment variables into an | ||
* array of strings which is the expected format of the Dockerode library that | ||
* we heavily use in our testing code to launch containers for infrastructure | ||
* simulation. | ||
* | ||
* @param envMap Environment variables as an ES6 map that will be converted into | ||
* an array of strings. | ||
*/ | ||
export function envMapToDocker(envMap: Map<string, unknown>): string[] { | ||
Checks.truthy(envMap, "test-tooling#envMapToDocker()"); | ||
const out = []; | ||
for (const [key, value] of envMap) { | ||
out.push(`${key}=${value}`); | ||
} | ||
return out; | ||
} |
23 changes: 23 additions & 0 deletions
23
packages/cactus-test-tooling/src/main/typescript/common/env-node-to-docker.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,23 @@ | ||
import { Checks } from "@hyperledger/cactus-common"; | ||
|
||
/** | ||
* Converts the NodeJS formatted (POJO) environment variable object into an | ||
* array of strings which is the expected format of the Dockerode library that | ||
* we heavily use in our testing code to launch containers for infrastructure | ||
* simulation. | ||
* | ||
* @param envNodeJs Environment variables in the format NodeJS provides it to | ||
* the script file that it is running. It's just a plain on Javascript object | ||
* that maps the environment variable names to values like this: | ||
* ```json | ||
* { | ||
* "MY_ENV_VAR": "SomeInterestingValueOfMyEnvVar" | ||
* } | ||
* ``` | ||
*/ | ||
export function envNodeToDocker(envNodeJs: NodeJS.ProcessEnv): string[] { | ||
Checks.truthy(envNodeJs, "test-tooling#envNodeToDocker()"); | ||
return Object.entries(envNodeJs).map((parts: [string, unknown]) => { | ||
return `${parts[0]}=${parts[1]}`; | ||
}); | ||
} |
23 changes: 23 additions & 0 deletions
23
packages/cactus-test-tooling/src/main/typescript/common/env-node-to-map.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,23 @@ | ||
import { Checks } from "@hyperledger/cactus-common"; | ||
|
||
/** | ||
* Converts the NodeJS formatted (POJO) environment variable object into an ES6 | ||
* Map object containing the same information. | ||
* | ||
* @param envNodeJs Environment variables in the format NodeJS provides it to | ||
* the script file that it is running. It's just a plain on Javascript object | ||
* that maps the environment variable names to values like this: | ||
* ```json | ||
* { | ||
* "MY_ENV_VAR": "SomeInterestingValueOfMyEnvVar" | ||
* } | ||
* ``` | ||
*/ | ||
export function envNodeToMap( | ||
envNodeJs: NodeJS.ProcessEnv, | ||
): Map<string, string> { | ||
Checks.truthy(envNodeJs, "test-tooling#envNodeToDocker()"); | ||
const map = new Map(); | ||
Object.entries(envNodeJs).forEach(([key, value]) => map.set(key, value)); | ||
return map; | ||
} |
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
50 changes: 50 additions & 0 deletions
50
...ges/cactus-test-tooling/src/test/typescript/unit/common/env-to-docker-conversions.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,50 @@ | ||
import "jest-extended"; | ||
|
||
import { envNodeToDocker } from "../../../../main/typescript/public-api"; | ||
import { envMapToDocker } from "../../../../main/typescript/public-api"; | ||
import { envNodeToMap } from "../../../../main/typescript/public-api"; | ||
|
||
describe("test-tooling#envMapToDocker()", () => { | ||
test("Empty Map", () => { | ||
expect(envMapToDocker(new Map())).toBeArrayOfSize(0); | ||
}); | ||
|
||
test("Non-empty Map", () => { | ||
const data = new Map(); | ||
data.set("X", "Y"); | ||
const out = envMapToDocker(data); | ||
expect(out).toBeArrayOfSize(1); | ||
expect(out[0]).toEqual("X=Y"); | ||
}); | ||
}); | ||
|
||
describe("test-tooling#envNodeToDocker()", () => { | ||
test("Empty POJO", () => { | ||
expect(envNodeToDocker({})).toBeArrayOfSize(0); | ||
}); | ||
|
||
test("Non-empty POJO", () => { | ||
const data = { X: "Y" }; | ||
const out = envNodeToDocker(data); | ||
expect(out).toBeArrayOfSize(1); | ||
expect(out[0]).toEqual("X=Y"); | ||
}); | ||
}); | ||
|
||
describe("test-tooling#envNodeToMap()", () => { | ||
test("Empty POJO", () => { | ||
const out = envNodeToMap({}); | ||
expect(out).toBeTruthy(); | ||
expect(out).toBeInstanceOf(Map); | ||
expect(out.size).toStrictEqual(0); | ||
}); | ||
|
||
test("Non-empty POJO", () => { | ||
const data = { X: "Y" }; | ||
const out = envNodeToMap(data); | ||
expect(out).toBeTruthy(); | ||
expect(out).toBeInstanceOf(Map); | ||
expect(out.size).toStrictEqual(1); | ||
expect(out.get("X")).toStrictEqual("Y"); | ||
}); | ||
}); |