mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-25 08:21:07 +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
118 lines
3.8 KiB
TypeScript
118 lines
3.8 KiB
TypeScript
import { expect } from 'chai';
|
|
import { ExtraUEnv } from '~/src/config/backends/extra-uEnv';
|
|
|
|
describe('config/extra-uEnv', () => {
|
|
const backend = new ExtraUEnv();
|
|
it('only allows supported configuration options', () => {
|
|
[
|
|
{ configName: 'fdt', supported: true },
|
|
{ configName: 'isolcpus', supported: true },
|
|
{ configName: 'custom_fdt_file', supported: false },
|
|
{ configName: 'splash', supported: false },
|
|
{ configName: '', supported: false },
|
|
].forEach(({ configName, supported }) =>
|
|
expect(backend.isSupportedConfig(configName)).to.equal(supported),
|
|
);
|
|
});
|
|
|
|
it('correctly detects boot config variables', () => {
|
|
[
|
|
{ config: 'HOST_EXTLINUX_isolcpus', valid: true },
|
|
{ config: 'HOST_EXTLINUX_fdt', valid: true },
|
|
{ config: 'HOST_EXTLINUX_rootwait', valid: true },
|
|
{ config: 'HOST_EXTLINUX_5', valid: true },
|
|
{ config: 'DEVICE_EXTLINUX_isolcpus', valid: false },
|
|
{ config: 'isolcpus', valid: false },
|
|
].forEach(({ config, valid }) =>
|
|
expect(backend.isBootConfigVar(config)).to.equal(valid),
|
|
);
|
|
});
|
|
|
|
it('converts variable to backend formatted name', () => {
|
|
[
|
|
{ input: 'HOST_EXTLINUX_isolcpus', output: 'isolcpus' },
|
|
{ input: 'HOST_EXTLINUX_fdt', output: 'fdt' },
|
|
{ input: 'HOST_EXTLINUX_', output: null },
|
|
{ input: 'value', output: null },
|
|
].forEach(({ input, output }) =>
|
|
expect(backend.processConfigVarName(input)).to.equal(output),
|
|
);
|
|
});
|
|
|
|
it('normalizes variable value', () => {
|
|
[{ input: { key: 'key', value: 'value' }, output: 'value' }].forEach(
|
|
({ input, output }) =>
|
|
expect(backend.processConfigVarValue(input.key, input.value)).to.equal(
|
|
output,
|
|
),
|
|
);
|
|
});
|
|
|
|
it('returns the environment name for config variable', () => {
|
|
[
|
|
{ input: 'isolcpus', output: 'HOST_EXTLINUX_isolcpus' },
|
|
{ input: 'fdt', output: 'HOST_EXTLINUX_fdt' },
|
|
{ input: 'rootwait', output: 'HOST_EXTLINUX_rootwait' },
|
|
{ input: '', output: null },
|
|
].forEach(({ input, output }) =>
|
|
expect(backend.createConfigVarName(input)).to.equal(output),
|
|
);
|
|
});
|
|
|
|
it('only allows supported configuration options', () => {
|
|
[
|
|
{ configName: 'fdt', supported: true },
|
|
{ configName: 'isolcpus', supported: true },
|
|
{ configName: 'custom_fdt_file', supported: false },
|
|
{ configName: 'splash', supported: false },
|
|
{ configName: '', supported: false },
|
|
].forEach(({ configName, supported }) =>
|
|
expect(backend.isSupportedConfig(configName)).to.equal(supported),
|
|
);
|
|
});
|
|
|
|
it('correctly detects boot config variables', () => {
|
|
[
|
|
{ config: 'HOST_EXTLINUX_isolcpus', valid: true },
|
|
{ config: 'HOST_EXTLINUX_fdt', valid: true },
|
|
{ config: 'HOST_EXTLINUX_rootwait', valid: true },
|
|
{ config: 'HOST_EXTLINUX_5', valid: true },
|
|
{ config: 'DEVICE_EXTLINUX_isolcpus', valid: false },
|
|
{ config: 'isolcpus', valid: false },
|
|
].forEach(({ config, valid }) =>
|
|
expect(backend.isBootConfigVar(config)).to.equal(valid),
|
|
);
|
|
});
|
|
|
|
it('converts variable to backend formatted name', () => {
|
|
[
|
|
{ input: 'HOST_EXTLINUX_isolcpus', output: 'isolcpus' },
|
|
{ input: 'HOST_EXTLINUX_fdt', output: 'fdt' },
|
|
{ input: 'HOST_EXTLINUX_', output: null },
|
|
{ input: 'value', output: null },
|
|
].forEach(({ input, output }) =>
|
|
expect(backend.processConfigVarName(input)).to.equal(output),
|
|
);
|
|
});
|
|
|
|
it('normalizes variable value', () => {
|
|
[{ input: { key: 'key', value: 'value' }, output: 'value' }].forEach(
|
|
({ input, output }) =>
|
|
expect(backend.processConfigVarValue(input.key, input.value)).to.equal(
|
|
output,
|
|
),
|
|
);
|
|
});
|
|
|
|
it('returns the environment name for config variable', () => {
|
|
[
|
|
{ input: 'isolcpus', output: 'HOST_EXTLINUX_isolcpus' },
|
|
{ input: 'fdt', output: 'HOST_EXTLINUX_fdt' },
|
|
{ input: 'rootwait', output: 'HOST_EXTLINUX_rootwait' },
|
|
{ input: '', output: null },
|
|
].forEach(({ input, output }) =>
|
|
expect(backend.createConfigVarName(input)).to.equal(output),
|
|
);
|
|
});
|
|
});
|