Skip to content

Commit

Permalink
Update resin-device-operations to v2
Browse files Browse the repository at this point in the history
Change-type: major
  • Loading branch information
thgreasi committed Apr 9, 2024
1 parent 65a1372 commit df57ac4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
Expand Down
57 changes: 45 additions & 12 deletions tests/e2e.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
Expand Down Expand Up @@ -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) ->
Expand All @@ -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
Expand All @@ -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()

Expand All @@ -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()

Expand Down

0 comments on commit df57ac4

Please sign in to comment.