From df57ac4af3c1800ce3ae0f2dbdb6f67504c5f6de Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Mon, 8 Apr 2024 19:25:10 +0300 Subject: [PATCH] Update resin-device-operations to v2 Change-type: major --- package.json | 3 ++- tests/e2e.coffee | 57 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index d120617..40fdb59 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "balena-sdk": "^12.27.0", "coffeescript": "^1.12.7", "dotenv": "^4.0.0", + "etcher-sdk": "^9.0.8", "gulp": "^4.0.2", "gulp-coffee": "^2.3.5", "gulp-coffeelint": "^0.5.0", @@ -50,7 +51,7 @@ "bluebird": "^3.7.2", "lodash": "^4.17.15", "reconfix": "1.0.0-v0-1-0-fork-46760acff4d165f5238bfac5e464256ef1944476", - "resin-device-operations": "^1.7.0", + "resin-device-operations": "^2.0.0", "rindle": "^1.3.4", "string-to-stream": "^1.1.1" } diff --git a/tests/e2e.coffee b/tests/e2e.coffee index ef937f0..102d6d4 100644 --- a/tests/e2e.coffee +++ b/tests/e2e.coffee @@ -7,6 +7,7 @@ fs = Promise.promisifyAll(require('fs')) wary = require('wary') settings = require('balena-settings-client') +etcherSdk = require('etcher-sdk') sdk = require('balena-sdk')({ apiUrl: settings.get('apiUrl') }) @@ -170,14 +171,52 @@ wary.it 'should not trigger a state event when configuring a raspberry pi', .then -> m.chai.expect(spy).to.not.have.been.called +mockBlockDeviceFromFile = (path) -> + drive = { + raw: path, + device: path, + devicePath: path, + displayName: path, + icon: 'some icon', + isSystem: false, + description: 'some description', + mountpoints: [], + size: fs.statSync(path).size, + isReadOnly: false, + busType: 'UNKNOWN', + error: null, + blockSize: 512, + busVersion: null, + enumerator: 'fake', + isCard: null, + isRemovable: true, + isSCSI: false, + isUAS: null, + isUSB: true, + isVirtual: false, + logicalBlockSize: 512, + partitionTableType: null, + }; + device = new etcherSdk.sourceDestination.BlockDevice({ + drive, + unmountOnSuccess: false, + write: true, + direct: false, + }) + + device._open = () -> + etcherSdk.sourceDestination.File.prototype._open.call(device) + device._close = () -> + etcherSdk.sourceDestination.File.prototype._close.call(device) + + device + wary.it 'should initialize a raspberry pi image', raspberrypi: RASPBERRYPI_OS1 random: RANDOM , (images) -> - drive = - raw: images.random - size: fs.statSync(images.random).size + drive = mockBlockDeviceFromFile(images.random) sdk.models.device.get(DEVICES.raspberrypi.id).then (device) -> getManifest(device.device_type).then (manifest) -> @@ -196,9 +235,7 @@ wary.it 'should initialize a raspberry pi image containing a device type', random: RANDOM , (images) -> - drive = - raw: images.random - size: fs.statSync(images.random).size + drive = mockBlockDeviceFromFile(images.random) sdk.models.device.get(DEVICES.raspberrypi.id).then (device) -> # make sure the device-type.json file is read from the image @@ -218,9 +255,7 @@ wary.it 'should emit state events when initializing a raspberry pi', random: RANDOM , (images) -> - drive = - raw: images.random - size: fs.statSync(images.random).size + drive = mockBlockDeviceFromFile(images.random) spy = m.sinon.spy() @@ -243,9 +278,7 @@ wary.it 'should emit burn events when initializing a raspberry pi', random: RANDOM , (images) -> - drive = - raw: images.random - size: fs.statSync(images.random).size + drive = mockBlockDeviceFromFile(images.random) spy = m.sinon.spy()