Skip to content

Commit 31cda81

Browse files
committed
refactor: go back to testcontainers
1 parent d6c4872 commit 31cda81

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@ jobs:
125125
registry: ghcr.io
126126
username: tnotheis
127127
password: ${{ secrets.GHCR_PAT_FOR_OID4VC_SERVICE_PULL }}
128-
- name: Start OpenID4VC Service
129-
run: npm run start:openid4vc
130128
- uses: actions/setup-node@v6
131129
with:
132130
node-version: current
@@ -156,8 +154,6 @@ jobs:
156154
registry: ghcr.io
157155
username: tnotheis
158156
password: ${{ secrets.GHCR_PAT_FOR_OID4VC_SERVICE_PULL }}
159-
- name: Start OpenID4VC Service
160-
run: npm run start:openid4vc
161157
- uses: actions/setup-node@v6
162158
with:
163159
node-version: current

packages/runtime/test/consumption/openid4vc.test.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
import axios, { AxiosInstance } from "axios";
2+
import path from "path";
3+
import { DockerComposeEnvironment, StartedDockerComposeEnvironment } from "testcontainers";
24
import { ConsumptionServices } from "../../src";
35
import { RuntimeServiceProvider } from "../lib";
46

57
const runtimeServiceProvider = new RuntimeServiceProvider();
68
let consumptionServices: ConsumptionServices;
7-
let oid4vcServiceBaseUrl: string;
89
let axiosInstance: AxiosInstance;
10+
let dockerComposeStack: StartedDockerComposeEnvironment | undefined;
911

1012
beforeAll(async () => {
1113
const runtimeServices = await runtimeServiceProvider.launch(1);
1214
consumptionServices = runtimeServices[0].consumption;
1315

14-
oid4vcServiceBaseUrl = process.env.OPENID4VC_SERVICE_BASEURL!;
16+
let oid4vcServiceBaseUrl = process.env.OPENID4VC_SERVICE_BASEURL!;
1517
if (!oid4vcServiceBaseUrl) {
16-
throw new Error("OPENID4VC_SERVICE_BASEURL environment variable is not set");
18+
dockerComposeStack = await startOid4VcComposeStack();
19+
const mappedPort = dockerComposeStack.getContainer("oid4vc-service-1").getMappedPort(9000);
20+
oid4vcServiceBaseUrl = `http://localhost:${mappedPort}`;
1721
}
1822

1923
axiosInstance = axios.create({
@@ -26,6 +30,7 @@ beforeAll(async () => {
2630

2731
afterAll(async () => {
2832
await runtimeServiceProvider.stop();
33+
if (dockerComposeStack) await dockerComposeStack.down();
2934
});
3035

3136
describe("OpenID4VCI and OpenID4VCP", () => {
@@ -144,3 +149,27 @@ describe("OpenID4VCI and OpenID4VCP", () => {
144149
expect(singleCredentialResult.value[0].id).toBe(firstCredentialId);
145150
}, 10000000);
146151
});
152+
153+
async function startOid4VcComposeStack() {
154+
let baseUrl = process.env.NMSHD_TEST_BASEURL ?? "http://localhost:8080";
155+
let addressGenerationHostnameOverride: string | undefined;
156+
157+
if (baseUrl.includes("localhost")) {
158+
addressGenerationHostnameOverride = "localhost";
159+
baseUrl = baseUrl.replace("localhost", "host.docker.internal");
160+
}
161+
162+
const composeFolder = path.resolve(path.join(__dirname, "..", "..", "..", "..", ".dev"));
163+
const composeStack = await new DockerComposeEnvironment(composeFolder, "compose.openid4vc.yml")
164+
.withProjectName("runtime-oid4vc-tests")
165+
.withEnvironment({
166+
// eslint-disable-next-line @typescript-eslint/naming-convention
167+
NMSHD_TEST_BASEURL: baseUrl,
168+
// eslint-disable-next-line @typescript-eslint/naming-convention
169+
NMSHD_TEST_ADDRESSGENERATIONHOSTNAMEOVERRIDE: addressGenerationHostnameOverride
170+
} as Record<string, string>)
171+
.withStartupTimeout(60000)
172+
.up();
173+
174+
return composeStack;
175+
}

0 commit comments

Comments
 (0)