parent
c0337f141b
commit
a4ba79ae69
|
@ -18,10 +18,11 @@ const test = base.extend<{
|
|||
testRoom: { roomId: string; name: string };
|
||||
joinedBot: Bot;
|
||||
}>({
|
||||
slidingSyncProxy: async ({ network, postgres, page, homeserver }, use, testInfo) => {
|
||||
slidingSyncProxy: async ({ logger, network, postgres, page, homeserver }, use, testInfo) => {
|
||||
const container = await new GenericContainer("ghcr.io/matrix-org/sliding-sync:v0.99.3")
|
||||
.withNetwork(network)
|
||||
.withExposedPorts(8008)
|
||||
.withLogConsumer(logger.getConsumer("sliding-sync-proxy"))
|
||||
.withEnvironment({
|
||||
SYNCV3_SECRET: "bwahahaha",
|
||||
SYNCV3_DB: `user=postgres dbname=postgres password=${postgres.getPassword()} host=${postgres.getHost()} sslmode=disable`,
|
||||
|
|
|
@ -12,8 +12,11 @@ import { PostgreSqlContainer, StartedPostgreSqlContainer } from "@testcontainers
|
|||
|
||||
import { StartedSynapseContainer, SynapseConfigOptions, SynapseContainer } from "./testcontainers/synapse.ts";
|
||||
import { MatrixAuthenticationServiceContainer } from "./testcontainers/mas.ts";
|
||||
import { ContainerLogger } from "./testcontainers/utils.ts";
|
||||
|
||||
export interface Services {
|
||||
logger: ContainerLogger;
|
||||
|
||||
network: StartedNetwork;
|
||||
postgres: StartedPostgreSqlContainer;
|
||||
|
||||
|
@ -26,18 +29,24 @@ export interface Services {
|
|||
mas: StartedTestContainer;
|
||||
}
|
||||
|
||||
// TODO logs
|
||||
export const test = base.extend<Services>({
|
||||
// eslint-disable-next-line no-empty-pattern
|
||||
logger: async ({}, use, testInfo) => {
|
||||
const logger = new ContainerLogger();
|
||||
await use(logger);
|
||||
await logger.testFinished(testInfo);
|
||||
},
|
||||
// eslint-disable-next-line no-empty-pattern
|
||||
network: async ({}, use) => {
|
||||
const network = await new Network().start();
|
||||
await use(network);
|
||||
await network.stop();
|
||||
},
|
||||
postgres: async ({ network }, use) => {
|
||||
postgres: async ({ logger, network }, use) => {
|
||||
const container = await new PostgreSqlContainer()
|
||||
.withNetwork(network)
|
||||
.withNetworkAliases("postgres")
|
||||
.withLogConsumer(logger.getConsumer("postgres"))
|
||||
.withTmpFs({
|
||||
"/dev/shm/pgdata/data": "",
|
||||
})
|
||||
|
@ -59,11 +68,12 @@ export const test = base.extend<Services>({
|
|||
await container.stop();
|
||||
},
|
||||
|
||||
mailhog: async ({ network }, use) => {
|
||||
mailhog: async ({ logger, network }, use) => {
|
||||
const container = await new GenericContainer("mailhog/mailhog:latest")
|
||||
.withNetwork(network)
|
||||
.withNetworkAliases("mailhog")
|
||||
.withExposedPorts(8025)
|
||||
.withLogConsumer(logger.getConsumer("mailhog"))
|
||||
.withWaitStrategy(Wait.forListeningPorts())
|
||||
.start();
|
||||
await use(container);
|
||||
|
@ -78,20 +88,22 @@ export const test = base.extend<Services>({
|
|||
const container = new SynapseContainer(request);
|
||||
await use(container);
|
||||
},
|
||||
homeserver: async ({ network, _homeserver: homeserver, synapseConfigOptions }, use) => {
|
||||
homeserver: async ({ logger, network, _homeserver: homeserver, synapseConfigOptions }, use) => {
|
||||
const container = await homeserver
|
||||
.withNetwork(network)
|
||||
.withNetworkAliases("homeserver")
|
||||
.withLogConsumer(logger.getConsumer("synapse"))
|
||||
.withConfig(synapseConfigOptions)
|
||||
.start();
|
||||
|
||||
await use(container);
|
||||
await container.stop();
|
||||
},
|
||||
mas: async ({ network }, use) => {
|
||||
mas: async ({ logger, network }, use) => {
|
||||
const container = await new MatrixAuthenticationServiceContainer()
|
||||
.withNetwork(network)
|
||||
.withNetworkAliases("mas")
|
||||
.withLogConsumer(logger.getConsumer("mas"))
|
||||
.withConfig({
|
||||
clients: [
|
||||
{
|
||||
|
|
|
@ -94,7 +94,7 @@ const DEFAULT_CONFIG = {
|
|||
burst_count: 10000,
|
||||
},
|
||||
},
|
||||
media_store_path: "/media",
|
||||
media_store_path: "/data/media_store",
|
||||
max_upload_size: "50M",
|
||||
max_image_pixels: "32M",
|
||||
dynamic_thumbnails: false,
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
Copyright 2024 New Vector Ltd.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { TestInfo } from "@playwright/test";
|
||||
import { Readable } from "stream";
|
||||
|
||||
export class ContainerLogger {
|
||||
private logs: Record<string, string> = {};
|
||||
|
||||
public getConsumer(container: string) {
|
||||
this.logs[container] = "";
|
||||
return (stream: Readable) => {
|
||||
stream.on("data", (chunk) => {
|
||||
this.logs[container] += chunk.toString();
|
||||
});
|
||||
stream.on("err", (chunk) => {
|
||||
this.logs[container] += "ERR " + chunk.toString();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
public async testFinished(testInfo: TestInfo) {
|
||||
if (testInfo.status !== "passed") {
|
||||
for (const container in this.logs) {
|
||||
await testInfo.attach(container, {
|
||||
body: this.logs[container],
|
||||
contentType: "text/plain",
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue