mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-29 18:18:52 +00:00
bea0b00804
Change-type: patch Closes: #644 Signed-off-by: Cameron Diver <cameron@resin.io>
50 lines
1.2 KiB
CoffeeScript
50 lines
1.2 KiB
CoffeeScript
m = require 'mochainon'
|
|
{ expect } = m.chai
|
|
|
|
conversion = require '../src/lib/conversions'
|
|
|
|
describe 'conversions', ->
|
|
|
|
describe 'envArrayToObject', ->
|
|
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', ->
|
|
expect(conversion.envArrayToObject(null)).to.deep.equal({})
|
|
expect(conversion.envArrayToObject('')).to.deep.equal({})
|
|
expect(conversion.envArrayToObject([])).to.deep.equal({})
|
|
expect(conversion.envArrayToObject(1)).to.deep.equal({})
|
|
|
|
it 'should ignore leading and trailing whitespace', ->
|
|
expect(conversion.envArrayToObject([
|
|
'TEST=\ntest'
|
|
'TEST2=test\n'
|
|
'TEST3=\ntest\n'
|
|
])).to.deep.equal({
|
|
TEST: 'test'
|
|
TEST2: 'test'
|
|
TEST3: 'test'
|
|
})
|