mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 13:47:52 +00:00
Merge pull request #1851 from balena-io/envs-all-as-default
v12 preparations: Add feature switch for 'envs --all'
This commit is contained in:
commit
254d9c49a4
@ -739,7 +739,7 @@ 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. As asterisk in these columns indicates that the
|
||||
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,
|
||||
|
@ -24,9 +24,10 @@ import { ExpectedError } from '../errors';
|
||||
import * as cf from '../utils/common-flags';
|
||||
import { getBalenaSdk, getVisuals } from '../utils/lazy';
|
||||
import { CommandHelp } from '../utils/oclif-utils';
|
||||
import { isV12 } from '../utils/version';
|
||||
|
||||
interface FlagsDef {
|
||||
all?: boolean; // whether to include application-wide, device-wide variables
|
||||
all?: boolean; // whether to include application-wide, device-wide variables //TODO: REMOVE
|
||||
application?: string; // application name
|
||||
config: boolean;
|
||||
device?: string; // device UUID
|
||||
@ -57,7 +58,42 @@ interface ServiceEnvironmentVariableInfo
|
||||
}
|
||||
|
||||
export default class EnvsCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
public static description = isV12()
|
||||
? 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 results 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.
|
||||
|
||||
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 --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 --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
|
||||
@ -79,7 +115,7 @@ export default class EnvsCmd extends Command {
|
||||
|
||||
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. As asterisk in these columns indicates that the
|
||||
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,
|
||||
@ -93,28 +129,50 @@ export default class EnvsCmd extends Command {
|
||||
(for example, in case the current user has been removed from the application
|
||||
by its owner).
|
||||
`;
|
||||
public static examples = [
|
||||
'$ 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 examples = isV12()
|
||||
? [
|
||||
'$ balena envs --application MyApp',
|
||||
'$ balena envs --application MyApp --json',
|
||||
'$ balena envs --application MyApp --service MyService',
|
||||
'$ balena envs --application MyApp --service MyService',
|
||||
'$ balena envs --application MyApp --config',
|
||||
'$ balena envs --device 7cf02a6',
|
||||
'$ balena envs --device 7cf02a6 --json',
|
||||
'$ balena envs --device 7cf02a6 --config --json',
|
||||
'$ 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 = (
|
||||
'envs ' + new CommandHelp({ args: EnvsCmd.args }).defaultUsage()
|
||||
).trim();
|
||||
|
||||
public static flags: flags.Input<FlagsDef> = {
|
||||
all: flags.boolean({
|
||||
description: stripIndent`
|
||||
...(isV12()
|
||||
? {
|
||||
all: flags.boolean({
|
||||
description: stripIndent`
|
||||
No-op since balena CLI v12.0.0.`,
|
||||
hidden: true,
|
||||
}),
|
||||
}
|
||||
: {
|
||||
all: flags.boolean({
|
||||
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 },
|
||||
config: flags.boolean({
|
||||
char: 'c',
|
||||
@ -135,6 +193,8 @@ export default class EnvsCmd extends Command {
|
||||
const { flags: options } = this.parse<FlagsDef, {}>(EnvsCmd);
|
||||
const variables: EnvironmentVariableInfo[] = [];
|
||||
|
||||
options.all = options.all || isV12();
|
||||
|
||||
await Command.checkLoggedIn();
|
||||
|
||||
if (!options.application && !options.device) {
|
||||
|
576
tests/commands/env/envs.spec.ts
vendored
576
tests/commands/env/envs.spec.ts
vendored
@ -18,6 +18,7 @@
|
||||
import { expect } from 'chai';
|
||||
import { stripIndent } from 'common-tags';
|
||||
|
||||
import { isV12 } from '../../../lib/utils/version';
|
||||
import { BalenaAPIMock } from '../../balena-api-mock';
|
||||
import { runCommand } from '../../helpers';
|
||||
|
||||
@ -44,19 +45,38 @@ describe('balena envs', function() {
|
||||
});
|
||||
|
||||
it('should successfully list env vars for a test app', async () => {
|
||||
api.expectGetApplication();
|
||||
api.expectGetAppEnvVars();
|
||||
if (isV12()) {
|
||||
api.expectGetApplication();
|
||||
api.expectGetAppEnvVars();
|
||||
api.expectGetAppServiceVars();
|
||||
|
||||
const { out, err } = await runCommand(`envs -a ${appName}`);
|
||||
const { out, err } = await runCommand(`envs -a ${appName}`);
|
||||
|
||||
expect(out.join('')).to.equal(
|
||||
stripIndent`
|
||||
ID NAME VALUE
|
||||
120101 var1 var1-val
|
||||
120102 var2 22
|
||||
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('');
|
||||
);
|
||||
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 () => {
|
||||
@ -65,12 +85,22 @@ describe('balena envs', function() {
|
||||
|
||||
const { out, err } = await runCommand(`envs -a ${appName} --config`);
|
||||
|
||||
expect(out.join('')).to.equal(
|
||||
stripIndent`
|
||||
ID NAME VALUE
|
||||
120300 RESIN_SUPERVISOR_NATIVE_LOGGER false
|
||||
if (isV12()) {
|
||||
expect(out.join('')).to.equal(
|
||||
stripIndent`
|
||||
ID NAME VALUE APPLICATION
|
||||
120300 RESIN_SUPERVISOR_NATIVE_LOGGER false test
|
||||
` + '\n',
|
||||
);
|
||||
);
|
||||
} else {
|
||||
expect(out.join('')).to.equal(
|
||||
stripIndent`
|
||||
ID NAME VALUE
|
||||
120300 RESIN_SUPERVISOR_NATIVE_LOGGER false
|
||||
` + '\n',
|
||||
);
|
||||
}
|
||||
|
||||
expect(err.join('')).to.equal('');
|
||||
});
|
||||
|
||||
@ -80,13 +110,24 @@ describe('balena envs', function() {
|
||||
|
||||
const { out, err } = await runCommand(`envs -cja ${appName}`);
|
||||
|
||||
expect(JSON.parse(out.join(''))).to.deep.equal([
|
||||
{
|
||||
id: 120300,
|
||||
name: 'RESIN_SUPERVISOR_NATIVE_LOGGER',
|
||||
value: 'false',
|
||||
},
|
||||
]);
|
||||
if (isV12()) {
|
||||
expect(JSON.parse(out.join(''))).to.deep.equal([
|
||||
{
|
||||
appName: 'test',
|
||||
id: 120300,
|
||||
name: 'RESIN_SUPERVISOR_NATIVE_LOGGER',
|
||||
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('');
|
||||
});
|
||||
|
||||
@ -94,176 +135,118 @@ describe('balena envs', function() {
|
||||
const serviceName = 'service2';
|
||||
api.expectGetService({ serviceName });
|
||||
api.expectGetApplication();
|
||||
if (isV12()) {
|
||||
api.expectGetAppEnvVars();
|
||||
}
|
||||
api.expectGetAppServiceVars();
|
||||
|
||||
const { out, err } = await runCommand(
|
||||
`envs -a ${appName} -s ${serviceName}`,
|
||||
);
|
||||
|
||||
expect(out.join('')).to.equal(
|
||||
stripIndent`
|
||||
if (isV12()) {
|
||||
expect(out.join('')).to.equal(
|
||||
stripIndent`
|
||||
ID NAME VALUE APPLICATION SERVICE
|
||||
120111 svar2 svar2-value test service2
|
||||
120101 var1 var1-val test *
|
||||
120102 var2 22 test *
|
||||
` + '\n',
|
||||
);
|
||||
} else {
|
||||
expect(out.join('')).to.equal(
|
||||
stripIndent`
|
||||
ID NAME VALUE
|
||||
120111 svar2 svar2-value
|
||||
` + '\n',
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
expect(err.join('')).to.equal('');
|
||||
});
|
||||
|
||||
it('should produce an empty JSON array when no app service variables exist', async () => {
|
||||
const serviceName = 'nono';
|
||||
api.expectGetService({ serviceName });
|
||||
api.expectGetApplication();
|
||||
api.expectGetAppServiceVars();
|
||||
if (!isV12()) {
|
||||
it('should produce an empty JSON array when no app service variables exist', async () => {
|
||||
const serviceName = 'nono';
|
||||
api.expectGetService({ serviceName });
|
||||
api.expectGetApplication();
|
||||
api.expectGetAppServiceVars();
|
||||
|
||||
const { out, err } = await runCommand(
|
||||
`envs -a ${appName} -s ${serviceName} -j`,
|
||||
);
|
||||
const { out, err } = await runCommand(
|
||||
`envs -a ${appName} -s ${serviceName} -j`,
|
||||
);
|
||||
|
||||
expect(out.join('')).to.equal('[]\n');
|
||||
expect(err.join('')).to.equal('');
|
||||
});
|
||||
expect(out.join('')).to.equal('[]\n');
|
||||
expect(err.join('')).to.equal('');
|
||||
});
|
||||
}
|
||||
|
||||
it('should successfully list env and service vars for a test app (--all flag)', async () => {
|
||||
api.expectGetApplication();
|
||||
api.expectGetAppEnvVars();
|
||||
api.expectGetAppServiceVars();
|
||||
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`);
|
||||
const { out, err } = await runCommand(`envs -a ${appName} --all`);
|
||||
|
||||
expect(out.join('')).to.equal(
|
||||
stripIndent`
|
||||
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('');
|
||||
});
|
||||
);
|
||||
expect(err.join('')).to.equal('');
|
||||
});
|
||||
}
|
||||
|
||||
it('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();
|
||||
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(
|
||||
`envs -a ${appName} --all -s ${serviceName}`,
|
||||
);
|
||||
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
|
||||
120110 svar1 svar1-value test ${serviceName}
|
||||
120101 var1 var1-val test *
|
||||
120102 var2 22 test *
|
||||
` + '\n',
|
||||
);
|
||||
expect(err.join('')).to.equal('');
|
||||
});
|
||||
expect(out.join('')).to.equal(
|
||||
stripIndent`
|
||||
ID NAME VALUE APPLICATION SERVICE
|
||||
120110 svar1 svar1-value test ${serviceName}
|
||||
120101 var1 var1-val test *
|
||||
120102 var2 22 test *
|
||||
` + '\n',
|
||||
);
|
||||
expect(err.join('')).to.equal('');
|
||||
},
|
||||
);
|
||||
|
||||
it('should successfully list env variables for a test device', async () => {
|
||||
api.expectGetDevice({ fullUUID });
|
||||
api.expectGetDeviceEnvVars();
|
||||
|
||||
const { out, err } = await runCommand(`envs -d ${shortUUID}`);
|
||||
|
||||
expect(out.join('')).to.equal(
|
||||
stripIndent`
|
||||
ID NAME VALUE
|
||||
120203 var3 var3-val
|
||||
120204 var4 44
|
||||
` + '\n',
|
||||
);
|
||||
expect(err.join('')).to.equal('');
|
||||
});
|
||||
|
||||
it('should successfully list env variables for a test device (JSON output)', async () => {
|
||||
api.expectGetDevice({ fullUUID });
|
||||
api.expectGetDeviceEnvVars();
|
||||
|
||||
const { out, err } = await runCommand(`envs -jd ${shortUUID}`);
|
||||
|
||||
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('');
|
||||
});
|
||||
|
||||
it('should successfully list config variables for a test device', async () => {
|
||||
api.expectGetDevice({ fullUUID });
|
||||
api.expectGetDeviceConfigVars();
|
||||
|
||||
const { out, err } = await runCommand(`envs -d ${shortUUID} --config`);
|
||||
|
||||
expect(out.join('')).to.equal(
|
||||
stripIndent`
|
||||
ID NAME VALUE
|
||||
120400 RESIN_SUPERVISOR_POLL_INTERVAL 900900
|
||||
` + '\n',
|
||||
);
|
||||
expect(err.join('')).to.equal('');
|
||||
});
|
||||
|
||||
it('should successfully list service variables for a test device (-s flag)', async () => {
|
||||
const serviceName = 'service2';
|
||||
api.expectGetService({ serviceName });
|
||||
api.expectGetApplication();
|
||||
api.expectGetDevice({ fullUUID });
|
||||
api.expectGetDeviceServiceVars();
|
||||
|
||||
const { out, err } = await runCommand(
|
||||
`envs -d ${shortUUID} -s ${serviceName}`,
|
||||
);
|
||||
|
||||
expect(out.join('')).to.equal(
|
||||
stripIndent`
|
||||
ID NAME VALUE
|
||||
120121 svar4 svar4-value
|
||||
` + '\n',
|
||||
);
|
||||
expect(err.join('')).to.equal('');
|
||||
});
|
||||
|
||||
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('');
|
||||
});
|
||||
|
||||
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();
|
||||
if (isV12()) {
|
||||
api.expectGetApplication();
|
||||
api.expectGetAppEnvVars();
|
||||
api.expectGetAppServiceVars();
|
||||
api.expectGetDeviceServiceVars();
|
||||
}
|
||||
|
||||
const uuid = shortUUID;
|
||||
const { out, err } = await runCommand(`envs -d ${uuid} --all`);
|
||||
const { out, err } = await runCommand(`envs -d ${uuid}`);
|
||||
|
||||
expect(out.join('')).to.equal(
|
||||
stripIndent`
|
||||
if (isV12()) {
|
||||
expect(out.join('')).to.equal(
|
||||
stripIndent`
|
||||
ID NAME VALUE APPLICATION DEVICE SERVICE
|
||||
120110 svar1 svar1-value test * service1
|
||||
120111 svar2 svar2-value test * service2
|
||||
@ -274,17 +257,188 @@ describe('balena envs', function() {
|
||||
120203 var3 var3-val test ${uuid} *
|
||||
120204 var4 44 test ${uuid} *
|
||||
` + '\n',
|
||||
);
|
||||
);
|
||||
} else {
|
||||
expect(out.join('')).to.equal(
|
||||
stripIndent`
|
||||
ID NAME VALUE
|
||||
120203 var3 var3-val
|
||||
120204 var4 44
|
||||
` + '\n',
|
||||
);
|
||||
}
|
||||
|
||||
expect(err.join('')).to.equal('');
|
||||
});
|
||||
|
||||
it('should successfully list env variables for a test device (JSON output)', async () => {
|
||||
api.expectGetDevice({ fullUUID });
|
||||
api.expectGetDeviceEnvVars();
|
||||
if (isV12()) {
|
||||
api.expectGetApplication();
|
||||
api.expectGetAppEnvVars();
|
||||
api.expectGetAppServiceVars();
|
||||
api.expectGetDeviceServiceVars();
|
||||
}
|
||||
|
||||
const { out, err } = await runCommand(`envs -jd ${shortUUID}`);
|
||||
|
||||
if (isV12()) {
|
||||
expect(JSON.parse(out.join(''))).to.deep.equal(
|
||||
JSON.parse(`[
|
||||
{ "id": 120101, "appName": "test", "deviceUUID": "*", "name": "var1", "value": "var1-val", "serviceName": "*" },
|
||||
{ "id": 120102, "appName": "test", "deviceUUID": "*", "name": "var2", "value": "22", "serviceName": "*" },
|
||||
{ "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": 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": 120203, "appName": "test", "deviceUUID": "${fullUUID}", "name": "var3", "value": "var3-val", "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('');
|
||||
});
|
||||
|
||||
it('should successfully list config variables for a test device', async () => {
|
||||
api.expectGetDevice({ fullUUID });
|
||||
api.expectGetDeviceConfigVars();
|
||||
if (isV12()) {
|
||||
api.expectGetApplication();
|
||||
api.expectGetAppConfigVars();
|
||||
}
|
||||
|
||||
const { out, err } = await runCommand(`envs -d ${shortUUID} --config`);
|
||||
|
||||
if (isV12()) {
|
||||
expect(out.join('')).to.equal(
|
||||
stripIndent`
|
||||
ID NAME VALUE APPLICATION DEVICE
|
||||
120300 RESIN_SUPERVISOR_NATIVE_LOGGER false test *
|
||||
120400 RESIN_SUPERVISOR_POLL_INTERVAL 900900 test ${shortUUID}
|
||||
` + '\n',
|
||||
);
|
||||
} else {
|
||||
expect(out.join('')).to.equal(
|
||||
stripIndent`
|
||||
ID NAME VALUE
|
||||
120400 RESIN_SUPERVISOR_POLL_INTERVAL 900900
|
||||
` + '\n',
|
||||
);
|
||||
}
|
||||
|
||||
expect(err.join('')).to.equal('');
|
||||
});
|
||||
|
||||
it('should successfully list service variables for a test device (-s flag)', async () => {
|
||||
const serviceName = 'service2';
|
||||
api.expectGetService({ serviceName });
|
||||
api.expectGetApplication();
|
||||
api.expectGetDevice({ fullUUID });
|
||||
api.expectGetDeviceServiceVars();
|
||||
if (isV12()) {
|
||||
api.expectGetAppEnvVars();
|
||||
api.expectGetAppServiceVars();
|
||||
api.expectGetDeviceEnvVars();
|
||||
}
|
||||
|
||||
const uuid = shortUUID;
|
||||
const { out, err } = await runCommand(`envs -d ${uuid} -s ${serviceName}`);
|
||||
|
||||
if (isV12()) {
|
||||
expect(out.join('')).to.equal(
|
||||
stripIndent`
|
||||
ID NAME VALUE APPLICATION DEVICE SERVICE
|
||||
120111 svar2 svar2-value test * service2
|
||||
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',
|
||||
);
|
||||
} else {
|
||||
expect(out.join('')).to.equal(
|
||||
stripIndent`
|
||||
ID NAME VALUE
|
||||
120121 svar4 svar4-value
|
||||
` + '\n',
|
||||
);
|
||||
}
|
||||
|
||||
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 () => {
|
||||
api.expectGetDevice({ fullUUID, inaccessibleApp: true });
|
||||
api.expectGetDeviceEnvVars();
|
||||
api.expectGetDeviceServiceVars();
|
||||
|
||||
const uuid = shortUUID;
|
||||
const { out, err } = await runCommand(`envs -d ${uuid} --all`);
|
||||
|
||||
const { out, err } = await runCommand(
|
||||
isV12() ? `envs -d ${uuid}` : `envs -d ${uuid} --all`,
|
||||
);
|
||||
|
||||
expect(out.join('')).to.equal(
|
||||
stripIndent`
|
||||
@ -298,51 +452,64 @@ describe('balena envs', function() {
|
||||
expect(err.join('')).to.equal('');
|
||||
});
|
||||
|
||||
it('should successfully list env and service vars for a test device (--all -s flags)', async () => {
|
||||
const serviceName = 'service1';
|
||||
api.expectGetService({ serviceName });
|
||||
api.expectGetApplication();
|
||||
api.expectGetAppEnvVars();
|
||||
api.expectGetAppServiceVars();
|
||||
api.expectGetDevice({ fullUUID });
|
||||
api.expectGetDeviceEnvVars();
|
||||
api.expectGetDeviceServiceVars();
|
||||
it(
|
||||
isV12()
|
||||
? 'should successfully list env and service vars for a test device (-s flags)'
|
||||
: 'should successfully list env and service vars for a test device (--all -s flags)',
|
||||
async () => {
|
||||
const serviceName = 'service1';
|
||||
api.expectGetService({ serviceName });
|
||||
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 -s ${serviceName}`,
|
||||
);
|
||||
const uuid = shortUUID;
|
||||
const { out, err } = await runCommand(
|
||||
isV12()
|
||||
? `envs -d ${uuid} -s ${serviceName}`
|
||||
: `envs -d ${uuid} --all -s ${serviceName}`,
|
||||
);
|
||||
|
||||
expect(out.join('')).to.equal(
|
||||
stripIndent`
|
||||
ID NAME VALUE APPLICATION DEVICE SERVICE
|
||||
120110 svar1 svar1-value test * ${serviceName}
|
||||
120120 svar3 svar3-value test ${uuid} ${serviceName}
|
||||
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('');
|
||||
});
|
||||
expect(out.join('')).to.equal(
|
||||
stripIndent`
|
||||
ID NAME VALUE APPLICATION DEVICE SERVICE
|
||||
120110 svar1 svar1-value test * ${serviceName}
|
||||
120120 svar3 svar3-value test ${uuid} ${serviceName}
|
||||
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 vars for a test device (--all -js flags)', async () => {
|
||||
const serviceName = 'service1';
|
||||
api.expectGetService({ serviceName });
|
||||
api.expectGetApplication();
|
||||
api.expectGetAppEnvVars();
|
||||
api.expectGetAppServiceVars();
|
||||
api.expectGetDevice({ fullUUID });
|
||||
api.expectGetDeviceEnvVars();
|
||||
api.expectGetDeviceServiceVars();
|
||||
it(
|
||||
isV12()
|
||||
? 'should successfully list env and service vars for a test device (-js flags)'
|
||||
: 'should successfully list env and service vars for a test device (--all -js flags)',
|
||||
async () => {
|
||||
const serviceName = 'service1';
|
||||
api.expectGetService({ serviceName });
|
||||
api.expectGetApplication();
|
||||
api.expectGetAppEnvVars();
|
||||
api.expectGetAppServiceVars();
|
||||
api.expectGetDevice({ fullUUID });
|
||||
api.expectGetDeviceEnvVars();
|
||||
api.expectGetDeviceServiceVars();
|
||||
|
||||
const { out, err } = await runCommand(
|
||||
`envs -d ${shortUUID} --all -js ${serviceName}`,
|
||||
);
|
||||
const { out, err } = await runCommand(
|
||||
isV12()
|
||||
? `envs -d ${shortUUID} -js ${serviceName}`
|
||||
: `envs -d ${shortUUID} --all -js ${serviceName}`,
|
||||
);
|
||||
|
||||
expect(JSON.parse(out.join(''))).to.deep.equal(
|
||||
JSON.parse(`[
|
||||
expect(JSON.parse(out.join(''))).to.deep.equal(
|
||||
JSON.parse(`[
|
||||
{ "id": 120101, "appName": "test", "deviceUUID": "*", "name": "var1", "value": "var1-val", "serviceName": "*" },
|
||||
{ "id": 120102, "appName": "test", "deviceUUID": "*", "name": "var2", "value": "22", "serviceName": "*" },
|
||||
{ "id": 120110, "appName": "test", "deviceUUID": "*", "name": "svar1", "value": "svar1-value", "serviceName": "${serviceName}" },
|
||||
@ -350,7 +517,8 @@ describe('balena envs', function() {
|
||||
{ "id": 120203, "appName": "test", "deviceUUID": "${fullUUID}", "name": "var3", "value": "var3-val", "serviceName": "*" },
|
||||
{ "id": 120204, "appName": "test", "deviceUUID": "${fullUUID}", "name": "var4", "value": "44", "serviceName": "*" }
|
||||
]`),
|
||||
);
|
||||
expect(err.join('')).to.equal('');
|
||||
});
|
||||
);
|
||||
expect(err.join('')).to.equal('');
|
||||
},
|
||||
);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user