From 02171c7922359a904b303915490016372b0fa878 Mon Sep 17 00:00:00 2001 From: Harald Fischer Date: Fri, 14 Apr 2023 16:02:21 +0200 Subject: [PATCH] Reproducing #2220 in test cases Change-type: patch Signed-off-by: Harald Fischer --- tests/commands/os/configure.spec.ts | 49 ++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/tests/commands/os/configure.spec.ts b/tests/commands/os/configure.spec.ts index 72688feebf..c2d501b7d5 100644 --- a/tests/commands/os/configure.spec.ts +++ b/tests/commands/os/configure.spec.ts @@ -28,7 +28,7 @@ const tmpNameAsync = promisify(tmp.tmpName); import { BalenaAPIMock } from '../../nock/balena-api-mock'; if (process.platform !== 'win32') { - describe('balena os configure', function () { + describe.only('balena os configure', function () { let api: BalenaAPIMock; let tmpPath: string; @@ -77,5 +77,52 @@ if (process.platform !== 'win32') { expect(configObj).to.have.property('deviceType', 'raspberrypi3'); expect(configObj).to.have.property('initialDeviceName', 'testDeviceName'); }); + + it('should inject a valid config.json file on top of an already configured one', async () => { + api.expectGetApplication(); + api.expectGetConfigDeviceTypes(); + api.expectDownloadConfig(); + + const command: string[] = [ + `os configure ${tmpPath}`, + '--device-type raspberrypi3', + '--version 2.47.0+rev1', + '--fleet testApp', + '--config-app-update-poll-interval 10', + '--config-network ethernet', + '--initial-device-name otherTestDeviceName', + '--provisioning-key-name testKey', + '--provisioning-key-expiry-date 2050-12-12', + ]; + + const { err } = await runCommand(command.join(' ')); + expect(err.join('')).to.equal(''); + const command2: string[] = [ + `os configure ${tmpPath}`, + '--device-type raspberrypi3', + '--version 2.47.0+rev1', + '--fleet testApp', + '--config-app-update-poll-interval 10', + '--config-network ethernet', + '--initial-device-name testDeviceName', + '--provisioning-key-name testKey', + '--provisioning-key-expiry-date 2050-12-12', + ]; + + const { err: err2 } = await runCommand(command2.join(' ')); + expect(err2.join('')).to.equal(''); + + // confirm the image contains a config.json... + const imagefs = await import('balena-image-fs'); + const config = await imagefs.interact(tmpPath, 1, async (_fs) => { + return await promisify(_fs.readFile)('/config.json'); + }); + expect(config).to.not.be.empty; + + // confirm the image has the correct config.json values... + const configObj = JSON.parse(config.toString('utf8')); + expect(configObj).to.have.property('deviceType', 'raspberrypi3'); + expect(configObj).to.have.property('initialDeviceName', 'testDeviceName'); + }); }); }