balena-supervisor/test/compose/service.spec.coffee
Lucian Buzzo 9bca2557ea Add mocha to enable unit testing
Implements a simple test for `parseMemoryNumber`

change-type: minor
2018-04-04 13:22:17 +01:00

43 lines
1.8 KiB
CoffeeScript

{ expect } = require 'chai'
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
serviceName: 'foobar'
memLimit: memLimit
)
it 'should correctly parse memory number strings without a unit', ->
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)
it 'should correctly parse memory number strings that use a kilobyte unit', ->
expect(makeComposeServiceWithLimit('64k').memLimit).to.equal(65536)
expect(makeComposeServiceWithLimit('64K').memLimit).to.equal(65536)
expect(makeComposeServiceWithLimit('64kb').memLimit).to.equal(65536)
expect(makeComposeServiceWithLimit('64Kb').memLimit).to.equal(65536)
it 'should correctly parse memory number strings that use a megabyte unit', ->
expect(makeComposeServiceWithLimit('64m').memLimit).to.equal(67108864)
expect(makeComposeServiceWithLimit('64M').memLimit).to.equal(67108864)
expect(makeComposeServiceWithLimit('64mb').memLimit).to.equal(67108864)
expect(makeComposeServiceWithLimit('64Mb').memLimit).to.equal(67108864)
it 'should correctly parse memory number strings that use a gigabyte unit', ->
expect(makeComposeServiceWithLimit('64g').memLimit).to.equal(68719476736)
expect(makeComposeServiceWithLimit('64G').memLimit).to.equal(68719476736)
expect(makeComposeServiceWithLimit('64gb').memLimit).to.equal(68719476736)
expect(makeComposeServiceWithLimit('64Gb').memLimit).to.equal(68719476736)