117 lines
3.5 KiB
JavaScript
117 lines
3.5 KiB
JavaScript
import test from 'brittle'
|
|
import {
|
|
bareHolesailEnvTruthy,
|
|
bareHolesailParseConfig
|
|
} from './lib/bare-holesail.js'
|
|
import { loadHolesailConstructor } from './lib/bare-holesail-loader.js'
|
|
import { tryLoadBareCtxKeyFromDriveBundlePath } from './lib/bare-os-ctx-bare.js'
|
|
|
|
test('bareHolesailEnvTruthy', (t) => {
|
|
t.ok(bareHolesailEnvTruthy('1'))
|
|
t.ok(bareHolesailEnvTruthy('true'))
|
|
t.ok(bareHolesailEnvTruthy(' YES '))
|
|
t.absent(bareHolesailEnvTruthy('0'))
|
|
t.absent(bareHolesailEnvTruthy(''))
|
|
})
|
|
|
|
test('bareHolesailParseConfig initd disabled', (t) => {
|
|
const r = bareHolesailParseConfig({}, 'initd')
|
|
t.absent(r.enabled)
|
|
})
|
|
|
|
test('bareHolesailParseConfig initd server secure', (t) => {
|
|
const r = bareHolesailParseConfig(
|
|
{
|
|
BARE_OS_HOLESAIL_INITD: '1',
|
|
BARE_OS_HOLESAIL_SERVER: '1',
|
|
BARE_OS_HOLESAIL_SECURE: '1',
|
|
BARE_OS_HOLESAIL_PORT: '18080'
|
|
},
|
|
'initd'
|
|
)
|
|
t.ok(r.enabled)
|
|
t.absent(r.err)
|
|
t.ok(r.opts)
|
|
t.is(r.opts.server, true)
|
|
t.is(r.opts.client, false)
|
|
t.is(r.opts.secure, true)
|
|
t.is(r.opts.port, 18080)
|
|
})
|
|
|
|
test('bareHolesailParseConfig initd client needs key', (t) => {
|
|
const r = bareHolesailParseConfig(
|
|
{
|
|
BARE_OS_HOLESAIL_INITD: '1',
|
|
BARE_OS_HOLESAIL_CLIENT: '1'
|
|
},
|
|
'initd'
|
|
)
|
|
t.ok(r.enabled)
|
|
t.ok(r.err)
|
|
})
|
|
|
|
test('bareHolesailParseConfig kernel profile uses KERNEL_ prefix', (t) => {
|
|
const r = bareHolesailParseConfig(
|
|
{
|
|
BARE_OS_HOLESAIL_KERNEL: '1',
|
|
BARE_OS_HOLESAIL_KERNEL_SERVER: '1'
|
|
},
|
|
'kernel'
|
|
)
|
|
t.ok(r.enabled)
|
|
t.absent(r.err)
|
|
t.ok(r.opts?.server)
|
|
})
|
|
|
|
test('bareHolesailParseConfig rejects both server and client', (t) => {
|
|
const r = bareHolesailParseConfig(
|
|
{
|
|
BARE_OS_HOLESAIL_INITD: '1',
|
|
BARE_OS_HOLESAIL_SERVER: '1',
|
|
BARE_OS_HOLESAIL_CLIENT: '1'
|
|
},
|
|
'initd'
|
|
)
|
|
t.ok(r.err)
|
|
})
|
|
|
|
test('loadHolesailConstructor uses booter-owned holesail import', async (t) => {
|
|
const ctx = { bare: Object.freeze({}) }
|
|
const Ho = await loadHolesailConstructor(ctx)
|
|
t.is(typeof Ho, 'function')
|
|
t.is(Object.prototype.hasOwnProperty.call(ctx.bare, 'holesail'), false)
|
|
})
|
|
|
|
test('drive bundle eval wraps non-addon require with addon-capable facade', async (t) => {
|
|
const prevRequire = globalThis.require
|
|
const fakeRequire = Object.preventExtensions(function fakeRequire() {
|
|
throw new Error('unexpected require() call in test bundle')
|
|
})
|
|
|
|
globalThis.require = fakeRequire
|
|
|
|
const bundleSource =
|
|
'var __require = ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) { throw Error(\'Dynamic require of "\' + x + \'" is not supported\'); });\n' +
|
|
'var __bare_os_bundle_exports__ = { default: typeof __require.addon === "function" };\n' +
|
|
';(function(){var g=globalThis;var s="__bare_os_stdlib__";g[s]=g[s]||{};var e=typeof __bare_os_bundle_exports__!=="undefined"?__bare_os_bundle_exports__:void 0;var v=e!=null&&typeof e==="object"&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;g[s]["driveBundleProbe"]=v;})();\n'
|
|
|
|
try {
|
|
const loaded = await tryLoadBareCtxKeyFromDriveBundlePath(
|
|
{},
|
|
{
|
|
async readFile(path) {
|
|
return path === '/lib/bare/bundles/driveBundleProbe.js'
|
|
? Buffer.from(bundleSource)
|
|
: null
|
|
}
|
|
},
|
|
'/lib/bare/bundles/driveBundleProbe.js',
|
|
'driveBundleProbe'
|
|
)
|
|
t.is(loaded, true)
|
|
} finally {
|
|
if (prevRequire === undefined) delete globalThis.require
|
|
else globalThis.require = prevRequire
|
|
}
|
|
})
|