Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resin.models.device.ensureSupervisorCompatibility(): add tests and handle invalid semver versions gracefully #227

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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