mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-24 15:56:40 +00:00
f586b7c9a8
When code that is unit tested is part of a file that imports modules which depend on the dbus module, this breaks the unit test environment because there is no system socket set up, as the unit test mocha config doesn't import fixtures.ts. For example, if we change src/compose/utils to import device-config or api-binder, both of those modules import lib/dbus which invokes a dbus.getBus call at the root level. This is problematic for unit testing. We can get around the root-level dbus.getBus call by initializing dbus only when it's first needed. The mocked-dbus test setup code can also be removed in favor of legacy mocha hooks, which makes the dbus stubbing in the legacy test environment more clear. We can remove these legacy hooks when all the legacy tests are migrated to unit/integration. Signed-off-by: Christina Ying Wang <christina@balena.io>
36 lines
922 B
TypeScript
36 lines
922 B
TypeScript
process.env.ROOT_MOUNTPOINT = './test/data';
|
|
process.env.BOOT_MOUNTPOINT = '/mnt/boot';
|
|
process.env.CONFIG_JSON_PATH = '/config.json';
|
|
process.env.CONFIG_MOUNT_POINT = './test/data/config.json';
|
|
process.env.DATABASE_PATH = './test/data/database.sqlite';
|
|
process.env.DATABASE_PATH_2 = './test/data/database2.sqlite';
|
|
process.env.DATABASE_PATH_3 = './test/data/database3.sqlite';
|
|
process.env.LED_FILE = './test/data/led_file';
|
|
|
|
import * as fs from 'fs';
|
|
|
|
// Make sure they are no database files left over from
|
|
// previous runs
|
|
try {
|
|
fs.unlinkSync(process.env.DATABASE_PATH);
|
|
} catch {
|
|
/* noop */
|
|
}
|
|
try {
|
|
fs.unlinkSync(process.env.DATABASE_PATH_2);
|
|
} catch {
|
|
/* noop */
|
|
}
|
|
try {
|
|
fs.unlinkSync(process.env.DATABASE_PATH_3);
|
|
} catch {
|
|
/* noop */
|
|
}
|
|
fs.writeFileSync(
|
|
'./test/data/config.json',
|
|
fs.readFileSync('./test/data/testconfig.json'),
|
|
);
|
|
|
|
import '~/test-lib/mocked-dockerode';
|
|
import '~/test-lib/mocked-iptables';
|