/** * The simulator reaches BOTH generated compose files, or neither. * * Wiring a simulator into one generator and not the other is the standard way * to produce something that works in exactly half the suites — and the half it * fails in is whichever one nobody ran first. These tests are cheap precisely * because that failure is expensive. */ import { describe, expect, test } from 'bun:test'; import { generateComposeYaml, generateTestComposeYaml } from './docker-compose-generator'; import { PROXMOX_SIM_IP } from './simulator-ips'; import type { NetworkConfig } from './types'; const config = (overrides: Partial = {}): NetworkConfig => ({ topology: 'default', dmzMachines: [], appMachines: [], secureMachines: [], internalMachines: [], secureMgmtMachines: [], domain: 'iamtheinternet.org', ddnsPassword: 'test123', verifyRouting: false, managementVolumes: [], dhcpClient: false, signalCli: false, signalSim: false, signalRelease: false, ...overrides, }); const GENERATORS: Array<[string, (c: NetworkConfig) => string]> = [ ['generateTestComposeYaml', (c) => generateTestComposeYaml(c)], ['generateComposeYaml', (c) => generateComposeYaml(c)], ]; describe.each(GENERATORS)('%s', (_name, generate) => { test('omits the simulator entirely when it is not asked for', () => { // Every existing suite deploys onto the machine pool. None of them should // pay for a container they do not use. expect(generate(config())).not.toContain('proxmox-sim'); }); test('emits the simulator when enabled', () => { expect(generate(config({ proxmoxSim: true }))).toContain('proxmox-sim'); }); test('puts it on secure-mgmt at the address celilo will be pointed at', () => { // secure-mgmt with celilo-mgr, not a data-plane tier: Proxmox creates the // fleet rather than being consumed by it (D6). const yaml = generate(config({ proxmoxSim: true })); expect(yaml).toContain(PROXMOX_SIM_IP); expect(yaml).toContain('secure-mgmt'); }); test('declares the secure-mgmt network it puts the simulator on', () => { // A service on a network the file never declares is a compose error at // `up`, and it reads as a topology problem rather than a missing line. const yaml = generate(config({ proxmoxSim: true })); const networksBlock = yaml.slice(yaml.indexOf('networks:'), yaml.indexOf('services:')); expect(networksBlock).toContain('secure-mgmt'); }); test('mounts the Docker socket, since creating an LXC must make a real box', () => { expect(generate(config({ proxmoxSim: true }))).toContain('/var/run/docker.sock'); }); test('passes the compose project through, which names the networks to attach to', () => { // Left to a default, the provisioner would start containers on a network // no test is watching, and the deploy failure would point at DNS. expect(generate(config({ proxmoxSim: true }))).toContain('CELILO_E2E_PROJECT'); }); });