mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-07 03:29:57 +00:00
Tests: improve reliability of os/configure.spec.ts
Change-type: patch
This commit is contained in:
parent
5b39878d54
commit
5d7d687d6c
@ -2,23 +2,30 @@ import { expect } from 'chai';
|
|||||||
import { promises as fs } from 'fs';
|
import { promises as fs } from 'fs';
|
||||||
import * as process from 'process';
|
import * as process from 'process';
|
||||||
import { runCommand } from '../../helpers';
|
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';
|
import { BalenaAPIMock } from '../../balena-api-mock';
|
||||||
|
|
||||||
if (process.platform !== 'win32') {
|
if (process.platform !== 'win32') {
|
||||||
describe('balena os configure', function () {
|
describe('balena os configure', function () {
|
||||||
let api: BalenaAPIMock;
|
let api: BalenaAPIMock;
|
||||||
|
let tmpPath: string;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
api = new BalenaAPIMock();
|
api = new BalenaAPIMock();
|
||||||
api.expectGetWhoAmI({ optional: true, persist: true });
|
api.expectGetWhoAmI({ optional: true, persist: true });
|
||||||
api.expectGetMixpanel({ optional: 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 () => {
|
afterEach(async () => {
|
||||||
api.done();
|
api.done();
|
||||||
await fs.unlink('/tmp/dummy.img');
|
await fs.unlink(tmpPath);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should inject a valid config.json file', async () => {
|
it('should inject a valid config.json file', async () => {
|
||||||
@ -28,7 +35,7 @@ if (process.platform !== 'win32') {
|
|||||||
api.expectApplicationProvisioning();
|
api.expectApplicationProvisioning();
|
||||||
|
|
||||||
const command: string[] = [
|
const command: string[] = [
|
||||||
'os configure /tmp/dummy.img',
|
`os configure ${tmpPath}`,
|
||||||
'--device-type raspberrypi3',
|
'--device-type raspberrypi3',
|
||||||
'--version 2.47.0+rev1',
|
'--version 2.47.0+rev1',
|
||||||
'--application testApp',
|
'--application testApp',
|
||||||
@ -43,7 +50,7 @@ if (process.platform !== 'win32') {
|
|||||||
// confirm the image contains a config.json...
|
// confirm the image contains a config.json...
|
||||||
const imagefs = await require('resin-image-fs');
|
const imagefs = await require('resin-image-fs');
|
||||||
const config = await imagefs.readFile({
|
const config = await imagefs.readFile({
|
||||||
image: '/tmp/dummy.img',
|
image: tmpPath,
|
||||||
partition: 1,
|
partition: 1,
|
||||||
path: '/config.json',
|
path: '/config.json',
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user