mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-30 02:28:53 +00:00
4a2ac557ef
'mz' can be safely replaced with fs.promises and util.promisify for faster native methods. 'mkdirp' after Node v8 uses native fs.mkdir, thus is redundant. 'body-parser' is deprecated and contained within express v4.x. Closes: #1567 Change-type: patch Signed-off-by: Christina Wang <christina@balena.io>
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
import { expect } from 'chai';
|
|
import * as conversion from '../src/lib/conversions';
|
|
|
|
describe('conversions', function () {
|
|
describe('envArrayToObject', function () {
|
|
it('should convert an env array to an object', () =>
|
|
expect(
|
|
conversion.envArrayToObject([
|
|
'key=value',
|
|
'test1=test2',
|
|
'k=v',
|
|
'equalsvalue=thisvaluehasan=char',
|
|
'asd=',
|
|
'number=123',
|
|
]),
|
|
).to.deep.equal({
|
|
key: 'value',
|
|
test1: 'test2',
|
|
k: 'v',
|
|
equalsvalue: 'thisvaluehasan=char',
|
|
asd: '',
|
|
number: '123',
|
|
}));
|
|
|
|
it('should ignore invalid env array entries', () =>
|
|
expect(
|
|
conversion.envArrayToObject(['key1', 'key1=value1']),
|
|
).to.deep.equal({
|
|
key1: 'value1',
|
|
}));
|
|
|
|
it('should return an empty object with an empty input', function () {
|
|
// @ts-ignore passing invalid value to test
|
|
expect(conversion.envArrayToObject(null)).to.deep.equal({});
|
|
// @ts-ignore passing invalid value to test
|
|
expect(conversion.envArrayToObject('')).to.deep.equal({});
|
|
expect(conversion.envArrayToObject([])).to.deep.equal({});
|
|
// @ts-ignore passing invalid value to test
|
|
expect(conversion.envArrayToObject(1)).to.deep.equal({});
|
|
});
|
|
});
|
|
|
|
it('should correctly handle whitespace', () =>
|
|
expect(
|
|
conversion.envArrayToObject([
|
|
'key1= test',
|
|
'key2=test\ntest',
|
|
'key3=test ',
|
|
'key4= test ',
|
|
'key5=test\r\ntest',
|
|
]),
|
|
).to.deep.equal({
|
|
key1: ' test',
|
|
key2: 'test\ntest',
|
|
key3: 'test ',
|
|
key4: ' test ',
|
|
key5: 'test\r\ntest',
|
|
}));
|
|
});
|