Skip to content

Commit

Permalink
fix(odap-hermes): fix unresolved database config path in repositories
Browse files Browse the repository at this point in the history
Signed-off-by: André Augusto <andre.augusto@tecnico.ulisboa.pt>
  • Loading branch information
AndreAugusto11 committed Mar 11, 2024
1 parent 106a80d commit fd1f7df
Show file tree
Hide file tree
Showing 34 changed files with 216 additions and 171 deletions.
2 changes: 1 addition & 1 deletion packages/cactus-plugin-satp-hermes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"scripts": {
"build": "run-p tsc codegen",
"build-proto": "buf build --path src/main/proto --verbose",
"build:dev:backend:postbuild": "mkdir -p ./dist/lib/main/knex && cp -r ./knex/* ./dist/lib/main/knex",
"build:dev:backend:postbuild": "mkdir -p ./dist/lib/knex && cp -r ./src/knex/* ./dist/lib/knex",
"codegen": "run-p 'codegen:*'",
"codegen:openapi": "npm run generate-sdk",
"codegen:proto": "npm run generate-proto",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
development: {
client: "sqlite3",
connection: {
filename: path.resolve(__dirname, ".dev-remote.sqlite3"),
filename: path.resolve(__dirname, ".dev.remote-" + uuidv4() + ".sqlite3"),
},
migrations: {
directory: path.resolve(__dirname, "migrations"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class KnexLocalLogRepository implements ILocalLogRepository {

public constructor(config: Knex.Config | undefined) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const configFile = require("../../../../knex/knexfile.ts")[
const configFile = require("../../../knex/knexfile.ts")[
process.env.ENVIRONMENT || "development"
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class KnexRemoteLogRepository implements IRemoteLogRepository {
// simulating a remote log storage
public constructor(config: Knex.Config | undefined) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const configFile = require("../../../../knex/knexfile-remote.ts")[
const configFile = require("../../../knex/knexfile-remote.ts")[
process.env.ENVIRONMENT || "development"
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,12 +547,16 @@ beforeAll(async () => {
pluginRecipientGateway = new BesuSATPGateway(serverGatewayPluginOptions);

expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined();
expect(
pluginRecipientGateway.localRepository?.database,
).not.toBeUndefined();

expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined();

expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined();
expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined();

await pluginSourceGateway.localRepository?.reset();
await pluginRecipientGateway.localRepository?.reset();

await pluginSourceGateway.remoteRepository?.reset();
await pluginRecipientGateway.remoteRepository?.reset();
}
{
// Server Gateway configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,12 +544,16 @@ beforeAll(async () => {
pluginRecipientGateway = new BesuSATPGateway(serverGatewayPluginOptions);

expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined();
expect(
pluginRecipientGateway.localRepository?.database,
).not.toBeUndefined();

expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined();

expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined();
expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined();

await pluginSourceGateway.localRepository?.reset();
await pluginRecipientGateway.localRepository?.reset();

await pluginSourceGateway.remoteRepository?.reset();
await pluginRecipientGateway.remoteRepository?.reset();
}
{
// Server Gateway configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,12 +545,16 @@ beforeAll(async () => {
pluginRecipientGateway = new BesuSATPGateway(serverGatewayPluginOptions);

expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined();
expect(
pluginRecipientGateway.localRepository?.database,
).not.toBeUndefined();

expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined();

expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined();
expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined();

await pluginSourceGateway.localRepository?.reset();
await pluginRecipientGateway.localRepository?.reset();

await pluginSourceGateway.remoteRepository?.reset();
await pluginRecipientGateway.remoteRepository?.reset();
}
{
// Server Gateway configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ beforeAll(async () => {

pluginRecipientGateway = new BesuSATPGateway(serverGatewayPluginOptions);

expect(
pluginRecipientGateway.localRepository?.database,
).not.toBeUndefined();

expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined();
expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined();

await pluginRecipientGateway.localRepository?.reset();
await pluginRecipientGateway.remoteRepository?.reset();

await pluginRecipientGateway.registerWebServices(serverExpressApp);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,16 @@ beforeAll(async () => {
pluginRecipientGateway = new BesuSATPGateway(serverGatewayPluginOptions);

expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined();
expect(
pluginRecipientGateway.localRepository?.database,
).not.toBeUndefined();

expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined();

expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined();
expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined();

await pluginSourceGateway.localRepository?.reset();
await pluginRecipientGateway.localRepository?.reset();

await pluginSourceGateway.remoteRepository?.reset();
await pluginRecipientGateway.remoteRepository?.reset();
}
{
// Server Gateway configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ test("runs ODAP between two gateways via openApi", async () => {

expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined();
expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined();

expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined();
expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined();

await pluginSourceGateway.localRepository?.reset();
await pluginRecipientGateway.localRepository?.reset();

await pluginSourceGateway.remoteRepository?.reset();
await pluginRecipientGateway.remoteRepository?.reset();

let serverGatewayApiHost: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,14 @@ beforeAll(async () => {
pluginRecipientGateway.localRepository?.database,
).not.toBeUndefined();

expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined();
expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined();

await pluginSourceGateway.localRepository?.reset();
await pluginRecipientGateway.localRepository?.reset();

await pluginSourceGateway.remoteRepository?.reset();
await pluginRecipientGateway.remoteRepository?.reset();
}
{
// Server Gateway configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@ test("successful run ODAP instance", async () => {

expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined();
expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined();

expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined();
expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined();

await pluginSourceGateway.localRepository?.reset();
await pluginRecipientGateway.localRepository?.reset();

await pluginSourceGateway.remoteRepository?.reset();
await pluginRecipientGateway.remoteRepository?.reset();

const dummyPath = { apiHost: "dummyPath" };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,12 +547,16 @@ beforeEach(async () => {
pluginRecipientGateway = new BesuSATPGateway(serverGatewayPluginOptions);

expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined();
expect(
pluginRecipientGateway.localRepository?.database,
).not.toBeUndefined();

expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined();

expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined();
expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined();

await pluginSourceGateway.localRepository?.reset();
await pluginRecipientGateway.localRepository?.reset();

await pluginSourceGateway.remoteRepository?.reset();
await pluginRecipientGateway.remoteRepository?.reset();
}
{
// Server Gateway configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ beforeAll(async () => {

pluginRecipientGateway = new BesuSATPGateway(serverGatewayPluginOptions);

expect(
pluginRecipientGateway.localRepository?.database,
).not.toBeUndefined();
expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined();
expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined();

await pluginRecipientGateway.localRepository?.reset();
await pluginRecipientGateway.remoteRepository?.reset();

await pluginRecipientGateway.registerWebServices(serverExpressApp);
}
Expand Down Expand Up @@ -123,11 +123,11 @@ beforeAll(async () => {

pluginSourceGateway = new FabricSATPGateway(clientGatewayPluginOptions);

if (pluginSourceGateway.localRepository?.database == undefined) {
throw new Error("Database is not correctly initialized");
}
expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined();
expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined();

await pluginSourceGateway.localRepository?.reset();
await pluginSourceGateway.remoteRepository?.reset();

await pluginSourceGateway.registerWebServices(clientExpressApp);

Expand Down Expand Up @@ -218,10 +218,10 @@ test("server gateway crashes after transfer initiation flow", async () => {
});

afterAll(async () => {
pluginSourceGateway.localRepository?.destroy();
pluginRecipientGateway.localRepository?.destroy();
pluginSourceGateway.remoteRepository?.destroy();
pluginRecipientGateway.remoteRepository?.destroy();
await pluginSourceGateway.localRepository?.destroy();
await pluginRecipientGateway.localRepository?.destroy();
await pluginSourceGateway.remoteRepository?.destroy();
await pluginRecipientGateway.remoteRepository?.destroy();

await Servers.shutdown(sourceGatewayServer);
await Servers.shutdown(recipientGatewayserver);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
import { v4 as uuidv4 } from "uuid";

export const knexClientConnection = {
client: "sqlite3",
connection: {
filename: "./packages/cactus-plugin-satp-hermes/knex/.dev.client.sqlite3",
filename: "./packages/cactus-plugin-satp-hermes/src/knex/.dev.client-" + uuidv4() + ".sqlite3",
},
migrations: {
directory: "./packages/cactus-plugin-satp-hermes/knex/migrations",
directory: "./packages/cactus-plugin-satp-hermes/src/knex/migrations",
},
useNullAsDefault: true,
};

export const knexServerConnection = {
client: "sqlite3",
connection: {
filename: "./packages/cactus-plugin-satp-hermes/knex/.dev.server.sqlite3",
filename: "./packages/cactus-plugin-satp-hermes/src/knex/.dev.server-" + uuidv4() + ".sqlite3",
},
migrations: {
directory: "./packages/cactus-plugin-satp-hermes/knex/migrations",
directory: "./packages/cactus-plugin-satp-hermes/src/knex/migrations",
},
useNullAsDefault: true,
};

export const knexRemoteConnection = {
client: "sqlite3",
connection: {
filename: "./packages/cactus-plugin-satp-hermes/knex/.dev.remote.sqlite3",
filename: "./packages/cactus-plugin-satp-hermes/src/knex/.dev.remote-" + uuidv4() + ".sqlite3",
},
migrations: {
directory: "./packages/cactus-plugin-satp-hermes/knex/migrations",
directory: "./packages/cactus-plugin-satp-hermes/src/knex/migrations",
},
useNullAsDefault: true,
};
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@ beforeEach(async () => {
pluginSourceGateway = new FabricSATPGateway(sourceGatewayConstructor);
pluginRecipientGateway = new BesuSATPGateway(recipientGatewayConstructor);

if (
pluginSourceGateway.localRepository?.database == undefined ||
pluginRecipientGateway.localRepository?.database == undefined
) {
throw new Error("Database is not correctly initialized");
}
expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined();
expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined();

expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined();
expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined();

await pluginSourceGateway.localRepository?.reset();
await pluginRecipientGateway.localRepository?.reset();

await pluginSourceGateway.remoteRepository?.reset();
await pluginRecipientGateway.remoteRepository?.reset();

sequenceNumber = randomInt(100);
sessionID = uuidv4();
Expand Down Expand Up @@ -88,16 +90,6 @@ beforeEach(async () => {
operation: "create",
data: COMMIT_ACK_CLAIM,
});

if (
pluginSourceGateway.localRepository?.database == undefined ||
pluginRecipientGateway.localRepository?.database == undefined
) {
throw new Error("Database is not correctly initialized");
}

await pluginSourceGateway.localRepository?.reset();
await pluginRecipientGateway.localRepository?.reset();
});

afterEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ beforeEach(async () => {
pluginSourceGateway = new FabricSATPGateway(sourceGatewayConstructor);
pluginRecipientGateway = new BesuSATPGateway(recipientGatewayConstructor);

if (
pluginSourceGateway.localRepository?.database == undefined ||
pluginRecipientGateway.localRepository?.database == undefined
) {
throw new Error("Database is not correctly initialized");
}
expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined();
expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined();

expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined();
expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined();

await pluginSourceGateway.localRepository?.reset();
await pluginRecipientGateway.localRepository?.reset();

await pluginSourceGateway.remoteRepository?.reset();
await pluginRecipientGateway.remoteRepository?.reset();

sequenceNumber = randomInt(100);
sessionID = uuidV4();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,17 @@ beforeEach(async () => {
pluginSourceGateway = new FabricSATPGateway(sourceGatewayConstructor);
pluginRecipientGateway = new BesuSATPGateway(recipientGatewayConstructor);

if (
pluginSourceGateway.localRepository?.database == undefined ||
pluginRecipientGateway.localRepository?.database == undefined
) {
throw new Error("Database is not correctly initialized");
}
expect(pluginSourceGateway.localRepository?.database).not.toBeUndefined();
expect(pluginRecipientGateway.localRepository?.database).not.toBeUndefined();

expect(pluginSourceGateway.remoteRepository?.database).not.toBeUndefined();
expect(pluginRecipientGateway.remoteRepository?.database).not.toBeUndefined();

await pluginSourceGateway.localRepository?.reset();
await pluginRecipientGateway.localRepository?.reset();

await pluginSourceGateway.remoteRepository?.reset();
await pluginRecipientGateway.remoteRepository?.reset();

sequenceNumber = randomInt(100);
sessionID = uuidV4();
Expand Down
Loading

0 comments on commit fd1f7df

Please sign in to comment.