mirror of
https://github.com/balena-io/etcher.git
synced 2025-04-24 15:27:17 +00:00
upgrade: etcher-image-write
to v8.0.0 (#688)
This new version stops sending a `passedValidation` boolean property upon completion and still throws an `EVALIDATION` error when validation fails. Such small chance allows us to get rid of lot of complexity related to handling the `passedValidation` value in the application state. Signed-off-by: Juan Cruz Viotti <jviotti@openmailbox.org>
This commit is contained in:
parent
73edf02e5f
commit
ce1c1d724d
@ -59,7 +59,7 @@ $ sudo etcher image.iso --robot --drive /dev/disk2
|
||||
{"command":"progress","data":{"type":"write","percentage":1,"eta":130,"speed":1703936}}
|
||||
...
|
||||
{"command":"progress","data":{"type":"check","percentage":100,"eta":0,"speed":17180514}}
|
||||
{"command":"done","data":{"passedValidation":true,"sourceChecksum":"27c39a5d"}}
|
||||
{"command":"done","data":{"sourceChecksum":"27c39a5d"}}
|
||||
```
|
||||
|
||||
The `command` property can be used to determine the action taking place, while
|
||||
|
@ -96,24 +96,15 @@ form.run([
|
||||
return log.toStdout(JSON.stringify({
|
||||
command: 'done',
|
||||
data: {
|
||||
passedValidation: results.passedValidation,
|
||||
sourceChecksum: results.sourceChecksum
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
if (results.passedValidation) {
|
||||
console.log('Your flash is complete!');
|
||||
console.log(`Checksum: ${results.sourceChecksum}`);
|
||||
} else {
|
||||
console.error('Validation failed!');
|
||||
}
|
||||
console.log('Your flash is complete!');
|
||||
console.log(`Checksum: ${results.sourceChecksum}`);
|
||||
}).then(() => {
|
||||
if (results.passedValidation) {
|
||||
process.exit(EXIT_CODES.SUCCESS);
|
||||
} else {
|
||||
process.exit(EXIT_CODES.VALIDATION_ERROR);
|
||||
}
|
||||
process.exit(EXIT_CODES.SUCCESS);
|
||||
});
|
||||
|
||||
}).catch((error) => {
|
||||
@ -132,6 +123,10 @@ form.run([
|
||||
|
||||
utils.printError(error);
|
||||
}).then(() => {
|
||||
if (error.code === 'EVALIDATION') {
|
||||
process.exit(EXIT_CODES.VALIDATION_ERROR);
|
||||
}
|
||||
|
||||
process.exit(EXIT_CODES.GENERAL_ERROR);
|
||||
});
|
||||
|
||||
|
@ -92,7 +92,6 @@ FlashState.service('FlashStateModel', function() {
|
||||
*
|
||||
* @example
|
||||
* FlashStateModel.unsetFlashingFlag({
|
||||
* passedValidation: true,
|
||||
* cancelled: false,
|
||||
* sourceChecksum: 'a1b45d'
|
||||
* });
|
||||
@ -170,32 +169,6 @@ FlashState.service('FlashStateModel', function() {
|
||||
return Store.getState().get('flashState').toJS();
|
||||
};
|
||||
|
||||
/**
|
||||
* @summary Determine if the last flash was successful
|
||||
* @function
|
||||
* @public
|
||||
*
|
||||
* @description
|
||||
* This function returns true if the flash was cancelled, given
|
||||
* a cancellation is a user request, and doesn't represent an
|
||||
* actual flash error.
|
||||
*
|
||||
* This function returns true if there was no last flash.
|
||||
*
|
||||
* @returns {Boolean} whether the last flash was successful
|
||||
*
|
||||
* @example
|
||||
* if (FlashStateModel.wasLastFlashSuccessful()) {
|
||||
* console.log('The last flash was successful');
|
||||
* }
|
||||
*/
|
||||
this.wasLastFlashSuccessful = () => {
|
||||
return _.some([
|
||||
this.wasLastFlashCancelled(),
|
||||
_.get(this.getFlashResults(), 'passedValidation', true)
|
||||
]);
|
||||
};
|
||||
|
||||
/**
|
||||
* @summary Determine if the last flash was cancelled
|
||||
* @function
|
||||
|
@ -171,14 +171,9 @@ const storeReducer = (state, action) => {
|
||||
}
|
||||
|
||||
_.defaults(action.data, {
|
||||
passedValidation: false,
|
||||
cancelled: false
|
||||
});
|
||||
|
||||
if (!_.isBoolean(action.data.passedValidation)) {
|
||||
throw new Error(`Invalid results passedValidation: ${action.data.passedValidation}`);
|
||||
}
|
||||
|
||||
if (!_.isBoolean(action.data.cancelled)) {
|
||||
throw new Error(`Invalid results cancelled: ${action.data.cancelled}`);
|
||||
}
|
||||
@ -187,18 +182,10 @@ const storeReducer = (state, action) => {
|
||||
throw new Error('The sourceChecksum value can\'t exist if the flashing was cancelled');
|
||||
}
|
||||
|
||||
if (action.data.cancelled && action.data.passedValidation) {
|
||||
throw new Error('The passedValidation value can\'t be true if the flashing was cancelled');
|
||||
}
|
||||
|
||||
if (action.data.passedValidation && action.data.sourceChecksum && !_.isString(action.data.sourceChecksum)) {
|
||||
if (action.data.sourceChecksum && !_.isString(action.data.sourceChecksum)) {
|
||||
throw new Error(`Invalid results sourceChecksum: ${action.data.sourceChecksum}`);
|
||||
}
|
||||
|
||||
if (action.data.passedValidation && action.data.errorCode) {
|
||||
throw new Error('The errorCode value can\'t be set if the flashing passed validation');
|
||||
}
|
||||
|
||||
if (action.data.errorCode && !_.isString(action.data.errorCode) && !_.isNumber(action.data.errorCode)) {
|
||||
throw new Error(`Invalid results errorCode: ${action.data.errorCode}`);
|
||||
}
|
||||
|
@ -64,24 +64,20 @@ module.exports = function(
|
||||
return;
|
||||
}
|
||||
|
||||
if (FlashStateModel.wasLastFlashSuccessful()) {
|
||||
OSNotificationService.send('Success!', 'Your flash is complete');
|
||||
AnalyticsService.logEvent('Done');
|
||||
$state.go('success');
|
||||
} else {
|
||||
OSNotificationService.send('Oops!', 'Looks like your flash has failed');
|
||||
AnalyticsService.logEvent('Validation error');
|
||||
}
|
||||
OSNotificationService.send('Success!', 'Your flash is complete');
|
||||
AnalyticsService.logEvent('Done');
|
||||
$state.go('success');
|
||||
})
|
||||
.catch((error) => {
|
||||
OSNotificationService.send('Oops!', 'Looks like your flash has failed');
|
||||
|
||||
if (error.type === 'check') {
|
||||
if (error.code === 'EVALIDATION') {
|
||||
AnalyticsService.logEvent('Validation error');
|
||||
} else {
|
||||
AnalyticsService.logEvent('Flash error');
|
||||
ErrorService.reportException(error);
|
||||
}
|
||||
|
||||
ErrorService.reportException(error);
|
||||
})
|
||||
.finally(() => {
|
||||
OSWindowProgressService.clear();
|
||||
|
@ -1,20 +1,23 @@
|
||||
<div class="page-main row around-xs">
|
||||
|
||||
<div class="alert-ribbon" ng-class="{
|
||||
'alert-ribbon--open': !main.state.wasLastFlashSuccessful()
|
||||
}">
|
||||
'alert-ribbon--open': main.state.getLastFlashErrorCode()
|
||||
}" ng-switch="main.state.getLastFlashErrorCode()">
|
||||
<span class="glyphicon glyphicon-warning-sign"></span>
|
||||
<span ng-show="main.state.getLastFlashErrorCode() === 'ENOSPC'">
|
||||
|
||||
<span ng-switch-when="ENOSPC">
|
||||
Not enough space on the drive.<br>
|
||||
Please insert larger one and
|
||||
<button class="button button-link" ng-click="main.restartAfterFailure()">try again</button>
|
||||
</span>
|
||||
<span ng-show="main.state.getLastFlashErrorCode() !== 'ENOSPC' && main.settings.get('validateWriteOnSuccess')">
|
||||
|
||||
<span ng-switch-when="EVALIDATION">
|
||||
Your removable drive may be corrupted.
|
||||
<br>Try inserting a different one and
|
||||
<button class="button button-link" ng-click="main.restartAfterFailure()">press "retry"</button>
|
||||
</span>
|
||||
<span ng-show="main.state.getLastFlashErrorCode() !== 'ENOSPC' && !main.settings.get('validateWriteOnSuccess')">
|
||||
|
||||
<span ng-switch-default>
|
||||
Oops, seems something went wrong.
|
||||
Click <button class="button button-link" ng-click="main.restartAfterFailure()">here</button> to retry
|
||||
</span>
|
||||
@ -111,13 +114,13 @@
|
||||
percentage="main.state.getFlashState().percentage"
|
||||
striped="{{ main.state.getFlashState().type == 'check' }}"
|
||||
ng-attr-active="{{ main.state.isFlashing() }}"
|
||||
ng-show="main.state.wasLastFlashSuccessful()"
|
||||
ng-show="!main.state.getLastFlashErrorCode()"
|
||||
ng-click="flash.flashImageToDrive(main.selection.getImagePath(), main.selection.getDrive())"
|
||||
ng-disabled="main.shouldFlashStepBeDisabled()">
|
||||
<span ng-bind="flash.getProgressButtonLabel()"></span>
|
||||
</progress-button>
|
||||
|
||||
<button class="button button-warning button-brick" ng-hide="main.state.wasLastFlashSuccessful()" ng-click="main.restartAfterFailure()">
|
||||
<button class="button button-warning button-brick" ng-show="main.state.getLastFlashErrorCode()" ng-click="main.restartAfterFailure()">
|
||||
<span class="glyphicon glyphicon-repeat"></span> Retry
|
||||
</button>
|
||||
|
||||
|
@ -49,10 +49,8 @@ const EXIT_CODES = require('../exit-codes');
|
||||
* throw error;
|
||||
* });
|
||||
*
|
||||
* child.on('done', (results) => {
|
||||
* if (results.passedValidation) {
|
||||
* console.log('Validation was successful!');
|
||||
* }
|
||||
* child.on('done', () => {
|
||||
* console.log('Validation was successful!');
|
||||
* });
|
||||
*/
|
||||
exports.write = (image, drive, options) => {
|
||||
|
57
npm-shrinkwrap.json
generated
57
npm-shrinkwrap.json
generated
@ -141,7 +141,7 @@
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"from": "isarray@>=1.0.0 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
"resolved": "http://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.1.4",
|
||||
@ -163,7 +163,7 @@
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"from": "isarray@>=1.0.0 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
"resolved": "http://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.1.4",
|
||||
@ -776,7 +776,7 @@
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"from": "isarray@>=1.0.0 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
"resolved": "http://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.1.4",
|
||||
@ -798,7 +798,7 @@
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"from": "isarray@>=1.0.0 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
"resolved": "http://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.0.6",
|
||||
@ -867,7 +867,7 @@
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"from": "isarray@>=1.0.0 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
"resolved": "http://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.0.6",
|
||||
@ -1076,7 +1076,7 @@
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"from": "isarray@>=1.0.0 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
"resolved": "http://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.0.6",
|
||||
@ -1167,7 +1167,7 @@
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"from": "isarray@>=1.0.0 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
"resolved": "http://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.1.4",
|
||||
@ -1294,6 +1294,18 @@
|
||||
"from": "ent@>=2.2.0 <3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ent/-/ent-2.2.0.tgz"
|
||||
},
|
||||
"error": {
|
||||
"version": "7.0.2",
|
||||
"from": "error@>=7.0.2 <8.0.0",
|
||||
"resolved": "https://registry.npmjs.org/error/-/error-7.0.2.tgz",
|
||||
"dependencies": {
|
||||
"xtend": {
|
||||
"version": "4.0.1",
|
||||
"from": "xtend@~4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz"
|
||||
}
|
||||
}
|
||||
},
|
||||
"error-ex": {
|
||||
"version": "1.3.0",
|
||||
"from": "error-ex@>=1.2.0 <2.0.0",
|
||||
@ -1398,14 +1410,14 @@
|
||||
}
|
||||
},
|
||||
"etcher-image-write": {
|
||||
"version": "7.0.1",
|
||||
"from": "etcher-image-write@7.0.1",
|
||||
"resolved": "https://registry.npmjs.org/etcher-image-write/-/etcher-image-write-7.0.1.tgz",
|
||||
"version": "8.0.0",
|
||||
"from": "etcher-image-write@8.0.0",
|
||||
"resolved": "https://registry.npmjs.org/etcher-image-write/-/etcher-image-write-8.0.0.tgz",
|
||||
"dependencies": {
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"from": "isarray@~1.0.0",
|
||||
"resolved": "http://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.0.6",
|
||||
@ -1509,7 +1521,7 @@
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"from": "isarray@>=1.0.0 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
"resolved": "http://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
},
|
||||
"mkdirp": {
|
||||
"version": "0.5.0",
|
||||
@ -2593,7 +2605,7 @@
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"from": "isarray@>=1.0.0 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
"resolved": "http://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.1.4",
|
||||
@ -4090,7 +4102,7 @@
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"from": "isarray@>=1.0.0 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
"resolved": "http://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.1.4",
|
||||
@ -4473,7 +4485,7 @@
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"from": "isarray@>=1.0.0 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
"resolved": "http://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.0.6",
|
||||
@ -4574,7 +4586,7 @@
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"from": "isarray@>=1.0.0 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
"resolved": "http://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.1.4",
|
||||
@ -4596,7 +4608,7 @@
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"from": "isarray@>=1.0.0 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
"resolved": "http://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.0.6",
|
||||
@ -4623,7 +4635,7 @@
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"from": "isarray@>=1.0.0 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
"resolved": "http://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.1.4",
|
||||
@ -4686,6 +4698,11 @@
|
||||
"from": "string_decoder@>=0.10.0 <0.11.0",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz"
|
||||
},
|
||||
"string-template": {
|
||||
"version": "0.2.1",
|
||||
"from": "string-template@>=0.2.1 <0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/string-template/-/string-template-0.2.1.tgz"
|
||||
},
|
||||
"string-to-stream": {
|
||||
"version": "1.1.0",
|
||||
"from": "string-to-stream@>=1.0.1 <2.0.0",
|
||||
@ -4827,7 +4844,7 @@
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"from": "isarray@>=1.0.0 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
"resolved": "http://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.1.4",
|
||||
@ -5319,7 +5336,7 @@
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"from": "isarray@>=1.0.0 <1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
"resolved": "http://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.1.4",
|
||||
|
@ -69,7 +69,7 @@
|
||||
"drivelist": "^3.3.3",
|
||||
"electron-is-running-in-asar": "^1.0.0",
|
||||
"etcher-image-stream": "^4.0.0",
|
||||
"etcher-image-write": "^7.0.1",
|
||||
"etcher-image-write": "^8.0.0",
|
||||
"etcher-latest-version": "^1.0.0",
|
||||
"file-tail": "^0.3.0",
|
||||
"flexboxgrid": "^6.3.0",
|
||||
|
@ -39,7 +39,6 @@ describe('Browser: FlashStateModel', function() {
|
||||
|
||||
it('should be able to reset the progress state', function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
passedValidation: true,
|
||||
cancelled: false,
|
||||
sourceChecksum: '1234'
|
||||
});
|
||||
@ -67,7 +66,6 @@ describe('Browser: FlashStateModel', function() {
|
||||
|
||||
it('should not allow setting the state if flashing is false', function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
passedValidation: true,
|
||||
cancelled: false,
|
||||
sourceChecksum: '1234'
|
||||
});
|
||||
@ -206,7 +204,6 @@ describe('Browser: FlashStateModel', function() {
|
||||
FlashStateModel.setFlashingFlag();
|
||||
|
||||
const expectedResults = {
|
||||
passedValidation: true,
|
||||
cancelled: false,
|
||||
sourceChecksum: '1234'
|
||||
};
|
||||
@ -255,7 +252,6 @@ describe('Browser: FlashStateModel', function() {
|
||||
|
||||
it('should be able to set a string error code', function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
passedValidation: false,
|
||||
cancelled: false,
|
||||
sourceChecksum: '1234',
|
||||
errorCode: 'EBUSY'
|
||||
@ -266,7 +262,6 @@ describe('Browser: FlashStateModel', function() {
|
||||
|
||||
it('should be able to set a number error code', function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
passedValidation: false,
|
||||
cancelled: false,
|
||||
sourceChecksum: '1234',
|
||||
errorCode: 123
|
||||
@ -278,7 +273,6 @@ describe('Browser: FlashStateModel', function() {
|
||||
it('should throw if errorCode is not a number not a string', function() {
|
||||
m.chai.expect(function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
passedValidation: false,
|
||||
cancelled: false,
|
||||
sourceChecksum: '1234',
|
||||
errorCode: {
|
||||
@ -288,41 +282,14 @@ describe('Browser: FlashStateModel', function() {
|
||||
}).to.throw('Invalid results errorCode: [object Object]');
|
||||
});
|
||||
|
||||
it('should default passedValidation to false', function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
cancelled: false,
|
||||
sourceChecksum: '1234'
|
||||
});
|
||||
|
||||
const flashResults = FlashStateModel.getFlashResults();
|
||||
|
||||
m.chai.expect(flashResults).to.deep.equal({
|
||||
passedValidation: false,
|
||||
cancelled: false,
|
||||
sourceChecksum: '1234'
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw if passedValidation is not boolean', function() {
|
||||
m.chai.expect(function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
passedValidation: 'true',
|
||||
cancelled: false,
|
||||
sourceChecksum: '1234'
|
||||
});
|
||||
}).to.throw('Invalid results passedValidation: true');
|
||||
});
|
||||
|
||||
it('should default cancelled to false', function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
passedValidation: true,
|
||||
sourceChecksum: '1234'
|
||||
});
|
||||
|
||||
const flashResults = FlashStateModel.getFlashResults();
|
||||
|
||||
m.chai.expect(flashResults).to.deep.equal({
|
||||
passedValidation: true,
|
||||
cancelled: false,
|
||||
sourceChecksum: '1234'
|
||||
});
|
||||
@ -331,65 +298,23 @@ describe('Browser: FlashStateModel', function() {
|
||||
it('should throw if cancelled is not boolean', function() {
|
||||
m.chai.expect(function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
passedValidation: true,
|
||||
cancelled: 'false',
|
||||
sourceChecksum: '1234'
|
||||
});
|
||||
}).to.throw('Invalid results cancelled: false');
|
||||
});
|
||||
|
||||
it('should not throw if passedValidation is true and sourceChecksum does not exist', function() {
|
||||
m.chai.expect(function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
passedValidation: true,
|
||||
cancelled: false
|
||||
});
|
||||
}).to.not.throw();
|
||||
});
|
||||
|
||||
it('should throw if passedValidation is true and sourceChecksum is not a string', function() {
|
||||
m.chai.expect(function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
passedValidation: true,
|
||||
cancelled: false,
|
||||
sourceChecksum: 12345
|
||||
});
|
||||
}).to.throw('Invalid results sourceChecksum: 12345');
|
||||
});
|
||||
|
||||
it('should throw if cancelled is true and sourceChecksum exists', function() {
|
||||
m.chai.expect(function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
passedValidation: false,
|
||||
cancelled: true,
|
||||
sourceChecksum: '1234'
|
||||
});
|
||||
}).to.throw('The sourceChecksum value can\'t exist if the flashing was cancelled');
|
||||
});
|
||||
|
||||
it('should throw if passedValidation is true and errorCode is set', function() {
|
||||
m.chai.expect(function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
passedValidation: true,
|
||||
cancelled: false,
|
||||
sourceChecksum: '1234',
|
||||
errorCode: 'ENOSPC'
|
||||
});
|
||||
}).to.throw('The errorCode value can\'t be set if the flashing passed validation');
|
||||
});
|
||||
|
||||
it('should throw if cancelled is true and passedValidation is true', function() {
|
||||
m.chai.expect(function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
passedValidation: true,
|
||||
cancelled: true
|
||||
});
|
||||
}).to.throw('The passedValidation value can\'t be true if the flashing was cancelled');
|
||||
});
|
||||
|
||||
it('should be able to set flashing to false', function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
passedValidation: true,
|
||||
cancelled: false,
|
||||
sourceChecksum: '1234'
|
||||
});
|
||||
@ -413,7 +338,6 @@ describe('Browser: FlashStateModel', function() {
|
||||
});
|
||||
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
passedValidation: true,
|
||||
cancelled: false,
|
||||
sourceChecksum: '1234'
|
||||
});
|
||||
@ -435,7 +359,6 @@ describe('Browser: FlashStateModel', function() {
|
||||
|
||||
it('should reset the flash results', function() {
|
||||
const expectedResults = {
|
||||
passedValidation: true,
|
||||
cancelled: false,
|
||||
sourceChecksum: '1234'
|
||||
};
|
||||
@ -449,44 +372,6 @@ describe('Browser: FlashStateModel', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('.wasLastFlashSuccessful()', function() {
|
||||
|
||||
it('should return true given a pristine state', function() {
|
||||
FlashStateModel.resetState();
|
||||
m.chai.expect(FlashStateModel.wasLastFlashSuccessful()).to.be.true;
|
||||
});
|
||||
|
||||
it('should return false if !cancelled && !passedValidation', function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
sourceChecksum: '1234',
|
||||
cancelled: false,
|
||||
passedValidation: false
|
||||
});
|
||||
|
||||
m.chai.expect(FlashStateModel.wasLastFlashSuccessful()).to.be.false;
|
||||
});
|
||||
|
||||
it('should return true if !cancelled && passedValidation', function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
sourceChecksum: '1234',
|
||||
cancelled: false,
|
||||
passedValidation: true
|
||||
});
|
||||
|
||||
m.chai.expect(FlashStateModel.wasLastFlashSuccessful()).to.be.true;
|
||||
});
|
||||
|
||||
it('should return true if cancelled && !passedValidation', function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
cancelled: true,
|
||||
passedValidation: false
|
||||
});
|
||||
|
||||
m.chai.expect(FlashStateModel.wasLastFlashSuccessful()).to.be.true;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.wasLastFlashCancelled()', function() {
|
||||
|
||||
it('should return false given a pristine state', function() {
|
||||
@ -494,30 +379,18 @@ describe('Browser: FlashStateModel', function() {
|
||||
m.chai.expect(FlashStateModel.wasLastFlashCancelled()).to.be.false;
|
||||
});
|
||||
|
||||
it('should return false if !cancelled && !passedValidation', function() {
|
||||
it('should return false if !cancelled', function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
sourceChecksum: '1234',
|
||||
cancelled: false,
|
||||
passedValidation: false
|
||||
cancelled: false
|
||||
});
|
||||
|
||||
m.chai.expect(FlashStateModel.wasLastFlashCancelled()).to.be.false;
|
||||
});
|
||||
|
||||
it('should return false if !cancelled && passedValidation', function() {
|
||||
it('should return true if cancelled', function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
sourceChecksum: '1234',
|
||||
cancelled: false,
|
||||
passedValidation: true
|
||||
});
|
||||
|
||||
m.chai.expect(FlashStateModel.wasLastFlashCancelled()).to.be.false;
|
||||
});
|
||||
|
||||
it('should return true if cancelled && !passedValidation', function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
cancelled: true,
|
||||
passedValidation: false
|
||||
cancelled: true
|
||||
});
|
||||
|
||||
m.chai.expect(FlashStateModel.wasLastFlashCancelled()).to.be.true;
|
||||
@ -535,8 +408,7 @@ describe('Browser: FlashStateModel', function() {
|
||||
it('should return the last flash source checksum', function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
sourceChecksum: '1234',
|
||||
cancelled: false,
|
||||
passedValidation: true
|
||||
cancelled: false
|
||||
});
|
||||
|
||||
m.chai.expect(FlashStateModel.getLastFlashSourceChecksum()).to.equal('1234');
|
||||
@ -544,8 +416,7 @@ describe('Browser: FlashStateModel', function() {
|
||||
|
||||
it('should return undefined if the last flash was cancelled', function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
cancelled: true,
|
||||
passedValidation: false
|
||||
cancelled: true
|
||||
});
|
||||
|
||||
m.chai.expect(FlashStateModel.getLastFlashSourceChecksum()).to.be.undefined;
|
||||
@ -564,7 +435,6 @@ describe('Browser: FlashStateModel', function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
sourceChecksum: '1234',
|
||||
cancelled: false,
|
||||
passedValidation: false,
|
||||
errorCode: 'ENOSPC'
|
||||
});
|
||||
|
||||
@ -574,8 +444,7 @@ describe('Browser: FlashStateModel', function() {
|
||||
it('should return undefined if the last flash did not report an error code', function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
sourceChecksum: '1234',
|
||||
cancelled: false,
|
||||
passedValidation: true
|
||||
cancelled: false
|
||||
});
|
||||
|
||||
m.chai.expect(FlashStateModel.getLastFlashErrorCode()).to.be.undefined;
|
||||
|
@ -35,7 +35,6 @@ describe('Browser: ImageWriter', function() {
|
||||
beforeEach(function() {
|
||||
this.performWriteStub = m.sinon.stub(ImageWriterService, 'performWrite');
|
||||
this.performWriteStub.returns($q.resolve({
|
||||
passedValidation: true,
|
||||
cancelled: false,
|
||||
sourceChecksum: '1234'
|
||||
}));
|
||||
@ -47,7 +46,6 @@ describe('Browser: ImageWriter', function() {
|
||||
|
||||
it('should set flashing to false when done', function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
passedValidation: true,
|
||||
cancelled: false,
|
||||
sourceChecksum: '1234'
|
||||
});
|
||||
@ -59,7 +57,6 @@ describe('Browser: ImageWriter', function() {
|
||||
|
||||
it('should prevent writing more than once', function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
passedValidation: true,
|
||||
cancelled: false,
|
||||
sourceChecksum: '1234'
|
||||
});
|
||||
@ -114,7 +111,6 @@ describe('Browser: ImageWriter', function() {
|
||||
|
||||
it('should be rejected with the error', function() {
|
||||
FlashStateModel.unsetFlashingFlag({
|
||||
passedValidation: true,
|
||||
cancelled: false,
|
||||
sourceChecksum: '1234'
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user