mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-28 01:28:52 +00:00
827f892c13
This means that configuration backend tests no longer use stubs and (mostly) avoid internal dependencies in the tests. Instead of stubs and mock-fs, the tests use [testfs](https://github.com/balena-io-modules/mocha-pod#working-with-the-filesystem) which allows working with a real filesystem and ensuring everything is re-set between tests. This is the last change needed in order to be able to merge #1971. Here is the list of changes - [x] Migrate splash image backend tests - [x] Migrate extlinux backend tests - [x] Migrate config.txt backend tests - [x] Migrate extra-uenv config tests - [x] Migrate odmdata config tests - [x] Migrate config utils tests - [x] Migrate device-config tests Change-type: patch
79 lines
2.1 KiB
TypeScript
79 lines
2.1 KiB
TypeScript
import { testfs } from 'mocha-pod';
|
|
import { stripIndent } from 'common-tags';
|
|
|
|
import { expect } from 'chai';
|
|
import * as hostUtils from '~/lib/host-utils';
|
|
|
|
import { ConfigTxt } from '~/src/config/backends/config-txt';
|
|
|
|
describe('config/config-txt', () => {
|
|
it('correctly parses a config.txt file', async () => {
|
|
const tfs = await testfs({
|
|
[hostUtils.pathOnBoot('config.txt')]: stripIndent`
|
|
initramfs initramf.gz 0x00800000
|
|
dtparam=i2c=on
|
|
dtparam=audio=on
|
|
dtoverlay=ads7846
|
|
enable_uart=1
|
|
avoid_warnings=1
|
|
gpu_mem=16
|
|
hdmi_force_hotplug:1=1
|
|
dtoverlay=lirc-rpi,gpio_out_pin=17,gpio_in_pin=13`,
|
|
}).enable();
|
|
|
|
const configTxt = new ConfigTxt();
|
|
|
|
// Will try to parse /test/data/mnt/boot/config.txt
|
|
await expect(configTxt.getBootConfig()).to.eventually.deep.equal({
|
|
dtparam: ['i2c=on', 'audio=on'],
|
|
dtoverlay: ['ads7846', 'lirc-rpi,gpio_out_pin=17,gpio_in_pin=13'],
|
|
enable_uart: '1',
|
|
avoid_warnings: '1',
|
|
gpu_mem: '16',
|
|
initramfs: 'initramf.gz 0x00800000',
|
|
// This syntax is supported by the backend but not the cloud side
|
|
'hdmi_force_hotplug:1': '1',
|
|
});
|
|
|
|
await tfs.restore();
|
|
});
|
|
|
|
it('ensures required fields are written to config.txt', async () => {
|
|
const tfs = await testfs({
|
|
[hostUtils.pathOnBoot('config.txt')]: stripIndent`
|
|
enable_uart=1
|
|
dtparam=i2c_arm=on
|
|
dtparam=spi=on
|
|
disable_splash=1
|
|
dtparam=audio=on
|
|
gpu_mem=16
|
|
`,
|
|
}).enable();
|
|
|
|
const configTxt = new ConfigTxt();
|
|
|
|
await configTxt.setBootConfig({
|
|
dtparam: ['i2c=on', 'audio=on'],
|
|
dtoverlay: ['ads7846', 'lirc-rpi,gpio_out_pin=17,gpio_in_pin=13'],
|
|
enable_uart: '1',
|
|
avoid_warnings: '1',
|
|
gpu_mem: '256',
|
|
initramfs: 'initramf.gz 0x00800000',
|
|
'hdmi_force_hotplug:1': '1',
|
|
});
|
|
|
|
// Will try to parse /test/data/mnt/boot/config.txt
|
|
await expect(configTxt.getBootConfig()).to.eventually.deep.equal({
|
|
dtparam: ['i2c=on', 'audio=on'],
|
|
dtoverlay: ['ads7846', 'lirc-rpi,gpio_out_pin=17,gpio_in_pin=13'],
|
|
enable_uart: '1',
|
|
avoid_warnings: '1',
|
|
gpu_mem: '256',
|
|
initramfs: 'initramf.gz 0x00800000',
|
|
'hdmi_force_hotplug:1': '1',
|
|
});
|
|
|
|
await tfs.restore();
|
|
});
|
|
});
|