2021-05-14 23:58:15 +00:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright 2020-2021 Balena Ltd.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-06-11 11:32:20 +00:00
|
|
|
import { expect } from 'chai';
|
2020-06-23 10:57:57 +00:00
|
|
|
import { promises as fs } from 'fs';
|
2020-06-11 11:32:20 +00:00
|
|
|
import * as process from 'process';
|
|
|
|
import { runCommand } from '../../helpers';
|
2021-01-21 19:27:07 +00:00
|
|
|
import { promisify } from 'util';
|
2020-07-30 11:35:16 +00:00
|
|
|
import * as tmp from 'tmp';
|
|
|
|
|
|
|
|
tmp.setGracefulCleanup();
|
|
|
|
const tmpNameAsync = promisify(tmp.tmpName);
|
2020-06-11 11:32:20 +00:00
|
|
|
|
|
|
|
import { BalenaAPIMock } from '../../balena-api-mock';
|
|
|
|
|
|
|
|
if (process.platform !== 'win32') {
|
2020-06-15 22:53:07 +00:00
|
|
|
describe('balena os configure', function () {
|
2020-06-11 11:32:20 +00:00
|
|
|
let api: BalenaAPIMock;
|
2020-07-30 11:35:16 +00:00
|
|
|
let tmpPath: string;
|
2020-06-11 11:32:20 +00:00
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
api = new BalenaAPIMock();
|
|
|
|
api.expectGetWhoAmI({ optional: true, persist: true });
|
|
|
|
api.expectGetMixpanel({ optional: true });
|
2020-07-30 11:35:16 +00:00
|
|
|
tmpPath = (await tmpNameAsync()) as string;
|
|
|
|
await fs.copyFile('./tests/test-data/dummy.img', tmpPath);
|
2020-06-11 11:32:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
api.done();
|
2020-07-30 11:35:16 +00:00
|
|
|
await fs.unlink(tmpPath);
|
2020-06-11 11:32:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should inject a valid config.json file', async () => {
|
|
|
|
api.expectGetApplication();
|
2021-05-14 23:58:15 +00:00
|
|
|
api.expectGetConfigDeviceTypes();
|
2020-06-11 11:32:20 +00:00
|
|
|
api.expectDownloadConfig();
|
|
|
|
api.expectApplicationProvisioning();
|
|
|
|
|
|
|
|
const command: string[] = [
|
2020-07-30 11:35:16 +00:00
|
|
|
`os configure ${tmpPath}`,
|
2020-06-11 11:32:20 +00:00
|
|
|
'--device-type raspberrypi3',
|
|
|
|
'--version 2.47.0+rev1',
|
|
|
|
'--application testApp',
|
|
|
|
'--config-app-update-poll-interval 10',
|
|
|
|
'--config-network ethernet',
|
|
|
|
'--initial-device-name testDeviceName',
|
|
|
|
];
|
|
|
|
|
|
|
|
const { err } = await runCommand(command.join(' '));
|
|
|
|
expect(err.join('')).to.equal('');
|
|
|
|
|
|
|
|
// confirm the image contains a config.json...
|
2021-01-21 19:27:07 +00:00
|
|
|
const imagefs = await import('balena-image-fs');
|
|
|
|
const config = await imagefs.interact(tmpPath, 1, async (_fs) => {
|
|
|
|
return await promisify(_fs.readFile)('/config.json');
|
2020-06-11 11:32:20 +00:00
|
|
|
});
|
|
|
|
expect(config).to.not.be.empty;
|
|
|
|
|
|
|
|
// confirm the image has the correct config.json values...
|
2021-01-21 19:27:07 +00:00
|
|
|
const configObj = JSON.parse(config.toString('utf8'));
|
2020-06-11 11:32:20 +00:00
|
|
|
expect(configObj).to.have.property('deviceType', 'raspberrypi3');
|
|
|
|
expect(configObj).to.have.property('initialDeviceName', 'testDeviceName');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|