Auto-merge for PR #616 via VersionBot

Fix regex for parsing memory numbers
This commit is contained in:
resin-io-versionbot[bot] 2018-04-04 14:58:12 +00:00 committed by GitHub
commit b91d6500b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 65 additions and 5 deletions

View File

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

View File

@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY! automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
This project adheres to [Semantic Versioning](http://semver.org/). This project adheres to [Semantic Versioning](http://semver.org/).
## v7.2.0 - 2018-04-04
* Run test suite on CI #616 [Cameron Diver]
* Add mocha to enable unit testing #616 [Lucian Buzzo]
* Fix regex for parsing memory numbers #616 [Cameron Diver]
## v7.1.24 - 2018-03-29 ## v7.1.24 - 2018-03-29
* Respond to reboot and shutdown endpoints with a success object #608 [Cameron Diver] * Respond to reboot and shutdown endpoints with a success object #608 [Cameron Diver]

View File

@ -40,8 +40,9 @@ RUN JOBS=MAX npm install --no-optional --unsafe-perm
COPY webpack.config.js fix-jsonstream.js hardcode-migrations.js /usr/src/app/ COPY webpack.config.js fix-jsonstream.js hardcode-migrations.js /usr/src/app/
COPY src /usr/src/app/src COPY src /usr/src/app/src
COPY test /usr/src/app/test
RUN npm run lint \ RUN npm test \
&& npm run build && npm run build
############################################################################## ##############################################################################

View File

@ -1,7 +1,7 @@
{ {
"name": "resin-supervisor", "name": "resin-supervisor",
"description": "This is resin.io's Supervisor, a program that runs on IoT devices and has the task of running user Apps (which are Docker containers), and updating them as Resin's API informs it to.", "description": "This is resin.io's Supervisor, a program that runs on IoT devices and has the task of running user Apps (which are Docker containers), and updating them as Resin's API informs it to.",
"version": "7.1.24", "version": "7.2.0",
"license": "Apache-2.0", "license": "Apache-2.0",
"repository": { "repository": {
"type": "git", "type": "git",
@ -11,7 +11,8 @@
"start": "./entry.sh", "start": "./entry.sh",
"build": "webpack", "build": "webpack",
"lint": "resin-lint src/", "lint": "resin-lint src/",
"versionist": "versionist" "versionist": "versionist",
"test": "npm run lint && mocha -r coffee-script/register test/**/*"
}, },
"dependencies": { "dependencies": {
"mkfifo": "^0.1.5", "mkfifo": "^0.1.5",
@ -26,6 +27,7 @@
"bluebird": "^3.5.0", "bluebird": "^3.5.0",
"body-parser": "^1.12.0", "body-parser": "^1.12.0",
"buffer-equal-constant-time": "^1.0.1", "buffer-equal-constant-time": "^1.0.1",
"chai": "^4.1.2",
"coffee-loader": "^0.7.3", "coffee-loader": "^0.7.3",
"coffee-script": "~1.11.0", "coffee-script": "~1.11.0",
"copy-webpack-plugin": "^4.2.3", "copy-webpack-plugin": "^4.2.3",
@ -44,6 +46,7 @@
"memoizee": "^0.4.1", "memoizee": "^0.4.1",
"mixpanel": "0.0.20", "mixpanel": "0.0.20",
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"mocha": "^5.0.5",
"network-checker": "~0.0.5", "network-checker": "~0.0.5",
"node-loader": "^0.6.0", "node-loader": "^0.6.0",
"null-loader": "^0.1.1", "null-loader": "^0.1.1",

View File

@ -14,7 +14,7 @@ validRestartPolicies = [ 'no', 'always', 'on-failure', 'unless-stopped' ]
PORTS_REGEX = /^(?:(?:([a-fA-F\d.:]+):)?([\d]*)(?:-([\d]+))?:)?([\d]+)(?:-([\d]+))?(?:\/(udp|tcp))?$/ PORTS_REGEX = /^(?:(?:([a-fA-F\d.:]+):)?([\d]*)(?:-([\d]+))?:)?([\d]+)(?:-([\d]+))?(?:\/(udp|tcp))?$/
parseMemoryNumber = (numAsString, defaultVal) -> parseMemoryNumber = (numAsString, defaultVal) ->
m = numAsString?.toString().match(/^([0-9]+)([bkmg]?)$/) m = numAsString?.toString().match(/^([0-9]+)([bkmg]?)b?$/i)
if !m? and defaultVal? if !m? and defaultVal?
return parseMemoryNumber(defaultVal) return parseMemoryNumber(defaultVal)
num = m[1] num = m[1]

View File

@ -0,0 +1,47 @@
{ expect } = require 'chai'
ComposeService = require '../../src/compose/service'
describe 'compose/service.cofee', ->
describe 'parseMemoryNumber()', ->
makeComposeServiceWithLimit = (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 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)
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)