mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-23 19:26:33 +00:00
fix: Correct image.size usage in tests and code-comments (#1833)
image.size is always an object, never a plain number Change-type: patch
This commit is contained in:
parent
03b252024e
commit
26b521411f
@ -41,7 +41,13 @@ module.exports = function (
|
|||||||
* @example
|
* @example
|
||||||
* FlashController.flashImageToDrive({
|
* FlashController.flashImageToDrive({
|
||||||
* path: 'rpi.img',
|
* path: 'rpi.img',
|
||||||
* size: 1000000000
|
* size: {
|
||||||
|
* original: 1000000000,
|
||||||
|
* final: {
|
||||||
|
* estimation: false,
|
||||||
|
* value: 1000000000
|
||||||
|
* }
|
||||||
|
* }
|
||||||
* }, {
|
* }, {
|
||||||
* device: '/dev/disk2',
|
* device: '/dev/disk2',
|
||||||
* description: 'Foo',
|
* description: 'Foo',
|
||||||
|
@ -102,7 +102,13 @@ exports.isSystemDrive = (drive) => {
|
|||||||
* ]
|
* ]
|
||||||
* }, {
|
* }, {
|
||||||
* path: '/Volumes/Untitled/image.img',
|
* path: '/Volumes/Untitled/image.img',
|
||||||
* size: 1000000000
|
* size: {
|
||||||
|
* original: 1000000000,
|
||||||
|
* final: {
|
||||||
|
* estimation: false,
|
||||||
|
* value: 1000000000
|
||||||
|
* }
|
||||||
|
* }
|
||||||
* })) {
|
* })) {
|
||||||
* console.log('This drive is a source drive!');
|
* console.log('This drive is a source drive!');
|
||||||
* }
|
* }
|
||||||
@ -136,7 +142,13 @@ exports.isSourceDrive = (drive, image) => {
|
|||||||
* size: 1000000000
|
* size: 1000000000
|
||||||
* }, {
|
* }, {
|
||||||
* path: 'rpi.img',
|
* path: 'rpi.img',
|
||||||
* size: 1000000000
|
* size: {
|
||||||
|
* original: 1000000000,
|
||||||
|
* final: {
|
||||||
|
* estimation: false,
|
||||||
|
* value: 1000000000
|
||||||
|
* }
|
||||||
|
* },
|
||||||
* })) {
|
* })) {
|
||||||
* console.log('We can flash the image to this drive!');
|
* console.log('We can flash the image to this drive!');
|
||||||
* }
|
* }
|
||||||
@ -206,7 +218,13 @@ exports.isDriveDisabled = (drive) => {
|
|||||||
* protected: false
|
* protected: false
|
||||||
* }, {
|
* }, {
|
||||||
* path: 'rpi.img',
|
* path: 'rpi.img',
|
||||||
* size: 1000000000,
|
* size: {
|
||||||
|
* original: 1000000000,
|
||||||
|
* final: {
|
||||||
|
* estimation: false,
|
||||||
|
* value: 1000000000
|
||||||
|
* }
|
||||||
|
* },
|
||||||
* recommendedDriveSize: 2000000000
|
* recommendedDriveSize: 2000000000
|
||||||
* })) {
|
* })) {
|
||||||
* console.log('This drive is valid!');
|
* console.log('This drive is valid!');
|
||||||
@ -242,7 +260,13 @@ exports.isDriveValid = (drive, image) => {
|
|||||||
*
|
*
|
||||||
* const image = {
|
* const image = {
|
||||||
* path: 'rpi.img',
|
* path: 'rpi.img',
|
||||||
* size: 2000000000
|
* size: {
|
||||||
|
* original: 2000000000,
|
||||||
|
* final: {
|
||||||
|
* estimation: false,
|
||||||
|
* value: 2000000000
|
||||||
|
* }
|
||||||
|
* },
|
||||||
* recommendedDriveSize: 4000000000
|
* recommendedDriveSize: 4000000000
|
||||||
* });
|
* });
|
||||||
*
|
*
|
||||||
@ -347,7 +371,13 @@ exports.COMPATIBILITY_STATUS_TYPES = {
|
|||||||
*
|
*
|
||||||
* const image = {
|
* const image = {
|
||||||
* path: '/path/to/rpi.img',
|
* path: '/path/to/rpi.img',
|
||||||
* size: 2000000000
|
* size: {
|
||||||
|
* original: 2000000000,
|
||||||
|
* final: {
|
||||||
|
* estimation: false,
|
||||||
|
* value: 2000000000
|
||||||
|
* }
|
||||||
|
* },
|
||||||
* recommendedDriveSize: 4000000000
|
* recommendedDriveSize: 4000000000
|
||||||
* });
|
* });
|
||||||
*
|
*
|
||||||
|
@ -64,7 +64,14 @@ exports.toggleSetDrive = (drive) => {
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* selectionState.setImage({
|
* selectionState.setImage({
|
||||||
* path: 'foo.img'
|
* path: 'foo.img',
|
||||||
|
* size: {
|
||||||
|
* original: 1000000000,
|
||||||
|
* final: {
|
||||||
|
* estimation: false,
|
||||||
|
* value: 1000000000
|
||||||
|
* }
|
||||||
|
* }
|
||||||
* });
|
* });
|
||||||
*/
|
*/
|
||||||
exports.setImage = (image) => {
|
exports.setImage = (image) => {
|
||||||
|
@ -325,14 +325,14 @@ describe('Shared: DriveConstraints', function () {
|
|||||||
size: {
|
size: {
|
||||||
original: this.drive.size - 1,
|
original: this.drive.size - 1,
|
||||||
final: {
|
final: {
|
||||||
estimation: false
|
estimation: false,
|
||||||
|
value: this.drive.size - 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return true if the final size is less than the drive size', function () {
|
it('should return true if the final size is less than the drive size', function () {
|
||||||
this.image.size.final.value = this.drive.size - 1
|
|
||||||
m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.true
|
m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.true
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -354,7 +354,8 @@ describe('Shared: DriveConstraints', function () {
|
|||||||
size: {
|
size: {
|
||||||
original: this.drive.size,
|
original: this.drive.size,
|
||||||
final: {
|
final: {
|
||||||
estimation: false
|
estimation: false,
|
||||||
|
value: this.drive.size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -366,7 +367,6 @@ describe('Shared: DriveConstraints', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should return true if the final size is equal to the drive size', function () {
|
it('should return true if the final size is equal to the drive size', function () {
|
||||||
this.image.size.final.value = this.drive.size
|
|
||||||
m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.true
|
m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.true
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -383,7 +383,8 @@ describe('Shared: DriveConstraints', function () {
|
|||||||
size: {
|
size: {
|
||||||
original: this.drive.size + 1,
|
original: this.drive.size + 1,
|
||||||
final: {
|
final: {
|
||||||
estimation: false
|
estimation: false,
|
||||||
|
value: this.drive.size + 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -400,7 +401,6 @@ describe('Shared: DriveConstraints', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should return false if the final size is greater than the drive size', function () {
|
it('should return false if the final size is greater than the drive size', function () {
|
||||||
this.image.size.final.value = this.drive.size + 1
|
|
||||||
m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.false
|
m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.false
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -414,14 +414,14 @@ describe('Shared: DriveConstraints', function () {
|
|||||||
size: {
|
size: {
|
||||||
original: this.drive.size - 1,
|
original: this.drive.size - 1,
|
||||||
final: {
|
final: {
|
||||||
estimation: true
|
estimation: true,
|
||||||
|
value: this.drive.size - 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return true if the final size is less than the drive size', function () {
|
it('should return true if the final size is less than the drive size', function () {
|
||||||
this.image.size.final.value = this.drive.size - 1
|
|
||||||
m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.true
|
m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.true
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -443,7 +443,8 @@ describe('Shared: DriveConstraints', function () {
|
|||||||
size: {
|
size: {
|
||||||
original: this.drive.size,
|
original: this.drive.size,
|
||||||
final: {
|
final: {
|
||||||
estimation: true
|
estimation: true,
|
||||||
|
value: this.drive.size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -455,7 +456,6 @@ describe('Shared: DriveConstraints', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should return true if the final size is equal to the drive size', function () {
|
it('should return true if the final size is equal to the drive size', function () {
|
||||||
this.image.size.final.value = this.drive.size
|
|
||||||
m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.true
|
m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.true
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -472,7 +472,8 @@ describe('Shared: DriveConstraints', function () {
|
|||||||
size: {
|
size: {
|
||||||
original: this.drive.size + 1,
|
original: this.drive.size + 1,
|
||||||
final: {
|
final: {
|
||||||
estimation: true
|
estimation: true,
|
||||||
|
value: this.drive.size + 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -489,7 +490,6 @@ describe('Shared: DriveConstraints', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should return false if the final size is greater than the drive size', function () {
|
it('should return false if the final size is greater than the drive size', function () {
|
||||||
this.image.size.final.value = this.drive.size + 1
|
|
||||||
m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.false
|
m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.false
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -573,7 +573,13 @@ describe('Shared: DriveConstraints', function () {
|
|||||||
protected: false
|
protected: false
|
||||||
}, {
|
}, {
|
||||||
path: path.join(__dirname, 'rpi.img'),
|
path: path.join(__dirname, 'rpi.img'),
|
||||||
size: 1000000000,
|
size: {
|
||||||
|
original: 1000000000,
|
||||||
|
final: {
|
||||||
|
estimation: false,
|
||||||
|
value: 1000000000
|
||||||
|
}
|
||||||
|
},
|
||||||
recommendedDriveSize: 2000000000
|
recommendedDriveSize: 2000000000
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -588,7 +594,13 @@ describe('Shared: DriveConstraints', function () {
|
|||||||
protected: false
|
protected: false
|
||||||
}, {
|
}, {
|
||||||
path: path.join(__dirname, 'rpi.img'),
|
path: path.join(__dirname, 'rpi.img'),
|
||||||
size: 1000000000,
|
size: {
|
||||||
|
original: 1000000000,
|
||||||
|
final: {
|
||||||
|
estimation: false,
|
||||||
|
value: 1000000000
|
||||||
|
}
|
||||||
|
},
|
||||||
recommendedDriveSize: 2000000000
|
recommendedDriveSize: 2000000000
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -603,7 +615,13 @@ describe('Shared: DriveConstraints', function () {
|
|||||||
protected: false
|
protected: false
|
||||||
}, {
|
}, {
|
||||||
path: path.join(__dirname, 'rpi.img'),
|
path: path.join(__dirname, 'rpi.img'),
|
||||||
size: 1000000000,
|
size: {
|
||||||
|
original: 1000000000,
|
||||||
|
final: {
|
||||||
|
estimation: false,
|
||||||
|
value: 1000000000
|
||||||
|
}
|
||||||
|
},
|
||||||
recommendedDriveSize: 2000000001
|
recommendedDriveSize: 2000000001
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -618,7 +636,13 @@ describe('Shared: DriveConstraints', function () {
|
|||||||
protected: false
|
protected: false
|
||||||
}, {
|
}, {
|
||||||
path: path.join(__dirname, 'rpi.img'),
|
path: path.join(__dirname, 'rpi.img'),
|
||||||
size: 1000000000
|
size: {
|
||||||
|
original: 1000000000,
|
||||||
|
final: {
|
||||||
|
estimation: false,
|
||||||
|
value: 1000000000
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
m.chai.expect(result).to.be.true
|
m.chai.expect(result).to.be.true
|
||||||
@ -627,7 +651,13 @@ describe('Shared: DriveConstraints', function () {
|
|||||||
it('should return false if the drive is undefined', function () {
|
it('should return false if the drive is undefined', function () {
|
||||||
const result = constraints.isDriveSizeRecommended(undefined, {
|
const result = constraints.isDriveSizeRecommended(undefined, {
|
||||||
path: path.join(__dirname, 'rpi.img'),
|
path: path.join(__dirname, 'rpi.img'),
|
||||||
size: 1000000000,
|
size: {
|
||||||
|
original: 1000000000,
|
||||||
|
final: {
|
||||||
|
estimation: false,
|
||||||
|
value: 1000000000
|
||||||
|
}
|
||||||
|
},
|
||||||
recommendedDriveSize: 1000000000
|
recommendedDriveSize: 1000000000
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -945,7 +975,8 @@ describe('Shared: DriveConstraints', function () {
|
|||||||
size: {
|
size: {
|
||||||
original: this.drive.size - 1,
|
original: this.drive.size - 1,
|
||||||
final: {
|
final: {
|
||||||
estimation: false
|
estimation: false,
|
||||||
|
value: this.drive.size - 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -966,10 +997,7 @@ describe('Shared: DriveConstraints', function () {
|
|||||||
|
|
||||||
describe('given there are no errors or warnings', () => {
|
describe('given there are no errors or warnings', () => {
|
||||||
it('should return an empty list', function () {
|
it('should return an empty list', function () {
|
||||||
const result = constraints.getDriveImageCompatibilityStatuses(this.drive, {
|
const result = constraints.getDriveImageCompatibilityStatuses(this.drive, this.image)
|
||||||
path: '/mnt/disk2/rpi.img',
|
|
||||||
size: 1000000000
|
|
||||||
})
|
|
||||||
|
|
||||||
m.chai.expect(result).to.deep.equal([])
|
m.chai.expect(result).to.deep.equal([])
|
||||||
})
|
})
|
||||||
@ -978,10 +1006,7 @@ describe('Shared: DriveConstraints', function () {
|
|||||||
describe('given the drive is disabled', () => {
|
describe('given the drive is disabled', () => {
|
||||||
it('should return an empty list', function () {
|
it('should return an empty list', function () {
|
||||||
this.drive.disabled = true
|
this.drive.disabled = true
|
||||||
const result = constraints.getDriveImageCompatibilityStatuses(this.drive, {
|
const result = constraints.getDriveImageCompatibilityStatuses(this.drive, this.image)
|
||||||
path: '/mnt/disk2/rpi.img',
|
|
||||||
size: 1000000000
|
|
||||||
})
|
|
||||||
|
|
||||||
const expectedTuples = []
|
const expectedTuples = []
|
||||||
expectStatusTypesAndMessagesToBe(result, expectedTuples)
|
expectStatusTypesAndMessagesToBe(result, expectedTuples)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user