mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 05:25:40 +09:00
refactor(schema): simplify validation and OpenAPI generation (#2709)
This commit is contained in:
1 parent
4bc5593f9f
commit
de1fd95a99
510 files changed
+29494
-36131
No files matched your search
@@ -1,38 +1,28 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {readFileSync} from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import {describe, expect, test} from 'vitest';
|
||||
|
||||
const SELF_HOSTING = path.join(fileURLToPath(new URL('../../../../', import.meta.url)), 'deploy/self-hosting');
|
||||
|
||||
const compose = readFileSync(path.join(SELF_HOSTING, 'docker-compose.yml'), 'utf8');
|
||||
|
||||
const serviceBlock = (name: string): string => {
|
||||
const start = compose.indexOf(`\n ${name}:\n`);
|
||||
if (start === -1) {
|
||||
throw new Error(`docker-compose.yml has no ${name} service`);
|
||||
}
|
||||
const rest = compose.slice(start + 1);
|
||||
const next = rest.slice(1).search(/\n {2}[a-z][a-z0-9_-]*:\n/u);
|
||||
return next === -1 ? rest : rest.slice(0, next + 1);
|
||||
};
|
||||
|
||||
const sharedEnv = compose.slice(compose.indexOf('x-fluxer-env: &fluxer-env'), compose.indexOf('\nx-fluxer-service:'));
|
||||
import {serviceEnvironment, serviceNames, sharedEnvironment} from './SelfHostingCompose';
|
||||
|
||||
describe('the shipped compose stack wires every service it starts', () => {
|
||||
test('no service sizes a pool for a connection it cannot make', () => {
|
||||
for (const [, name] of compose.matchAll(/\n {2}([a-z][a-z0-9_-]*):\n/gu)) {
|
||||
const block = serviceBlock(name);
|
||||
if (block.includes('FLUXER_POSTGRES_MAX_CONNECTIONS')) {
|
||||
expect(block).toMatch(/<<: \*fluxer-(postgres-)?env/u);
|
||||
}
|
||||
const pooledServices = serviceNames.filter((name) => 'FLUXER_POSTGRES_MAX_CONNECTIONS' in serviceEnvironment(name));
|
||||
expect(pooledServices.length).toBeGreaterThan(0);
|
||||
for (const name of pooledServices) {
|
||||
expect(serviceEnvironment(name), name).toMatchObject({
|
||||
FLUXER_DATABASE_BACKEND: 'postgres',
|
||||
FLUXER_POSTGRES_HOST: expect.stringMatching(/\S/u),
|
||||
FLUXER_POSTGRES_PORT: expect.stringMatching(/\S/u),
|
||||
FLUXER_POSTGRES_DATABASE: expect.stringMatching(/\S/u),
|
||||
FLUXER_POSTGRES_USERNAME: expect.stringMatching(/\S/u),
|
||||
FLUXER_POSTGRES_PASSWORD: expect.stringMatching(/\S/u),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test('the shared block sets the client-IP trust the merged services read', () => {
|
||||
expect(sharedEnv).toContain('FLUXER_TRUST_CLIENT_IP_HEADER: "${FLUXER_TRUST_CLIENT_IP_HEADER:-true}"');
|
||||
expect(sharedEnv).toContain('FLUXER_CLIENT_IP_HEADER_NAME: ${FLUXER_CLIENT_IP_HEADER_NAME:-x-forwarded-for}');
|
||||
expect(sharedEnvironment).toMatchObject({
|
||||
FLUXER_TRUST_CLIENT_IP_HEADER: `\${FLUXER_TRUST_CLIENT_IP_HEADER:-true}`,
|
||||
FLUXER_CLIENT_IP_HEADER_NAME: `\${FLUXER_CLIENT_IP_HEADER_NAME:-x-forwarded-for}`,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user