Skip to content

Commit

Permalink
test(test-tooling): jest migrate postgres container constructor options
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Somogyvari <[email protected]>
  • Loading branch information
petermetz committed Aug 29, 2024
1 parent d509dad commit 6872ec5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2469,7 +2469,7 @@ jobs:
JEST_TEST_COVERAGE_PATH: ./code-coverage-ts/cactus-test-tooling
JEST_TEST_CODE_COVERAGE_ENABLED: true
TAPE_TEST_PATTERN: >-
--files={./packages/cactus-test-tooling/src/test/typescript/integration/besu/besu-test-ledger/constructor-validates-options.test.ts,./packages/cactus-test-tooling/src/test/typescript/integration/fabric/fabric-test-ledger-v1/constructor-validates-options.test.ts,./packages/cactus-test-tooling/src/test/typescript/integration/postgres/postgres-test-container/constructor-validates-options.test.ts,./packages/cactus-test-tooling/src/test/typescript/integration/substrate/substrate-test-ledger-constructor.test.ts,./packages/cactus-test-tooling/src/test/typescript/integration/substrate/substrate-test-ledger-multiple-concurrent.test.ts}
--files={./packages/cactus-test-tooling/src/test/typescript/integration/besu/besu-test-ledger/constructor-validates-options.test.ts,./packages/cactus-test-tooling/src/test/typescript/integration/fabric/fabric-test-ledger-v1/constructor-validates-options.test.ts,./packages/cactus-test-tooling/src/test/typescript/integration/substrate/substrate-test-ledger-constructor.test.ts,./packages/cactus-test-tooling/src/test/typescript/integration/substrate/substrate-test-ledger-multiple-concurrent.test.ts}
TAPE_TEST_RUNNER_DISABLED: false
runs-on: ubuntu-22.04
steps:
Expand Down
1 change: 0 additions & 1 deletion .taprc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ files:
- ./packages/cactus-plugin-keychain-vault/src/test/typescript/integration/cactus-keychain-vault-server.test.ts
- ./packages/cactus-plugin-keychain-vault/src/test/typescript/integration/plugin-keychain-vault.test.ts
- ./packages/cactus-plugin-keychain-vault/src/test/typescript/integration/openapi/openapi-validation.test.ts
- ./packages/cactus-test-tooling/src/test/typescript/integration/postgres/postgres-test-container/constructor-validates-options.test.ts
- ./packages/cactus-test-tooling/src/test/typescript/integration/fabric/fabric-test-ledger-v1/constructor-validates-options.test.ts
- ./packages/cactus-test-tooling/src/test/typescript/integration/substrate/substrate-test-ledger-constructor.test.ts
- ./packages/cactus-test-tooling/src/test/typescript/integration/substrate/substrate-test-ledger-multiple-concurrent.test.ts
Expand Down
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ module.exports = {
`./packages/cactus-plugin-keychain-vault/src/test/typescript/integration/cactus-keychain-vault-server.test.ts`,
`./packages/cactus-plugin-keychain-vault/src/test/typescript/integration/plugin-keychain-vault.test.ts`,
`./packages/cactus-plugin-keychain-vault/src/test/typescript/integration/openapi/openapi-validation.test.ts`,
`./packages/cactus-test-tooling/src/test/typescript/integration/postgres/postgres-test-container/constructor-validates-options.test.ts`,
`./packages/cactus-test-tooling/src/test/typescript/integration/fabric/fabric-test-ledger-v1/constructor-validates-options.test.ts`,
`./packages/cactus-test-tooling/src/test/typescript/integration/substrate/substrate-test-ledger-constructor.test.ts`,
`./packages/cactus-test-tooling/src/test/typescript/integration/substrate/substrate-test-ledger-multiple-concurrent.test.ts`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
import test, { Test } from "tape-promise/tape";
import "jest-extended";
import isPortReachable from "is-port-reachable";
import { Container } from "dockerode";
import { PostgresTestContainer } from "../../../../../main/typescript/public-api";
import { LogLevelDesc } from "@hyperledger/cactus-common";

const logLevel: LogLevelDesc = "TRACE";
const logLevel: LogLevelDesc = "INFO";

test("constructor throws if invalid input is provided", (assert: Test) => {
assert.ok(PostgresTestContainer);
assert.throws(() => new PostgresTestContainer({ imageVersion: "nope" }));
assert.end();
});

test("constructor does not throw if valid input is provided", (assert: Test) => {
assert.ok(PostgresTestContainer);
assert.doesNotThrow(() => new PostgresTestContainer());
assert.end();
});

test("starts/stops/destroys a docker container", async (assert: Test) => {
describe("PostgresTestContainer", () => {
const postgresTestContainer = new PostgresTestContainer({ logLevel });
let postgresContainer: Container;

beforeAll(async () => {
postgresContainer = await postgresTestContainer.start();
});

const postgresContainer: Container = await postgresTestContainer.start();
test.onFinish(async () => {
afterAll(async () => {
await postgresTestContainer.stop();
});

assert.ok(postgresContainer);
const ipAddress: string = await postgresTestContainer.getContainerIpAddress();
assert.ok(ipAddress);
assert.ok(ipAddress.length);
it("constructor throws if invalid input is provided", () => {
expect(PostgresTestContainer).toBeTruthy();
expect(
() => new PostgresTestContainer({ imageVersion: "nope" }),
).toThrowError();
});

const hostPort: number = await postgresTestContainer.getPostgresPort();
assert.ok(hostPort, "getRpcApiPublicPort() returns truthy OK");
assert.ok(isFinite(hostPort), "getRpcApiPublicPort() returns finite OK");
it("constructor does not throw if valid input is provided", () => {
expect(PostgresTestContainer).toBeTruthy();
expect(() => new PostgresTestContainer()).not.toThrow();
});

const isReachable = await isPortReachable(hostPort, { host: "127.0.0.1" });
assert.ok(isReachable, `HostPort ${hostPort} is reachable via 127.0.0.1`);
it("starts/stops/destroys a docker container", async () => {
expect(postgresContainer).toBeTruthy();
const ip: string = await postgresTestContainer.getContainerIpAddress();
expect(ip).toBeString();
expect(ip).not.toBeEmpty();

assert.end();
const hostPort: number = await postgresTestContainer.getPostgresPort();
expect(hostPort).toBeTruthy();
expect(hostPort).toBeFinite();

const reachabilityCheck = isPortReachable(hostPort, { host: "127.0.0.1" });
expect(reachabilityCheck).resolves.toBeTrue();
});
});

0 comments on commit 6872ec5

Please sign in to comment.