Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/modules/mockserver.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ npm install @testcontainers/mockserver --save-dev
<!--codeinclude-->
[Start container:](../../packages/modules/mockserver/src/mockserver-container.test.ts) inside_block:startContainer
<!--/codeinclude-->

MockServer includes built-in TLS support. To obtain an HTTPS URL, use the `getSecureUrl` method. Keep in mind that MockServer uses a self-signed certificate.

<!--codeinclude-->
[Using TLS:](../../packages/modules/mockserver/src/mockserver-container.test.ts) inside_block:httpsRequests
<!--/codeinclude-->
35 changes: 35 additions & 0 deletions packages/modules/mockserver/src/mockserver-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,39 @@
expect(response.text).toBe("bar");
});
// }

Check failure on line 34 in packages/modules/mockserver/src/mockserver-container.test.ts

View workflow job for this annotation

GitHub Actions / Lint (mockserver)

Delete `··`
it("should return an https url", async () => {
const container = await new MockserverContainer(IMAGE).start();
const secureUrl = container.getSecureUrl()

Check failure on line 37 in packages/modules/mockserver/src/mockserver-container.test.ts

View workflow job for this annotation

GitHub Actions / Lint (mockserver)

Insert `;`
await container.stop()

Check failure on line 38 in packages/modules/mockserver/src/mockserver-container.test.ts

View workflow job for this annotation

GitHub Actions / Lint (mockserver)

Insert `;`
expect(secureUrl.startsWith("https://")).to.equal(true, `${secureUrl} does not start with https://`)

Check failure on line 39 in packages/modules/mockserver/src/mockserver-container.test.ts

View workflow job for this annotation

GitHub Actions / Lint (mockserver)

Insert `;`
})

Check failure on line 40 in packages/modules/mockserver/src/mockserver-container.test.ts

View workflow job for this annotation

GitHub Actions / Lint (mockserver)

Insert `;`

// httpsRequests {
it("should respond to https requests", async () => {
const container = await new MockserverContainer(IMAGE).start();
const client = mockServerClient(container.getHost(), container.getMockserverPort());

await client.mockAnyResponse({
httpRequest: {
method: "GET",
path: "/foo",
},
httpResponse: {
body: {
string: "bar",
},
statusCode: 200,
},
});

const secureUrl = container.getSecureUrl()

Check failure on line 60 in packages/modules/mockserver/src/mockserver-container.test.ts

View workflow job for this annotation

GitHub Actions / Lint (mockserver)

Insert `;`
const response = await superagent.get(`${secureUrl}/foo`).disableTLSCerts();

expect(response.statusCode).toBe(200);
expect(response.text).toBe("bar");

await container.stop()

Check failure on line 66 in packages/modules/mockserver/src/mockserver-container.test.ts

View workflow job for this annotation

GitHub Actions / Lint (mockserver)

Insert `;`
})

Check failure on line 67 in packages/modules/mockserver/src/mockserver-container.test.ts

View workflow job for this annotation

GitHub Actions / Lint (mockserver)

Insert `;`
// }
});
4 changes: 4 additions & 0 deletions packages/modules/mockserver/src/mockserver-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
getUrl(): string {
return `http://${this.getHost()}:${this.getFirstMappedPort()}`;
}

getSecureUrl(): string {
return `https://${this.getHost()}:${this.getFirstMappedPort()}`

Check failure on line 13 in packages/modules/mockserver/src/mockserver-container.ts

View workflow job for this annotation

GitHub Actions / Lint (mockserver)

Insert `;`
}
}

const MOCKSERVER_PORT = 1080;
Expand Down
Loading