Tests: improve reliability of os/configure.spec.ts

Change-type: patch
This commit is contained in:
Pagan Gazzard 2020-07-30 12:35:16 +01:00
parent 5b39878d54
commit 5d7d687d6c

View File

@ -2,23 +2,30 @@ import { expect } from 'chai';
import { promises as fs } from 'fs';
import * as process from 'process';
import { runCommand } from '../../helpers';
import { promisify } from 'bluebird';
import * as tmp from 'tmp';
tmp.setGracefulCleanup();
const tmpNameAsync = promisify(tmp.tmpName);
import { BalenaAPIMock } from '../../balena-api-mock';
if (process.platform !== 'win32') {
describe('balena os configure', function () {
let api: BalenaAPIMock;
let tmpPath: string;
beforeEach(async () => {
api = new BalenaAPIMock();
api.expectGetWhoAmI({ optional: true, persist: true });
api.expectGetMixpanel({ optional: true });
await fs.copyFile('./tests/test-data/dummy.img', '/tmp/dummy.img');
tmpPath = (await tmpNameAsync()) as string;
await fs.copyFile('./tests/test-data/dummy.img', tmpPath);
});
afterEach(async () => {
api.done();
await fs.unlink('/tmp/dummy.img');
await fs.unlink(tmpPath);
});
it('should inject a valid config.json file', async () => {
@ -28,7 +35,7 @@ if (process.platform !== 'win32') {
api.expectApplicationProvisioning();
const command: string[] = [
'os configure /tmp/dummy.img',
`os configure ${tmpPath}`,
'--device-type raspberrypi3',
'--version 2.47.0+rev1',
'--application testApp',
@ -43,7 +50,7 @@ if (process.platform !== 'win32') {
// confirm the image contains a config.json...
const imagefs = await require('resin-image-fs');
const config = await imagefs.readFile({
image: '/tmp/dummy.img',
image: tmpPath,
partition: 1,
path: '/config.json',
});