mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-04-14 06:26:35 +00:00
Fix parsing of non-unit memory numbers and add tests
Signed-off-by: Cameron Diver <cameron@resin.io>
This commit is contained in:
parent
a6dbfb57a1
commit
1c27ebc354
@ -14,7 +14,7 @@ validRestartPolicies = [ 'no', 'always', 'on-failure', 'unless-stopped' ]
|
||||
PORTS_REGEX = /^(?:(?:([a-fA-F\d.:]+):)?([\d]*)(?:-([\d]+))?:)?([\d]+)(?:-([\d]+))?(?:\/(udp|tcp))?$/
|
||||
|
||||
parseMemoryNumber = (numAsString, defaultVal) ->
|
||||
m = numAsString?.toString().match(/^([0-9]+)([bkmg])?b?$/i)
|
||||
m = numAsString?.toString().match(/^([0-9]+)([bkmg]?)b?$/i)
|
||||
if !m? and defaultVal?
|
||||
return parseMemoryNumber(defaultVal)
|
||||
num = m[1]
|
||||
|
@ -4,7 +4,6 @@ ComposeService = require '../../src/compose/service'
|
||||
describe 'compose/service.cofee', ->
|
||||
describe 'parseMemoryNumber()', ->
|
||||
makeComposeServiceWithLimit = (memLimit) ->
|
||||
console.log('MAKING SERVICE WITH LIMIT', memLimit)
|
||||
new ComposeService(
|
||||
appId: 123456
|
||||
serviceId: 123456
|
||||
@ -15,6 +14,12 @@ describe 'compose/service.cofee', ->
|
||||
it 'should correctly parse memory number strings without a unit', ->
|
||||
expect(makeComposeServiceWithLimit('64').memLimit).to.equal(64)
|
||||
|
||||
it 'should correctly apply the default value', ->
|
||||
expect(makeComposeServiceWithLimit(undefined).memLimit).to.equal(0)
|
||||
|
||||
it 'should correctly support parsing numbers as memory limits', ->
|
||||
expect(makeComposeServiceWithLimit(64).memLimit).to.equal(64)
|
||||
|
||||
it 'should correctly parse memory number strings that use a byte unit', ->
|
||||
expect(makeComposeServiceWithLimit('64b').memLimit).to.equal(64)
|
||||
expect(makeComposeServiceWithLimit('64B').memLimit).to.equal(64)
|
||||
|
Loading…
x
Reference in New Issue
Block a user