diff --git a/lib/commands/apps.ts b/lib/commands/apps.ts index ffbe50a4..e12a53fb 100644 --- a/lib/commands/apps.ts +++ b/lib/commands/apps.ts @@ -19,7 +19,6 @@ import { flags } from '@oclif/command'; import Command from '../command'; import * as cf from '../utils/common-flags'; import { getBalenaSdk, getVisuals, stripIndent } from '../utils/lazy'; -import { isV12 } from '../utils/version'; interface ExtendedApplication extends ApplicationWithDeviceType { device_count?: number; @@ -49,9 +48,7 @@ export default class AppsCmd extends Command { verbose: flags.boolean({ default: false, char: 'v', - description: isV12() - ? 'No-op since release v12.0.0' - : 'add extra columns in the tabular output (SLUG)', + description: 'No-op since release v12.0.0', }), }; @@ -88,7 +85,7 @@ export default class AppsCmd extends Command { getVisuals().table.horizontal(applications, [ 'id', 'app_name', - options.verbose || isV12() ? 'slug' : '', + options.verbose || 'slug', 'device_type', 'online_devices', 'device_count', diff --git a/lib/commands/envs.ts b/lib/commands/envs.ts index ccdf0f4c..5dc1a606 100644 --- a/lib/commands/envs.ts +++ b/lib/commands/envs.ts @@ -22,11 +22,9 @@ import Command from '../command'; import { ExpectedError } from '../errors'; import * as cf from '../utils/common-flags'; import { getBalenaSdk, getVisuals, stripIndent } from '../utils/lazy'; -import { CommandHelp } from '../utils/oclif-utils'; -import { isV12 } from '../utils/version'; +import { isV13 } from '../utils/version'; interface FlagsDef { - all?: boolean; // whether to include application-wide, device-wide variables //TODO: REMOVE application?: string; // application name config: boolean; device?: string; // device UUID @@ -57,8 +55,7 @@ interface ServiceEnvironmentVariableInfo } export default class EnvsCmd extends Command { - public static description = isV12() - ? stripIndent` + public static description = stripIndent` List the environment or config variables of an application, device or service. 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 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, 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 @@ -128,52 +89,32 @@ 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 = 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 examples = [ + '$ 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', + ]; - public static usage = ( - 'envs ' + new CommandHelp({ args: EnvsCmd.args }).defaultUsage() - ).trim(); + public static usage = 'envs'; public static flags: flags.Input = { - ...(isV12() - ? { + ...(isV13() + ? {} + : { all: flags.boolean({ default: false, description: stripIndent` No-op since balena CLI v12.0.0.`, 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 }, config: flags.boolean({ default: false, @@ -196,8 +137,6 @@ export default class EnvsCmd extends Command { const { flags: options } = this.parse(EnvsCmd); const variables: EnvironmentVariableInfo[] = []; - options.all = options.all || isV12(); - await Command.checkLoggedIn(); if (!options.application && !options.device) { @@ -225,9 +164,7 @@ export default class EnvsCmd extends Command { if (appName && options.service) { 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) { variables.push( ...(await getDeviceVars(balena, fullUUID, appName, options)), @@ -251,20 +188,18 @@ export default class EnvsCmd extends Command { ) { const fields = ['id', 'name', 'value']; - if (options.all) { - // Replace undefined app names with 'N/A' or null - varArray = varArray.map((i: EnvironmentVariableInfo) => { - i.appName = i.appName || (options.json ? null : 'N/A'); - return i; - }); + // Replace undefined app names with 'N/A' or null + varArray = varArray.map((i: EnvironmentVariableInfo) => { + i.appName = i.appName || (options.json ? null : 'N/A'); + return i; + }); - fields.push(options.json ? 'appName' : 'appName => APPLICATION'); - if (options.device) { - fields.push(options.json ? 'deviceUUID' : 'deviceUUID => DEVICE'); - } - if (!options.config) { - fields.push(options.json ? 'serviceName' : 'serviceName => SERVICE'); - } + fields.push(options.json ? 'appName' : 'appName => APPLICATION'); + if (options.device) { + fields.push(options.json ? 'deviceUUID' : 'deviceUUID => DEVICE'); + } + if (!options.config) { + fields.push(options.json ? 'serviceName' : 'serviceName => SERVICE'); } if (options.json) { @@ -313,14 +248,12 @@ async function getAppVars( if (!appName) { return appVars; } - if (options.config || options.all || !options.service) { - const vars = await sdk.models.application[ - options.config ? 'configVar' : 'envVar' - ].getAllByApplication(appName); - fillInInfoFields(vars, appName); - appVars.push(...vars); - } - if (!options.config && (options.service || options.all)) { + const vars = await sdk.models.application[ + options.config ? 'configVar' : 'envVar' + ].getAllByApplication(appName); + fillInInfoFields(vars, appName); + appVars.push(...vars); + if (!options.config) { const pineOpts: SDK.PineOptions = { $expand: { service: {}, @@ -362,35 +295,32 @@ async function getDeviceVars( fillInInfoFields(deviceConfigVars, appName, printedUUID); deviceVars.push(...deviceConfigVars); } else { - if (options.service || options.all) { - const pineOpts: SDK.PineOptions = { - $expand: { - service_install: { - $expand: 'installs__service', - }, + const pineOpts: SDK.PineOptions = { + $expand: { + service_install: { + $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; } diff --git a/lib/commands/tags.ts b/lib/commands/tags.ts index e0e85021..c6db0f28 100644 --- a/lib/commands/tags.ts +++ b/lib/commands/tags.ts @@ -22,7 +22,6 @@ import * as cf from '../utils/common-flags'; import { getBalenaSdk, getVisuals, stripIndent } from '../utils/lazy'; import { disambiguateReleaseParam } from '../utils/normalization'; import { tryAsInteger } from '../utils/validation'; -import { isV12 } from '../utils/version'; interface FlagsDef { application?: string; @@ -110,11 +109,7 @@ export default class TagsCmd extends Command { throw new ExpectedError('No tags found'); } - console.log( - isV12() - ? getVisuals().table.horizontal(tags, ['tag_key', 'value']) - : getVisuals().table.horizontal(tags, ['id', 'tag_key', 'value']), - ); + console.log(getVisuals().table.horizontal(tags, ['tag_key', 'value'])); } protected missingResourceMessage = stripIndent` diff --git a/lib/utils/compose_ts.ts b/lib/utils/compose_ts.ts index c112e42e..ad9bc42d 100644 --- a/lib/utils/compose_ts.ts +++ b/lib/utils/compose_ts.ts @@ -1128,15 +1128,10 @@ export async function validateProjectDirectory( checkCompose(path.join(opts.projectPath, '..')), ]); if (!hasCompose && hasParentCompose) { - const { isV12 } = await import('./version'); const msg = stripIndent` "docker-compose.y[a]ml" file found in parent directory: please check that the correct source folder was specified. (Suppress with '--noparent-check'.)`; - if (isV12()) { - throw new ExpectedError(`Error: ${msg}`); - } else { - Logger.getLogger().logWarn(msg); - } + throw new ExpectedError(`Error: ${msg}`); } } } diff --git a/lib/utils/eol-conversion.ts b/lib/utils/eol-conversion.ts index 81279adb..2d015c6b 100644 --- a/lib/utils/eol-conversion.ts +++ b/lib/utils/eol-conversion.ts @@ -17,7 +17,6 @@ import { promises as fs } from 'fs'; import Logger = require('./logger'); -import { isV12 } from './version'; const globalLogger = Logger.getLogger(); @@ -111,9 +110,7 @@ export async function readFileWithEolConversion( ); // And summary warning later 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. Consider using the `--convert-eol` option.', + 'Windows-format line endings were detected in some files, but were not converted due to `--noconvert-eol` option.', Logger.Level.WARN, ); diff --git a/lib/utils/version.ts b/lib/utils/version.ts index 04a36c41..086af903 100644 --- a/lib/utils/version.ts +++ b/lib/utils/version.ts @@ -22,13 +22,12 @@ export function isVersionGTE(v: string): boolean { return semver.gte(process.env.BALENA_CLI_VERSION_OVERRIDE || version, v); } -let v12: boolean; +let v13: boolean; -export function isV12(): boolean { - if (v12 === undefined) { - // This is the `Change-type: major` PR that will produce v12.0.0. - // Enable the v12 feature switches and run all v12 tests. - v12 = true; // v12 = isVersionGTE('12.0.0'); +/** Feature switch for the next major version of the CLI */ +export function isV13(): boolean { + if (v13 === undefined) { + v13 = isVersionGTE('13.0.0'); } - return v12; + return v13; } diff --git a/tests/commands/device/supported.spec.ts b/tests/commands/device/supported.spec.ts index afbd5be7..a495bcf8 100644 --- a/tests/commands/device/supported.spec.ts +++ b/tests/commands/device/supported.spec.ts @@ -17,7 +17,6 @@ import { expect } from 'chai'; -import { isV12 } from '../../../build/utils/version'; import { BalenaAPIMock } from '../../balena-api-mock'; import { cleanOutput, runCommand } from '../../helpers'; @@ -50,9 +49,7 @@ describe('balena devices supported', function () { const lines = cleanOutput(out); - expect(lines[0].replace(/ +/g, ' ')).to.equal( - isV12() ? 'SLUG ALIASES ARCH NAME' : 'SLUG NAME', - ); + expect(lines[0].replace(/ +/g, ' ')).to.equal('SLUG ALIASES ARCH NAME'); expect(lines).to.have.lengthOf.at.least(2); // Discontinued devices should be filtered out from results diff --git a/tests/commands/env/envs.spec.ts b/tests/commands/env/envs.spec.ts index 254ffd5d..d548ca1b 100644 --- a/tests/commands/env/envs.spec.ts +++ b/tests/commands/env/envs.spec.ts @@ -18,7 +18,6 @@ import { expect } from 'chai'; import { stripIndent } from '../../../lib/utils/lazy'; -import { isV12 } from '../../../lib/utils/version'; import { BalenaAPIMock } from '../../balena-api-mock'; import { runCommand } from '../../helpers'; @@ -43,38 +42,22 @@ describe('balena envs', function () { }); it('should successfully list env vars for a test app', async () => { - if (isV12()) { - api.expectGetApplication(); - api.expectGetAppEnvVars(); - api.expectGetAppServiceVars(); + 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 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(''); - } 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(''); - } + 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('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`); - 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(out.join('')).to.equal( + stripIndent` + ID NAME VALUE APPLICATION + 120300 RESIN_SUPERVISOR_NATIVE_LOGGER false test + ` + '\n', + ); expect(err.join('')).to.equal(''); }); @@ -108,24 +82,14 @@ describe('balena envs', function () { const { out, err } = await runCommand(`envs -cja ${appName}`); - 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(JSON.parse(out.join(''))).to.deep.equal([ + { + appName: 'test', + id: 120300, + name: 'RESIN_SUPERVISOR_NATIVE_LOGGER', + value: 'false', + }, + ]); expect(err.join('')).to.equal(''); }); @@ -133,138 +97,70 @@ describe('balena envs', function () { const serviceName = 'service2'; api.expectGetService({ serviceName }); api.expectGetApplication(); - if (isV12()) { - api.expectGetAppEnvVars(); - } + api.expectGetAppEnvVars(); api.expectGetAppServiceVars(); const { out, err } = await runCommand( `envs -a ${appName} -s ${serviceName}`, ); - 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(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', + ); expect(err.join('')).to.equal(''); }); - 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(); + it('should successfully list env and service vars for a test app (-s flags)', async () => { + const serviceName = 'service1'; + api.expectGetService({ serviceName }); + api.expectGetApplication(); + api.expectGetAppEnvVars(); + api.expectGetAppServiceVars(); - const { out, err } = await runCommand( - `envs -a ${appName} -s ${serviceName} -j`, - ); + const { out, err } = await runCommand( + `envs -a ${appName} -s ${serviceName}`, + ); - expect(out.join('')).to.equal('[]\n'); - expect(err.join('')).to.equal(''); - }); - } - - 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` + 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(err.join('')).to.equal(''); + }); it('should successfully list env variables for a test device', async () => { api.expectGetDevice({ fullUUID }); api.expectGetDeviceEnvVars(); - if (isV12()) { - api.expectGetApplication(); - api.expectGetAppEnvVars(); - api.expectGetAppServiceVars(); - api.expectGetDeviceServiceVars(); - } + api.expectGetApplication(); + api.expectGetAppEnvVars(); + api.expectGetAppServiceVars(); + api.expectGetDeviceServiceVars(); const uuid = shortUUID; const { out, err } = await runCommand(`envs -d ${uuid}`); - 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 - 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', - ); - } else { - expect(out.join('')).to.equal( - stripIndent` - ID NAME VALUE - 120203 var3 var3-val - 120204 var4 44 - ` + '\n', - ); - } + 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(''); }); @@ -272,42 +168,25 @@ describe('balena envs', function () { 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(); - } + 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(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": "*" } + ]`), + ); expect(err.join('')).to.equal(''); }); @@ -315,29 +194,18 @@ describe('balena envs', function () { it('should successfully list config variables for a test device', async () => { api.expectGetDevice({ fullUUID }); api.expectGetDeviceConfigVars(); - if (isV12()) { - api.expectGetApplication(); - api.expectGetAppConfigVars(); - } + 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(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', + ); expect(err.join('')).to.equal(''); }); @@ -348,85 +216,28 @@ describe('balena envs', function () { api.expectGetApplication(); api.expectGetDevice({ fullUUID }); api.expectGetDeviceServiceVars(); - if (isV12()) { - api.expectGetAppEnvVars(); - api.expectGetAppServiceVars(); - api.expectGetDeviceEnvVars(); - } + 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(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', + ); 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(); @@ -434,9 +245,7 @@ describe('balena envs', function () { const uuid = shortUUID; - const { out, err } = await runCommand( - isV12() ? `envs -d ${uuid}` : `envs -d ${uuid} --all`, - ); + const { out, err } = await runCommand(`envs -d ${uuid}`); expect(out.join('')).to.equal( stripIndent` @@ -450,29 +259,21 @@ describe('balena envs', function () { expect(err.join('')).to.equal(''); }); - 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(); + it('should successfully list env and service vars for a test device (-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( - isV12() - ? `envs -d ${uuid} -s ${serviceName}` - : `envs -d ${uuid} --all -s ${serviceName}`, - ); + const uuid = shortUUID; + const { out, err } = await runCommand(`envs -d ${uuid} -s ${serviceName}`); - expect(out.join('')).to.equal( - stripIndent` + 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} @@ -481,33 +282,26 @@ describe('balena envs', function () { 120203 var3 var3-val test ${uuid} * 120204 var4 44 test ${uuid} * ` + '\n', - ); - expect(err.join('')).to.equal(''); - }, - ); + ); + expect(err.join('')).to.equal(''); + }); - 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(); + it('should successfully list env and service vars for a test device (-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( - isV12() - ? `envs -d ${shortUUID} -js ${serviceName}` - : `envs -d ${shortUUID} --all -js ${serviceName}`, - ); + const { out, err } = await runCommand( + `envs -d ${shortUUID} -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}" }, @@ -515,8 +309,7 @@ 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(''); + }); });