balena-supervisor/test/legacy/14-conversions.spec.ts
Felipe Lalanne e1e35eb83b Move the current test suite under test/legacy
We are refactoring the supervisor test suite into unit tests (for
algorithms an domain model tests) and integration
tests (for interaction with out-of-process dependencies).
This means the current test suite needs to be classified into
these two categories, and fixed whenever possible.

This commit moves the test suite under the `test/legacy` folder, this
folder should be progressively migrated and eventually removed.
Subsequent commits will begin to split these files into unit and
integration whenever possible.

Depends-on: #1996
Change-type: patch
2022-08-22 17:21:51 -04:00

60 lines
1.5 KiB
TypeScript

import { expect } from 'chai';
import * as conversion from '~/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',
}));
});