Skip to content

Commit

Permalink
resin.models.device.ensureSupervisorCompatibility(): add tests and ha…
Browse files Browse the repository at this point in the history
…ndle invalid semver versions gracefully
  • Loading branch information
lekkas committed Oct 26, 2016
1 parent 938d8d7 commit 45438ab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build/models/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ limitations under the License.
*/

exports.ensureSupervisorCompatibility = ensureSupervisorCompatibility = Promise.method(function(version, minVersion) {
if (!semver.valid(version)) {
throw new Error("Invalid supervisor version: " + version);
}
if (semver.lt(version, minVersion)) {
throw new Error("Incompatible supervisor version: " + version + " - must be >= " + minVersion);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/models/device.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ CONTAINER_ACTION_ENDPOINT_TIMEOUT = 50000
# });
###
exports.ensureSupervisorCompatibility = ensureSupervisorCompatibility = Promise.method (version, minVersion) ->
if not semver.valid(version)
throw new Error("Invalid supervisor version: #{version}")

if semver.lt(version, minVersion)
throw new Error("Incompatible supervisor version: #{version} - must be >= #{minVersion}")

Expand Down
16 changes: 16 additions & 0 deletions tests/integration.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,22 @@ describe 'SDK Integration Tests', ->
m.chai.expect(manifest.slug).to.equal('raspberry-pi')
.nodeify(done)

describe 'resin.models.device.ensureSupervisorCompatibility()', ->
MIN_VERSION = '1.0.0'

it 'should be fulfilled if supervisor version is compatible', ->
promise = resin.models.device.ensureSupervisorCompatibility('1.1.0', MIN_VERSION)
m.chai.expect(promise).to.be.fulfilled

it 'should be rejected if supervisor version is not compatible', ->
promise = resin.models.device.ensureSupervisorCompatibility('0.9.0', MIN_VERSION)
m.chai.expect(promise).to.be.rejected

it 'should be rejected if supervisor version is not semver-compatible', ->
INVALID_VERSION = 'InvalidSemver'
promise = resin.models.device.ensureSupervisorCompatibility(INVALID_VERSION, MIN_VERSION)
m.chai.expect(promise).to.be.rejectedWith("Invalid supervisor version: #{INVALID_VERSION}")

describe 'given no applications', ->

describe 'Application Model', ->
Expand Down

0 comments on commit 45438ab

Please sign in to comment.