Reproducing #2220 in test cases

Change-type: patch

Signed-off-by: Harald Fischer <harald@balena.io>
This commit is contained in:
Harald Fischer 2023-04-14 16:02:21 +02:00
parent e8bc43dc64
commit 02171c7922

View File

@ -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');
});
});
}