40 lines
2.0 KiB
JavaScript
40 lines
2.0 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { runInNewContext } from 'node:vm';
|
|
import { readFileSync } from 'node:fs';
|
|
import { patchSettings, target } from './install-host-settings.mjs';
|
|
|
|
test("next host settings API remains unchanged", () => {
|
|
const source = "this.ctx.remote.settings.describe(); this.ctx.remote.settings.mutate(namespace, ops, revision);";
|
|
assert.equal(patchSettings(source, "0.2.1-rc.5"), source);
|
|
assert.throws(() => patchSettings(target, "0.2.1-rc.5"), /native host settings/);
|
|
assert.throws(() => patchSettings("", "0.2.1-rc.5"), /native host settings/);
|
|
});
|
|
|
|
test('settings use host persistence on domains without changing loopback facts', () => {
|
|
for (const isLoopback of [false, true]) {
|
|
const ctx = { remote: { $host: { isLoopback } } };
|
|
const source = '(function(ctx) { ' + target + ' return persistence; })(ctx)';
|
|
assert.equal(runInNewContext(patchSettings(source, '0.2.0-rc.2'), { ctx }), 'host');
|
|
assert.equal(ctx.remote.$host.isLoopback, isLoopback);
|
|
}
|
|
});
|
|
|
|
test('reject unsupported versions, changed selectors, duplicates and repeat installation', () => {
|
|
assert.throws(() => patchSettings(target, '0.2.0-rc.3'), /unsupported DSH version/);
|
|
for (const source of ['', target.replace('isLoopback', 'isLocal'), target + target,
|
|
patchSettings(target, '0.2.0-rc.2')]) {
|
|
assert.throws(() => patchSettings(source, '0.2.0-rc.2'), /exactly one/);
|
|
}
|
|
});
|
|
|
|
test('patch leaves surrounding code unchanged and is wired into the image', () => {
|
|
const source = 'before; ' + target + ' after;';
|
|
const result = patchSettings(source, '0.2.0-rc.2');
|
|
assert.ok(result.startsWith('before; '));
|
|
assert.ok(result.endsWith(' after;'));
|
|
const dockerfile = readFileSync(new URL('./Dockerfile', import.meta.url), 'utf8');
|
|
assert.ok(dockerfile.includes('COPY install-host-settings.mjs /usr/local/lib/dsh-mgr/install-host-settings.mjs'));
|
|
assert.ok(dockerfile.indexOf('RUN node /usr/local/lib/dsh-mgr/install-host-settings.mjs') > dockerfile.indexOf('npm install --global --foreground-scripts'));
|
|
});
|