Files
client-web/src/deployment/blueGreenDeployment.test.mjs
T

25 lines
1.2 KiB
JavaScript

import assert from 'node:assert/strict'
import { readFile } from 'node:fs/promises'
import test from 'node:test'
const script = (await readFile(new URL('../../scripts/deploy-production.sh', import.meta.url), 'utf8'))
.replaceAll('\r\n', '\n')
const compose = (await readFile(new URL('../../docker-compose.production.yml', import.meta.url), 'utf8'))
.replaceAll('\r\n', '\n')
test('client production deployment switches healthy blue-green slots atomically', () => {
const start = script.indexOf('compose run -d --no-deps --name "$candidate"')
const health = script.indexOf('docker exec "$candidate" wget')
const nginx = script.indexOf('nginx -t || ! nginx -s reload')
const stop = script.indexOf('docker stop --time 30 "$active_container"')
assert.ok(start >= 0 && start < health && health < nginx && nginx < stop)
assert.match(script, /target_port=\$\(\(base_port \+ 10000\)\)/)
assert.match(script, /cp -f "\$backup" "\$nginx_config"/)
})
test('client uses stable active gateway aliases on the routing network', () => {
assert.match(compose, /API_UPSTREAM: "http:\/\/gateway-active:9000"/)
assert.match(compose, /OVERSEAS_API_UPSTREAM: "http:\/\/gateway-overseas-active:9300"/)
assert.match(compose, /name: firstleg-production-routing/)
})