Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 3 additions & 11 deletions apps/auth-cron/tests/configurations/vitest.globalSetup.mts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import path from 'node:path';
import type { TestProject } from 'vitest/node';
import {
createMinioContainer,
MINIO_PORT,
createS3Client,
createAndProvideTempDir,
removeTempDir,
mergeTestConfig,
ensureBucketExists,
} from 'test-utils';
import { createS3Container, S3_PORT, createS3Client, createAndProvideTempDir, removeTempDir, mergeTestConfig, ensureBucketExists } from 'test-utils';
import { getConfig, initConfig } from '@src/config.js';

export async function setup(project: TestProject): Promise<void> {
Expand All @@ -17,12 +9,12 @@ export async function setup(project: TestProject): Promise<void> {
const configInstance = getConfig();
const cronOptions = configInstance.get('cron.np');

const container = await createMinioContainer({
const container = await createS3Container({
username: cronOptions?.s3.accessKeyId as string,
password: cronOptions?.s3.secretAccessKey as string,
});

const endpoint = `http://${container.getHost()}:${container.getMappedPort(MINIO_PORT)}`;
const endpoint = `http://${container.getHost()}:${container.getMappedPort(S3_PORT)}`;

await mergeTestConfig(path.join(__dirname, '../../config'), { 'cron.np.s3.endpoint': endpoint, 'cron.prod.s3.endpoint': endpoint });

Expand Down
2 changes: 1 addition & 1 deletion packages/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"@faker-js/faker": "catalog:",
"@map-colonies/auth-core": "workspace:^",
"@map-colonies/schemas": "catalog:",
"@testcontainers/minio": "~11.14.0",
"@testcontainers/postgresql": "^11.14.0",
"testcontainers": "^11.14.0",
"lodash": "catalog:",
"drizzle-orm": "catalog:",
"pg": "catalog:"
Expand Down
25 changes: 17 additions & 8 deletions packages/test-utils/src/containers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PostgreSqlContainer, type StartedPostgreSqlContainer } from '@testcontainers/postgresql';
import { MinioContainer, type StartedMinioContainer } from '@testcontainers/minio';
import { GenericContainer, Wait, type StartedTestContainer } from 'testcontainers';

const POSTGRES_IMAGE = 'postgres:15';
const MINIO_IMAGE = 'minio/minio:latest';
const SEAWEEDFS_IMAGE = 'chrislusf/seaweedfs:4.47';

export const PG_PORT = 5432;

Expand All @@ -20,14 +20,23 @@ export async function createPostgresContainer(options: {
return container.withUsername(options.username).withDatabase(options.database).withPassword(options.password).start();
}

export const MINIO_PORT = 9000;

export async function createMinioContainer(options: { username: string; password: string }): Promise<StartedMinioContainer> {
const container = new MinioContainer(MINIO_IMAGE);
export const S3_PORT = 8333;
export const S3_UI_PORT = 8888;

export async function createS3Container(options: { username: string; password: string }): Promise<StartedTestContainer> {
const container = new GenericContainer(SEAWEEDFS_IMAGE)
.withExposedPorts(S3_PORT, S3_UI_PORT)
.withEnvironment({
/* eslint-disable @typescript-eslint/naming-convention */
AWS_ACCESS_KEY_ID: options.username,
AWS_SECRET_ACCESS_KEY: options.password,
S3_BUCKET: 'test-bucket',
/* eslint-enable @typescript-eslint/naming-convention */
})
.withWaitStrategy(Wait.forListeningPorts());

if (process.env.CI === undefined) {
container.withReuse();
}

return container.withUsername(options.username).withPassword(options.password).start();
return container.start();
}
19 changes: 4 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading