Files
baiyue-firstleg/scripts/container-logging-contract.test.mjs
T
2026-09-29 18:47:37 +08:00

71 lines
2.7 KiB
JavaScript

import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { test } from 'node:test';
const applicationConfigs = [
'auth/src/main/resources/application.yml',
'audit-service/src/main/resources/application.yml',
'file/src/main/resources/application.yml',
'finance/src/main/resources/application.yml',
'firstleg/src/main/resources/application.yml',
'gateway/src/main/resources/application.yml',
'iam/src/main/resources/application.yml',
'integration-service/src/main/resources/application.yml',
'lastleg-service/src/main/resources/application.yml',
'order/src/main/resources/application.yml',
'print/src/main/resources/application.yml',
'warehouse/src/main/resources/application.yml',
'warehouse-overseas-service/src/main/resources/application.yml',
'config/nacos/test/baiyue-common.yml',
];
const composeFiles = [
'deploy/docker-compose.yml',
];
const infrastructureComposeFiles = [
['deploy/docker-compose.rocketmq.yml', 3],
['docker-compose-infra.yml', 3],
];
test('deployable applications log only to stdout and stderr', () => {
for (const path of applicationConfigs) {
const source = readFileSync(path, 'utf8');
assert.doesNotMatch(source, /LOG_PATH|LOGGING_FILE_NAME|LOGGING_ROLLING/, path);
}
});
test('Compose uses one bounded BaoTa-compatible log stream without application log mounts', () => {
for (const path of composeFiles) {
const source = readFileSync(path, 'utf8');
assert.match(source, /driver:\s+\$\{DOCKER_LOG_DRIVER:-json-file\}/, path);
assert.match(source, /DOCKER_LOG_MAX_SIZE/, path);
assert.match(source, /DOCKER_LOG_MAX_FILE/, path);
assert.doesNotMatch(source, /LOG_PATH|LOG_ROOT|\/app\/logs/, path);
}
const domesticCompose = readFileSync(composeFiles[0], 'utf8');
assert.match(domesticCompose, /FILE_UPLOADS_HOST_DIR[^\n]+:\/data\/files/);
});
test('runtime image does not prepare an application log directory', () => {
const dockerfile = readFileSync('deploy/docker/Dockerfile', 'utf8');
assert.doesNotMatch(dockerfile, /\/app\/logs/);
});
test('infrastructure containers also use bounded BaoTa-compatible logs', () => {
for (const [path, expectedServiceCount] of infrastructureComposeFiles) {
const source = readFileSync(path, 'utf8');
assert.match(source, /x-bounded-logging:\s+&bounded-logging/, path);
assert.match(source, /driver:\s+\$\{DOCKER_LOG_DRIVER:-json-file\}/, path);
assert.match(source, /DOCKER_LOG_MAX_SIZE/, path);
assert.match(source, /DOCKER_LOG_MAX_FILE/, path);
assert.equal(
source.match(/logging:\s+\*bounded-logging/g)?.length,
expectedServiceCount,
path,
);
assert.doesNotMatch(source, /driver:\s+local/, path);
}
});