Remove remaining v12 switches

Change-type: patch
Signed-off-by: Scott Lowe <scott@balena.io>
This commit is contained in:
Scott Lowe 2020-12-07 14:58:23 +01:00
parent ad16c5270e
commit 3edf7a038f
8 changed files with 212 additions and 509 deletions

View File

@ -19,7 +19,6 @@ import { flags } from '@oclif/command';
import Command from '../command'; import Command from '../command';
import * as cf from '../utils/common-flags'; import * as cf from '../utils/common-flags';
import { getBalenaSdk, getVisuals, stripIndent } from '../utils/lazy'; import { getBalenaSdk, getVisuals, stripIndent } from '../utils/lazy';
import { isV12 } from '../utils/version';
interface ExtendedApplication extends ApplicationWithDeviceType { interface ExtendedApplication extends ApplicationWithDeviceType {
device_count?: number; device_count?: number;
@ -49,9 +48,7 @@ export default class AppsCmd extends Command {
verbose: flags.boolean({ verbose: flags.boolean({
default: false, default: false,
char: 'v', char: 'v',
description: isV12() description: 'No-op since release v12.0.0',
? 'No-op since release v12.0.0'
: 'add extra columns in the tabular output (SLUG)',
}), }),
}; };
@ -88,7 +85,7 @@ export default class AppsCmd extends Command {
getVisuals().table.horizontal(applications, [ getVisuals().table.horizontal(applications, [
'id', 'id',
'app_name', 'app_name',
options.verbose || isV12() ? 'slug' : '', options.verbose || 'slug',
'device_type', 'device_type',
'online_devices', 'online_devices',
'device_count', 'device_count',

View File

@ -22,11 +22,9 @@ import Command from '../command';
import { ExpectedError } from '../errors'; import { ExpectedError } from '../errors';
import * as cf from '../utils/common-flags'; import * as cf from '../utils/common-flags';
import { getBalenaSdk, getVisuals, stripIndent } from '../utils/lazy'; import { getBalenaSdk, getVisuals, stripIndent } from '../utils/lazy';
import { CommandHelp } from '../utils/oclif-utils'; import { isV13 } from '../utils/version';
import { isV12 } from '../utils/version';
interface FlagsDef { interface FlagsDef {
all?: boolean; // whether to include application-wide, device-wide variables //TODO: REMOVE
application?: string; // application name application?: string; // application name
config: boolean; config: boolean;
device?: string; // device UUID device?: string; // device UUID
@ -57,8 +55,7 @@ interface ServiceEnvironmentVariableInfo
} }
export default class EnvsCmd extends Command { export default class EnvsCmd extends Command {
public static description = isV12() public static description = stripIndent`
? stripIndent`
List the environment or config variables of an application, device or service. List the environment or config variables of an application, device or service.
List the environment or configuration variables of an application, device or List the environment or configuration variables of an application, device or
@ -81,42 +78,6 @@ export default class EnvsCmd extends Command {
by the user. The --config and the --service options are mutually exclusive by the user. The --config and the --service options are mutually exclusive
because configuration variables cannot be set for specific services. because configuration variables cannot be set for specific services.
The --json option is recommended when scripting the output of this command,
because the JSON format is less likely to change and it better represents data
types like lists and empty strings. The 'jq' utility may be helpful in shell
scripts (https://stedolan.github.io/jq/manual/). When --json is used, an empty
JSON array ([]) is printed instead of an error message when no variables exist
for the given query. When querying variables for a device, note that the
application name may be null in JSON output (or 'N/A' in tabular output) if the
application linked to the device is no longer accessible by the current user
(for example, in case the current user has been removed from the application
by its owner).
`
: stripIndent`
List the environment or config variables of an application, device or service.
List the environment or configuration variables of an application, device or
service, as selected by the respective command-line options. (A service is
an application container in a "microservices" application.)
The --config option is used to list "configuration variables" that control
balena platform features, as opposed to custom environment variables defined
by the user. The --config and the --service options are mutually exclusive
because configuration variables cannot be set for specific services.
The --all option is used to include application-wide (fleet), device-wide
(multiple services on a device) and service-specific variables that apply to
the selected application, device or service. It can be thought of as including
"inherited" variables: for example, a service inherits device-wide variables,
and a device inherits application-wide variables. Variables are still filtered
out by type with the --config option, such that configuration and non-
configuration variables are never listed together.
When the --all option is used, the printed output may include DEVICE and/or
SERVICE columns to distinguish between application-wide, device-specific and
service-specific variables. An asterisk in these columns indicates that the
variable applies to "all devices" or "all services".
The --json option is recommended when scripting the output of this command, The --json option is recommended when scripting the output of this command,
because the JSON format is less likely to change and it better represents data because the JSON format is less likely to change and it better represents data
types like lists and empty strings. The 'jq' utility may be helpful in shell types like lists and empty strings. The 'jq' utility may be helpful in shell
@ -128,52 +89,32 @@ export default class EnvsCmd extends Command {
(for example, in case the current user has been removed from the application (for example, in case the current user has been removed from the application
by its owner). by its owner).
`; `;
public static examples = isV12() public static examples = [
? [ '$ balena envs --application MyApp',
'$ balena envs --application MyApp', '$ balena envs --application MyApp --json',
'$ balena envs --application MyApp --json', '$ balena envs --application MyApp --service MyService',
'$ balena envs --application MyApp --service MyService', '$ balena envs --application MyApp --service MyService',
'$ balena envs --application MyApp --service MyService', '$ balena envs --application MyApp --config',
'$ balena envs --application MyApp --config', '$ balena envs --device 7cf02a6',
'$ balena envs --device 7cf02a6', '$ balena envs --device 7cf02a6 --json',
'$ balena envs --device 7cf02a6 --json', '$ balena envs --device 7cf02a6 --config --json',
'$ balena envs --device 7cf02a6 --config --json', '$ balena envs --device 7cf02a6 --service MyService',
'$ balena envs --device 7cf02a6 --service MyService', ];
]
: [
'$ balena envs --application MyApp',
'$ balena envs --application MyApp --all --json',
'$ balena envs --application MyApp --service MyService',
'$ balena envs --application MyApp --all --service MyService',
'$ balena envs --application MyApp --config',
'$ balena envs --device 7cf02a6',
'$ balena envs --device 7cf02a6 --all --json',
'$ balena envs --device 7cf02a6 --config --all --json',
'$ balena envs --device 7cf02a6 --all --service MyService',
];
public static usage = ( public static usage = 'envs';
'envs ' + new CommandHelp({ args: EnvsCmd.args }).defaultUsage()
).trim();
public static flags: flags.Input<FlagsDef> = { public static flags: flags.Input<FlagsDef> = {
...(isV12() ...(isV13()
? { ? {}
: {
all: flags.boolean({ all: flags.boolean({
default: false, default: false,
description: stripIndent` description: stripIndent`
No-op since balena CLI v12.0.0.`, No-op since balena CLI v12.0.0.`,
hidden: true, hidden: true,
}), }),
}
: {
all: flags.boolean({
default: false,
description: stripIndent`
include app-wide, device-wide variables that apply to the selected device or service.
Variables are still filtered out by type with the --config option.`,
}),
}), }),
application: { exclusive: ['device'], ...cf.application }, application: { exclusive: ['device'], ...cf.application },
config: flags.boolean({ config: flags.boolean({
default: false, default: false,
@ -196,8 +137,6 @@ export default class EnvsCmd extends Command {
const { flags: options } = this.parse<FlagsDef, {}>(EnvsCmd); const { flags: options } = this.parse<FlagsDef, {}>(EnvsCmd);
const variables: EnvironmentVariableInfo[] = []; const variables: EnvironmentVariableInfo[] = [];
options.all = options.all || isV12();
await Command.checkLoggedIn(); await Command.checkLoggedIn();
if (!options.application && !options.device) { if (!options.application && !options.device) {
@ -225,9 +164,7 @@ export default class EnvsCmd extends Command {
if (appName && options.service) { if (appName && options.service) {
await validateServiceName(balena, options.service, appName); await validateServiceName(balena, options.service, appName);
} }
if (options.application || options.all) { variables.push(...(await getAppVars(balena, appName, options)));
variables.push(...(await getAppVars(balena, appName, options)));
}
if (fullUUID) { if (fullUUID) {
variables.push( variables.push(
...(await getDeviceVars(balena, fullUUID, appName, options)), ...(await getDeviceVars(balena, fullUUID, appName, options)),
@ -251,20 +188,18 @@ export default class EnvsCmd extends Command {
) { ) {
const fields = ['id', 'name', 'value']; const fields = ['id', 'name', 'value'];
if (options.all) { // Replace undefined app names with 'N/A' or null
// Replace undefined app names with 'N/A' or null varArray = varArray.map((i: EnvironmentVariableInfo) => {
varArray = varArray.map((i: EnvironmentVariableInfo) => { i.appName = i.appName || (options.json ? null : 'N/A');
i.appName = i.appName || (options.json ? null : 'N/A'); return i;
return i; });
});
fields.push(options.json ? 'appName' : 'appName => APPLICATION'); fields.push(options.json ? 'appName' : 'appName => APPLICATION');
if (options.device) { if (options.device) {
fields.push(options.json ? 'deviceUUID' : 'deviceUUID => DEVICE'); fields.push(options.json ? 'deviceUUID' : 'deviceUUID => DEVICE');
} }
if (!options.config) { if (!options.config) {
fields.push(options.json ? 'serviceName' : 'serviceName => SERVICE'); fields.push(options.json ? 'serviceName' : 'serviceName => SERVICE');
}
} }
if (options.json) { if (options.json) {
@ -313,14 +248,12 @@ async function getAppVars(
if (!appName) { if (!appName) {
return appVars; return appVars;
} }
if (options.config || options.all || !options.service) { const vars = await sdk.models.application[
const vars = await sdk.models.application[ options.config ? 'configVar' : 'envVar'
options.config ? 'configVar' : 'envVar' ].getAllByApplication(appName);
].getAllByApplication(appName); fillInInfoFields(vars, appName);
fillInInfoFields(vars, appName); appVars.push(...vars);
appVars.push(...vars); if (!options.config) {
}
if (!options.config && (options.service || options.all)) {
const pineOpts: SDK.PineOptions<SDK.ServiceEnvironmentVariable> = { const pineOpts: SDK.PineOptions<SDK.ServiceEnvironmentVariable> = {
$expand: { $expand: {
service: {}, service: {},
@ -362,35 +295,32 @@ async function getDeviceVars(
fillInInfoFields(deviceConfigVars, appName, printedUUID); fillInInfoFields(deviceConfigVars, appName, printedUUID);
deviceVars.push(...deviceConfigVars); deviceVars.push(...deviceConfigVars);
} else { } else {
if (options.service || options.all) { const pineOpts: SDK.PineOptions<SDK.DeviceServiceEnvironmentVariable> = {
const pineOpts: SDK.PineOptions<SDK.DeviceServiceEnvironmentVariable> = { $expand: {
$expand: { service_install: {
service_install: { $expand: 'installs__service',
$expand: 'installs__service', },
}, },
};
if (options.service) {
pineOpts.$filter = {
service_install: {
installs__service: { service_name: options.service },
}, },
}; };
if (options.service) {
pineOpts.$filter = {
service_install: {
installs__service: { service_name: options.service },
},
};
}
const deviceServiceVars = await sdk.models.device.serviceVar.getAllByDevice(
fullUUID,
pineOpts,
);
fillInInfoFields(deviceServiceVars, appName, printedUUID);
deviceVars.push(...deviceServiceVars);
}
if (!options.service || options.all) {
const deviceEnvVars = await sdk.models.device.envVar.getAllByDevice(
fullUUID,
);
fillInInfoFields(deviceEnvVars, appName, printedUUID);
deviceVars.push(...deviceEnvVars);
} }
const deviceServiceVars = await sdk.models.device.serviceVar.getAllByDevice(
fullUUID,
pineOpts,
);
fillInInfoFields(deviceServiceVars, appName, printedUUID);
deviceVars.push(...deviceServiceVars);
const deviceEnvVars = await sdk.models.device.envVar.getAllByDevice(
fullUUID,
);
fillInInfoFields(deviceEnvVars, appName, printedUUID);
deviceVars.push(...deviceEnvVars);
} }
return deviceVars; return deviceVars;
} }

View File

@ -22,7 +22,6 @@ import * as cf from '../utils/common-flags';
import { getBalenaSdk, getVisuals, stripIndent } from '../utils/lazy'; import { getBalenaSdk, getVisuals, stripIndent } from '../utils/lazy';
import { disambiguateReleaseParam } from '../utils/normalization'; import { disambiguateReleaseParam } from '../utils/normalization';
import { tryAsInteger } from '../utils/validation'; import { tryAsInteger } from '../utils/validation';
import { isV12 } from '../utils/version';
interface FlagsDef { interface FlagsDef {
application?: string; application?: string;
@ -110,11 +109,7 @@ export default class TagsCmd extends Command {
throw new ExpectedError('No tags found'); throw new ExpectedError('No tags found');
} }
console.log( console.log(getVisuals().table.horizontal(tags, ['tag_key', 'value']));
isV12()
? getVisuals().table.horizontal(tags, ['tag_key', 'value'])
: getVisuals().table.horizontal(tags, ['id', 'tag_key', 'value']),
);
} }
protected missingResourceMessage = stripIndent` protected missingResourceMessage = stripIndent`

View File

@ -1128,15 +1128,10 @@ export async function validateProjectDirectory(
checkCompose(path.join(opts.projectPath, '..')), checkCompose(path.join(opts.projectPath, '..')),
]); ]);
if (!hasCompose && hasParentCompose) { if (!hasCompose && hasParentCompose) {
const { isV12 } = await import('./version');
const msg = stripIndent` const msg = stripIndent`
"docker-compose.y[a]ml" file found in parent directory: please check that "docker-compose.y[a]ml" file found in parent directory: please check that
the correct source folder was specified. (Suppress with '--noparent-check'.)`; the correct source folder was specified. (Suppress with '--noparent-check'.)`;
if (isV12()) { throw new ExpectedError(`Error: ${msg}`);
throw new ExpectedError(`Error: ${msg}`);
} else {
Logger.getLogger().logWarn(msg);
}
} }
} }
} }

View File

@ -17,7 +17,6 @@
import { promises as fs } from 'fs'; import { promises as fs } from 'fs';
import Logger = require('./logger'); import Logger = require('./logger');
import { isV12 } from './version';
const globalLogger = Logger.getLogger(); const globalLogger = Logger.getLogger();
@ -111,9 +110,7 @@ export async function readFileWithEolConversion(
); );
// And summary warning later // And summary warning later
globalLogger.deferredLog( globalLogger.deferredLog(
isV12() 'Windows-format line endings were detected in some files, but were not converted due to `--noconvert-eol` option.',
? 'Windows-format line endings were detected in some files, but were not converted due to `--noconvert-eol` option.'
: 'Windows-format line endings were detected in some files. Consider using the `--convert-eol` option.',
Logger.Level.WARN, Logger.Level.WARN,
); );

View File

@ -22,13 +22,12 @@ export function isVersionGTE(v: string): boolean {
return semver.gte(process.env.BALENA_CLI_VERSION_OVERRIDE || version, v); return semver.gte(process.env.BALENA_CLI_VERSION_OVERRIDE || version, v);
} }
let v12: boolean; let v13: boolean;
export function isV12(): boolean { /** Feature switch for the next major version of the CLI */
if (v12 === undefined) { export function isV13(): boolean {
// This is the `Change-type: major` PR that will produce v12.0.0. if (v13 === undefined) {
// Enable the v12 feature switches and run all v12 tests. v13 = isVersionGTE('13.0.0');
v12 = true; // v12 = isVersionGTE('12.0.0');
} }
return v12; return v13;
} }

View File

@ -17,7 +17,6 @@
import { expect } from 'chai'; import { expect } from 'chai';
import { isV12 } from '../../../build/utils/version';
import { BalenaAPIMock } from '../../balena-api-mock'; import { BalenaAPIMock } from '../../balena-api-mock';
import { cleanOutput, runCommand } from '../../helpers'; import { cleanOutput, runCommand } from '../../helpers';
@ -50,9 +49,7 @@ describe('balena devices supported', function () {
const lines = cleanOutput(out); const lines = cleanOutput(out);
expect(lines[0].replace(/ +/g, ' ')).to.equal( expect(lines[0].replace(/ +/g, ' ')).to.equal('SLUG ALIASES ARCH NAME');
isV12() ? 'SLUG ALIASES ARCH NAME' : 'SLUG NAME',
);
expect(lines).to.have.lengthOf.at.least(2); expect(lines).to.have.lengthOf.at.least(2);
// Discontinued devices should be filtered out from results // Discontinued devices should be filtered out from results

View File

@ -18,7 +18,6 @@
import { expect } from 'chai'; import { expect } from 'chai';
import { stripIndent } from '../../../lib/utils/lazy'; import { stripIndent } from '../../../lib/utils/lazy';
import { isV12 } from '../../../lib/utils/version';
import { BalenaAPIMock } from '../../balena-api-mock'; import { BalenaAPIMock } from '../../balena-api-mock';
import { runCommand } from '../../helpers'; import { runCommand } from '../../helpers';
@ -43,38 +42,22 @@ describe('balena envs', function () {
}); });
it('should successfully list env vars for a test app', async () => { it('should successfully list env vars for a test app', async () => {
if (isV12()) { api.expectGetApplication();
api.expectGetApplication(); api.expectGetAppEnvVars();
api.expectGetAppEnvVars(); api.expectGetAppServiceVars();
api.expectGetAppServiceVars();
const { out, err } = await runCommand(`envs -a ${appName}`); const { out, err } = await runCommand(`envs -a ${appName}`);
expect(out.join('')).to.equal( expect(out.join('')).to.equal(
stripIndent` stripIndent`
ID NAME VALUE APPLICATION SERVICE ID NAME VALUE APPLICATION SERVICE
120110 svar1 svar1-value test service1 120110 svar1 svar1-value test service1
120111 svar2 svar2-value test service2 120111 svar2 svar2-value test service2
120101 var1 var1-val test * 120101 var1 var1-val test *
120102 var2 22 test * 120102 var2 22 test *
` + '\n', ` + '\n',
); );
expect(err.join('')).to.equal(''); expect(err.join('')).to.equal('');
} else {
api.expectGetApplication();
api.expectGetAppEnvVars();
const { out, err } = await runCommand(`envs -a ${appName}`);
expect(out.join('')).to.equal(
stripIndent`
ID NAME VALUE
120101 var1 var1-val
120102 var2 22
` + '\n',
);
expect(err.join('')).to.equal('');
}
}); });
it('should successfully list config vars for a test app', async () => { it('should successfully list config vars for a test app', async () => {
@ -83,21 +66,12 @@ describe('balena envs', function () {
const { out, err } = await runCommand(`envs -a ${appName} --config`); const { out, err } = await runCommand(`envs -a ${appName} --config`);
if (isV12()) { expect(out.join('')).to.equal(
expect(out.join('')).to.equal( stripIndent`
stripIndent` ID NAME VALUE APPLICATION
ID NAME VALUE APPLICATION 120300 RESIN_SUPERVISOR_NATIVE_LOGGER false test
120300 RESIN_SUPERVISOR_NATIVE_LOGGER false test ` + '\n',
` + '\n', );
);
} else {
expect(out.join('')).to.equal(
stripIndent`
ID NAME VALUE
120300 RESIN_SUPERVISOR_NATIVE_LOGGER false
` + '\n',
);
}
expect(err.join('')).to.equal(''); expect(err.join('')).to.equal('');
}); });
@ -108,24 +82,14 @@ describe('balena envs', function () {
const { out, err } = await runCommand(`envs -cja ${appName}`); const { out, err } = await runCommand(`envs -cja ${appName}`);
if (isV12()) { expect(JSON.parse(out.join(''))).to.deep.equal([
expect(JSON.parse(out.join(''))).to.deep.equal([ {
{ appName: 'test',
appName: 'test', id: 120300,
id: 120300, name: 'RESIN_SUPERVISOR_NATIVE_LOGGER',
name: 'RESIN_SUPERVISOR_NATIVE_LOGGER', value: 'false',
value: 'false', },
}, ]);
]);
} else {
expect(JSON.parse(out.join(''))).to.deep.equal([
{
id: 120300,
name: 'RESIN_SUPERVISOR_NATIVE_LOGGER',
value: 'false',
},
]);
}
expect(err.join('')).to.equal(''); expect(err.join('')).to.equal('');
}); });
@ -133,138 +97,70 @@ describe('balena envs', function () {
const serviceName = 'service2'; const serviceName = 'service2';
api.expectGetService({ serviceName }); api.expectGetService({ serviceName });
api.expectGetApplication(); api.expectGetApplication();
if (isV12()) { api.expectGetAppEnvVars();
api.expectGetAppEnvVars();
}
api.expectGetAppServiceVars(); api.expectGetAppServiceVars();
const { out, err } = await runCommand( const { out, err } = await runCommand(
`envs -a ${appName} -s ${serviceName}`, `envs -a ${appName} -s ${serviceName}`,
); );
if (isV12()) { expect(out.join('')).to.equal(
expect(out.join('')).to.equal( stripIndent`
stripIndent` ID NAME VALUE APPLICATION SERVICE
ID NAME VALUE APPLICATION SERVICE 120111 svar2 svar2-value test service2
120111 svar2 svar2-value test service2 120101 var1 var1-val test *
120101 var1 var1-val test * 120102 var2 22 test *
120102 var2 22 test * ` + '\n',
` + '\n', );
);
} else {
expect(out.join('')).to.equal(
stripIndent`
ID NAME VALUE
120111 svar2 svar2-value
` + '\n',
);
}
expect(err.join('')).to.equal(''); expect(err.join('')).to.equal('');
}); });
if (!isV12()) { it('should successfully list env and service vars for a test app (-s flags)', async () => {
it('should produce an empty JSON array when no app service variables exist', async () => { const serviceName = 'service1';
const serviceName = 'nono'; api.expectGetService({ serviceName });
api.expectGetService({ serviceName }); api.expectGetApplication();
api.expectGetApplication(); api.expectGetAppEnvVars();
api.expectGetAppServiceVars(); api.expectGetAppServiceVars();
const { out, err } = await runCommand( const { out, err } = await runCommand(
`envs -a ${appName} -s ${serviceName} -j`, `envs -a ${appName} -s ${serviceName}`,
); );
expect(out.join('')).to.equal('[]\n'); expect(out.join('')).to.equal(
expect(err.join('')).to.equal(''); stripIndent`
});
}
if (!isV12()) {
it('should successfully list env and service vars for a test app (--all flag)', async () => {
api.expectGetApplication();
api.expectGetAppEnvVars();
api.expectGetAppServiceVars();
const { out, err } = await runCommand(`envs -a ${appName} --all`);
expect(out.join('')).to.equal(
stripIndent`
ID NAME VALUE APPLICATION SERVICE
120110 svar1 svar1-value test service1
120111 svar2 svar2-value test service2
120101 var1 var1-val test *
120102 var2 22 test *
` + '\n',
);
expect(err.join('')).to.equal('');
});
}
it(
isV12()
? 'should successfully list env and service vars for a test app (-s flags)'
: 'should successfully list env and service vars for a test app (--all -s flags)',
async () => {
const serviceName = 'service1';
api.expectGetService({ serviceName });
api.expectGetApplication();
api.expectGetAppEnvVars();
api.expectGetAppServiceVars();
const { out, err } = await runCommand(
isV12()
? `envs -a ${appName} -s ${serviceName}`
: `envs -a ${appName} --all -s ${serviceName}`,
);
expect(out.join('')).to.equal(
stripIndent`
ID NAME VALUE APPLICATION SERVICE ID NAME VALUE APPLICATION SERVICE
120110 svar1 svar1-value test ${serviceName} 120110 svar1 svar1-value test ${serviceName}
120101 var1 var1-val test * 120101 var1 var1-val test *
120102 var2 22 test * 120102 var2 22 test *
` + '\n', ` + '\n',
); );
expect(err.join('')).to.equal(''); expect(err.join('')).to.equal('');
}, });
);
it('should successfully list env variables for a test device', async () => { it('should successfully list env variables for a test device', async () => {
api.expectGetDevice({ fullUUID }); api.expectGetDevice({ fullUUID });
api.expectGetDeviceEnvVars(); api.expectGetDeviceEnvVars();
if (isV12()) { api.expectGetApplication();
api.expectGetApplication(); api.expectGetAppEnvVars();
api.expectGetAppEnvVars(); api.expectGetAppServiceVars();
api.expectGetAppServiceVars(); api.expectGetDeviceServiceVars();
api.expectGetDeviceServiceVars();
}
const uuid = shortUUID; const uuid = shortUUID;
const { out, err } = await runCommand(`envs -d ${uuid}`); const { out, err } = await runCommand(`envs -d ${uuid}`);
if (isV12()) { expect(out.join('')).to.equal(
expect(out.join('')).to.equal( stripIndent`
stripIndent` ID NAME VALUE APPLICATION DEVICE SERVICE
ID NAME VALUE APPLICATION DEVICE SERVICE 120110 svar1 svar1-value test * service1
120110 svar1 svar1-value test * service1 120111 svar2 svar2-value test * service2
120111 svar2 svar2-value test * service2 120120 svar3 svar3-value test ${uuid} service1
120120 svar3 svar3-value test ${uuid} service1 120121 svar4 svar4-value test ${uuid} service2
120121 svar4 svar4-value test ${uuid} service2 120101 var1 var1-val test * *
120101 var1 var1-val test * * 120102 var2 22 test * *
120102 var2 22 test * * 120203 var3 var3-val test ${uuid} *
120203 var3 var3-val test ${uuid} * 120204 var4 44 test ${uuid} *
120204 var4 44 test ${uuid} * ` + '\n',
` + '\n', );
);
} else {
expect(out.join('')).to.equal(
stripIndent`
ID NAME VALUE
120203 var3 var3-val
120204 var4 44
` + '\n',
);
}
expect(err.join('')).to.equal(''); expect(err.join('')).to.equal('');
}); });
@ -272,42 +168,25 @@ describe('balena envs', function () {
it('should successfully list env variables for a test device (JSON output)', async () => { it('should successfully list env variables for a test device (JSON output)', async () => {
api.expectGetDevice({ fullUUID }); api.expectGetDevice({ fullUUID });
api.expectGetDeviceEnvVars(); api.expectGetDeviceEnvVars();
if (isV12()) { api.expectGetApplication();
api.expectGetApplication(); api.expectGetAppEnvVars();
api.expectGetAppEnvVars(); api.expectGetAppServiceVars();
api.expectGetAppServiceVars(); api.expectGetDeviceServiceVars();
api.expectGetDeviceServiceVars();
}
const { out, err } = await runCommand(`envs -jd ${shortUUID}`); const { out, err } = await runCommand(`envs -jd ${shortUUID}`);
if (isV12()) { expect(JSON.parse(out.join(''))).to.deep.equal(
expect(JSON.parse(out.join(''))).to.deep.equal( JSON.parse(`[
JSON.parse(`[ { "id": 120101, "appName": "test", "deviceUUID": "*", "name": "var1", "value": "var1-val", "serviceName": "*" },
{ "id": 120101, "appName": "test", "deviceUUID": "*", "name": "var1", "value": "var1-val", "serviceName": "*" }, { "id": 120102, "appName": "test", "deviceUUID": "*", "name": "var2", "value": "22", "serviceName": "*" },
{ "id": 120102, "appName": "test", "deviceUUID": "*", "name": "var2", "value": "22", "serviceName": "*" }, { "id": 120110, "appName": "test", "deviceUUID": "*", "name": "svar1", "value": "svar1-value", "serviceName": "service1" },
{ "id": 120110, "appName": "test", "deviceUUID": "*", "name": "svar1", "value": "svar1-value", "serviceName": "service1" }, { "id": 120111, "appName": "test", "deviceUUID": "*", "name": "svar2", "value": "svar2-value", "serviceName": "service2" },
{ "id": 120111, "appName": "test", "deviceUUID": "*", "name": "svar2", "value": "svar2-value", "serviceName": "service2" }, { "id": 120120, "appName": "test", "deviceUUID": "${fullUUID}", "name": "svar3", "value": "svar3-value", "serviceName": "service1" },
{ "id": 120120, "appName": "test", "deviceUUID": "${fullUUID}", "name": "svar3", "value": "svar3-value", "serviceName": "service1" }, { "id": 120121, "appName": "test", "deviceUUID": "${fullUUID}", "name": "svar4", "value": "svar4-value", "serviceName": "service2" },
{ "id": 120121, "appName": "test", "deviceUUID": "${fullUUID}", "name": "svar4", "value": "svar4-value", "serviceName": "service2" }, { "id": 120203, "appName": "test", "deviceUUID": "${fullUUID}", "name": "var3", "value": "var3-val", "serviceName": "*" },
{ "id": 120203, "appName": "test", "deviceUUID": "${fullUUID}", "name": "var3", "value": "var3-val", "serviceName": "*" }, { "id": 120204, "appName": "test", "deviceUUID": "${fullUUID}", "name": "var4", "value": "44", "serviceName": "*" }
{ "id": 120204, "appName": "test", "deviceUUID": "${fullUUID}", "name": "var4", "value": "44", "serviceName": "*" } ]`),
]`), );
);
} else {
expect(JSON.parse(out.join(''))).to.deep.equal([
{
id: 120203,
name: 'var3',
value: 'var3-val',
},
{
id: 120204,
name: 'var4',
value: '44',
},
]);
}
expect(err.join('')).to.equal(''); expect(err.join('')).to.equal('');
}); });
@ -315,29 +194,18 @@ describe('balena envs', function () {
it('should successfully list config variables for a test device', async () => { it('should successfully list config variables for a test device', async () => {
api.expectGetDevice({ fullUUID }); api.expectGetDevice({ fullUUID });
api.expectGetDeviceConfigVars(); api.expectGetDeviceConfigVars();
if (isV12()) { api.expectGetApplication();
api.expectGetApplication(); api.expectGetAppConfigVars();
api.expectGetAppConfigVars();
}
const { out, err } = await runCommand(`envs -d ${shortUUID} --config`); const { out, err } = await runCommand(`envs -d ${shortUUID} --config`);
if (isV12()) { expect(out.join('')).to.equal(
expect(out.join('')).to.equal( stripIndent`
stripIndent` ID NAME VALUE APPLICATION DEVICE
ID NAME VALUE APPLICATION DEVICE 120300 RESIN_SUPERVISOR_NATIVE_LOGGER false test *
120300 RESIN_SUPERVISOR_NATIVE_LOGGER false test * 120400 RESIN_SUPERVISOR_POLL_INTERVAL 900900 test ${shortUUID}
120400 RESIN_SUPERVISOR_POLL_INTERVAL 900900 test ${shortUUID} ` + '\n',
` + '\n', );
);
} else {
expect(out.join('')).to.equal(
stripIndent`
ID NAME VALUE
120400 RESIN_SUPERVISOR_POLL_INTERVAL 900900
` + '\n',
);
}
expect(err.join('')).to.equal(''); expect(err.join('')).to.equal('');
}); });
@ -348,85 +216,28 @@ describe('balena envs', function () {
api.expectGetApplication(); api.expectGetApplication();
api.expectGetDevice({ fullUUID }); api.expectGetDevice({ fullUUID });
api.expectGetDeviceServiceVars(); api.expectGetDeviceServiceVars();
if (isV12()) { api.expectGetAppEnvVars();
api.expectGetAppEnvVars(); api.expectGetAppServiceVars();
api.expectGetAppServiceVars(); api.expectGetDeviceEnvVars();
api.expectGetDeviceEnvVars();
}
const uuid = shortUUID; const uuid = shortUUID;
const { out, err } = await runCommand(`envs -d ${uuid} -s ${serviceName}`); const { out, err } = await runCommand(`envs -d ${uuid} -s ${serviceName}`);
if (isV12()) { expect(out.join('')).to.equal(
expect(out.join('')).to.equal( stripIndent`
stripIndent` ID NAME VALUE APPLICATION DEVICE SERVICE
ID NAME VALUE APPLICATION DEVICE SERVICE 120111 svar2 svar2-value test * service2
120111 svar2 svar2-value test * service2 120121 svar4 svar4-value test ${uuid} service2
120121 svar4 svar4-value test ${uuid} service2 120101 var1 var1-val test * *
120101 var1 var1-val test * * 120102 var2 22 test * *
120102 var2 22 test * * 120203 var3 var3-val test ${uuid} *
120203 var3 var3-val test ${uuid} * 120204 var4 44 test ${uuid} *
120204 var4 44 test ${uuid} * ` + '\n',
` + '\n', );
);
} else {
expect(out.join('')).to.equal(
stripIndent`
ID NAME VALUE
120121 svar4 svar4-value
` + '\n',
);
}
expect(err.join('')).to.equal(''); expect(err.join('')).to.equal('');
}); });
if (!isV12()) {
it('should produce an empty JSON array when no device service variables exist', async () => {
const serviceName = 'nono';
api.expectGetService({ serviceName });
api.expectGetApplication();
api.expectGetDevice({ fullUUID });
api.expectGetDeviceServiceVars();
const { out, err } = await runCommand(
`envs -d ${shortUUID} -s ${serviceName} -j`,
);
expect(out.join('')).to.equal('[]\n');
expect(err.join('')).to.equal('');
});
}
if (!isV12()) {
it('should successfully list env and service variables for a test device (--all flag)', async () => {
api.expectGetApplication();
api.expectGetAppEnvVars();
api.expectGetAppServiceVars();
api.expectGetDevice({ fullUUID });
api.expectGetDeviceEnvVars();
api.expectGetDeviceServiceVars();
const uuid = shortUUID;
const { out, err } = await runCommand(`envs -d ${uuid} --all`);
expect(out.join('')).to.equal(
stripIndent`
ID NAME VALUE APPLICATION DEVICE SERVICE
120110 svar1 svar1-value test * service1
120111 svar2 svar2-value test * service2
120120 svar3 svar3-value test ${uuid} service1
120121 svar4 svar4-value test ${uuid} service2
120101 var1 var1-val test * *
120102 var2 22 test * *
120203 var3 var3-val test ${uuid} *
120204 var4 44 test ${uuid} *
` + '\n',
);
expect(err.join('')).to.equal('');
});
}
it('should successfully list env and service variables for a test device (unknown app)', async () => { it('should successfully list env and service variables for a test device (unknown app)', async () => {
api.expectGetDevice({ fullUUID, inaccessibleApp: true }); api.expectGetDevice({ fullUUID, inaccessibleApp: true });
api.expectGetDeviceEnvVars(); api.expectGetDeviceEnvVars();
@ -434,9 +245,7 @@ describe('balena envs', function () {
const uuid = shortUUID; const uuid = shortUUID;
const { out, err } = await runCommand( const { out, err } = await runCommand(`envs -d ${uuid}`);
isV12() ? `envs -d ${uuid}` : `envs -d ${uuid} --all`,
);
expect(out.join('')).to.equal( expect(out.join('')).to.equal(
stripIndent` stripIndent`
@ -450,29 +259,21 @@ describe('balena envs', function () {
expect(err.join('')).to.equal(''); expect(err.join('')).to.equal('');
}); });
it( it('should successfully list env and service vars for a test device (-s flags)', async () => {
isV12() const serviceName = 'service1';
? 'should successfully list env and service vars for a test device (-s flags)' api.expectGetService({ serviceName });
: 'should successfully list env and service vars for a test device (--all -s flags)', api.expectGetApplication();
async () => { api.expectGetAppEnvVars();
const serviceName = 'service1'; api.expectGetAppServiceVars();
api.expectGetService({ serviceName }); api.expectGetDevice({ fullUUID });
api.expectGetApplication(); api.expectGetDeviceEnvVars();
api.expectGetAppEnvVars(); api.expectGetDeviceServiceVars();
api.expectGetAppServiceVars();
api.expectGetDevice({ fullUUID });
api.expectGetDeviceEnvVars();
api.expectGetDeviceServiceVars();
const uuid = shortUUID; const uuid = shortUUID;
const { out, err } = await runCommand( const { out, err } = await runCommand(`envs -d ${uuid} -s ${serviceName}`);
isV12()
? `envs -d ${uuid} -s ${serviceName}`
: `envs -d ${uuid} --all -s ${serviceName}`,
);
expect(out.join('')).to.equal( expect(out.join('')).to.equal(
stripIndent` stripIndent`
ID NAME VALUE APPLICATION DEVICE SERVICE ID NAME VALUE APPLICATION DEVICE SERVICE
120110 svar1 svar1-value test * ${serviceName} 120110 svar1 svar1-value test * ${serviceName}
120120 svar3 svar3-value test ${uuid} ${serviceName} 120120 svar3 svar3-value test ${uuid} ${serviceName}
@ -481,33 +282,26 @@ describe('balena envs', function () {
120203 var3 var3-val test ${uuid} * 120203 var3 var3-val test ${uuid} *
120204 var4 44 test ${uuid} * 120204 var4 44 test ${uuid} *
` + '\n', ` + '\n',
); );
expect(err.join('')).to.equal(''); expect(err.join('')).to.equal('');
}, });
);
it( it('should successfully list env and service vars for a test device (-js flags)', async () => {
isV12() const serviceName = 'service1';
? 'should successfully list env and service vars for a test device (-js flags)' api.expectGetService({ serviceName });
: 'should successfully list env and service vars for a test device (--all -js flags)', api.expectGetApplication();
async () => { api.expectGetAppEnvVars();
const serviceName = 'service1'; api.expectGetAppServiceVars();
api.expectGetService({ serviceName }); api.expectGetDevice({ fullUUID });
api.expectGetApplication(); api.expectGetDeviceEnvVars();
api.expectGetAppEnvVars(); api.expectGetDeviceServiceVars();
api.expectGetAppServiceVars();
api.expectGetDevice({ fullUUID });
api.expectGetDeviceEnvVars();
api.expectGetDeviceServiceVars();
const { out, err } = await runCommand( const { out, err } = await runCommand(
isV12() `envs -d ${shortUUID} -js ${serviceName}`,
? `envs -d ${shortUUID} -js ${serviceName}` );
: `envs -d ${shortUUID} --all -js ${serviceName}`,
);
expect(JSON.parse(out.join(''))).to.deep.equal( expect(JSON.parse(out.join(''))).to.deep.equal(
JSON.parse(`[ JSON.parse(`[
{ "id": 120101, "appName": "test", "deviceUUID": "*", "name": "var1", "value": "var1-val", "serviceName": "*" }, { "id": 120101, "appName": "test", "deviceUUID": "*", "name": "var1", "value": "var1-val", "serviceName": "*" },
{ "id": 120102, "appName": "test", "deviceUUID": "*", "name": "var2", "value": "22", "serviceName": "*" }, { "id": 120102, "appName": "test", "deviceUUID": "*", "name": "var2", "value": "22", "serviceName": "*" },
{ "id": 120110, "appName": "test", "deviceUUID": "*", "name": "svar1", "value": "svar1-value", "serviceName": "${serviceName}" }, { "id": 120110, "appName": "test", "deviceUUID": "*", "name": "svar1", "value": "svar1-value", "serviceName": "${serviceName}" },
@ -515,8 +309,7 @@ describe('balena envs', function () {
{ "id": 120203, "appName": "test", "deviceUUID": "${fullUUID}", "name": "var3", "value": "var3-val", "serviceName": "*" }, { "id": 120203, "appName": "test", "deviceUUID": "${fullUUID}", "name": "var3", "value": "var3-val", "serviceName": "*" },
{ "id": 120204, "appName": "test", "deviceUUID": "${fullUUID}", "name": "var4", "value": "44", "serviceName": "*" } { "id": 120204, "appName": "test", "deviceUUID": "${fullUUID}", "name": "var4", "value": "44", "serviceName": "*" }
]`), ]`),
); );
expect(err.join('')).to.equal(''); expect(err.join('')).to.equal('');
}, });
);
}); });