Merge pull request #617 from resin-io/tests

Add mocha to enable unit testing
This commit is contained in:
Lucian Buzzo 2018-04-04 13:42:21 +01:00 committed by GitHub
commit a6dbfb57a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 2 deletions

View File

@ -9,4 +9,7 @@ trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
trim_trailing_whitespace = false
[*.json]
indent_style = space

View File

@ -11,7 +11,8 @@
"start": "./entry.sh",
"build": "webpack",
"lint": "resin-lint src/",
"versionist": "versionist"
"versionist": "versionist",
"test": "mocha -r coffee-script/register test/**/*"
},
"dependencies": {
"mkfifo": "^0.1.5",
@ -26,6 +27,7 @@
"bluebird": "^3.5.0",
"body-parser": "^1.12.0",
"buffer-equal-constant-time": "^1.0.1",
"chai": "^4.1.2",
"coffee-loader": "^0.7.3",
"coffee-script": "~1.11.0",
"copy-webpack-plugin": "^4.2.3",
@ -44,6 +46,7 @@
"memoizee": "^0.4.1",
"mixpanel": "0.0.20",
"mkdirp": "^0.5.1",
"mocha": "^5.0.5",
"network-checker": "~0.0.5",
"node-loader": "^0.6.0",
"null-loader": "^0.1.1",

View File

@ -0,0 +1,42 @@
{ 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)