Skip to content

Commit

Permalink
Wipe mailhog between test runs
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
  • Loading branch information
t3chguy committed Jan 10, 2025
1 parent ad0b86c commit 6a62ae5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
25 changes: 12 additions & 13 deletions playwright/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,26 @@ import { SynapseConfigOptions, SynapseContainer } from "./testcontainers/synapse
import { ContainerLogger } from "./testcontainers/utils.ts";
import { StartedMatrixAuthenticationServiceContainer } from "./testcontainers/mas.ts";
import { HomeserverContainer, StartedHomeserverContainer } from "./testcontainers/HomeserverContainer.ts";
import { MailhogContainer, StartedMailhogContainer } from "./testcontainers/mailhog.ts";

interface TestFixtures {
mailhogClient: mailhog.API;
}

export interface Services {
logger: ContainerLogger;

network: StartedNetwork;
postgres: StartedPostgreSqlContainer;

mailhog: StartedTestContainer;
mailhogClient: mailhog.API;
mailhog: StartedMailhogContainer;

synapseConfigOptions: SynapseConfigOptions;
_homeserver: HomeserverContainer<any>;
homeserver: StartedHomeserverContainer;
mas?: StartedMatrixAuthenticationServiceContainer;
}

export const test = base.extend<{}, Services>({
export const test = base.extend<TestFixtures, Services>({
logger: [
// eslint-disable-next-line no-empty-pattern
async ({}, use) => {
Expand Down Expand Up @@ -79,24 +82,20 @@ export const test = base.extend<{}, Services>({

mailhog: [
async ({ logger, network }, use) => {
const container = await new GenericContainer("mailhog/mailhog:latest")
const container = await new MailhogContainer()
.withNetwork(network)
.withNetworkAliases("mailhog")
.withExposedPorts(8025)
.withLogConsumer(logger.getConsumer("mailhog"))
.withWaitStrategy(Wait.forListeningPorts())
.start();
await use(container);
await container.stop();
},
{ scope: "worker" },
],
mailhogClient: [
async ({ mailhog: container }, use) => {
await use(mailhog({ host: container.getHost(), port: container.getMappedPort(8025) }));
},
{ scope: "worker" },
],
mailhogClient: async ({ mailhog: container }, use) => {
await use(container.client);
await container.client.deleteAll();
},

synapseConfigOptions: [{}, { option: true, scope: "worker" }],
_homeserver: [
Expand Down
30 changes: 30 additions & 0 deletions playwright/testcontainers/mailhog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Copyright 2024 New Vector Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/

import { AbstractStartedContainer, GenericContainer, StartedTestContainer, Wait } from "testcontainers";
import mailhog from "mailhog";

export class MailhogContainer extends GenericContainer {
constructor() {
super("mailhog/mailhog:latest");

this.withExposedPorts(8025).withWaitStrategy(Wait.forListeningPorts());
}

public override async start(): Promise<StartedMailhogContainer> {
return new StartedMailhogContainer(await super.start());
}
}

export class StartedMailhogContainer extends AbstractStartedContainer {
public readonly client: mailhog.API;

constructor(container: StartedTestContainer) {
super(container);
this.client = mailhog({ host: container.getHost(), port: container.getMappedPort(8025) });
}
}

0 comments on commit 6a62ae5

Please sign in to comment.