mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-20 22:23:07 +00:00
v13 preparations: Adjust test cases for 'balena envs'
Change-type: patch
This commit is contained in:
parent
afb6f938b7
commit
352fd197b7
241
tests/commands/env/envs.spec.ts
vendored
241
tests/commands/env/envs.spec.ts
vendored
@ -21,11 +21,7 @@ import { stripIndent } from '../../../lib/utils/lazy';
|
||||
import { BalenaAPIMock } from '../../nock/balena-api-mock';
|
||||
import { runCommand } from '../../helpers';
|
||||
|
||||
import {
|
||||
appToFleetFlagMsg,
|
||||
appToFleetOutputMsg,
|
||||
warnify,
|
||||
} from '../../../build/utils/messages';
|
||||
import { appToFleetOutputMsg, warnify } from '../../../build/utils/messages';
|
||||
import { isV13 } from '../../../build/utils/version';
|
||||
|
||||
describe('balena envs', function () {
|
||||
@ -48,13 +44,6 @@ describe('balena envs', function () {
|
||||
api.done();
|
||||
});
|
||||
|
||||
const appToFleetFlagWarn =
|
||||
!isV13() &&
|
||||
process.stderr.isTTY &&
|
||||
process.env.BALENA_CLI_TEST_TYPE !== 'standalone'
|
||||
? warnify(appToFleetFlagMsg) + '\n'
|
||||
: '';
|
||||
|
||||
const appToFleetOutputWarn =
|
||||
!isV13() &&
|
||||
process.stderr.isTTY &&
|
||||
@ -67,18 +56,18 @@ describe('balena envs', function () {
|
||||
api.expectGetAppEnvVars();
|
||||
api.expectGetAppServiceVars();
|
||||
|
||||
const { out, err } = await runCommand(`envs -a ${appName}`);
|
||||
const { out, err } = await runCommand(`envs -f ${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 *
|
||||
ID NAME VALUE FLEET 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(appToFleetFlagWarn);
|
||||
expect(err.join('')).to.equal('');
|
||||
});
|
||||
|
||||
it('should successfully list config vars for a test fleet', async () => {
|
||||
@ -101,11 +90,11 @@ describe('balena envs', function () {
|
||||
api.expectGetApplication();
|
||||
api.expectGetAppConfigVars();
|
||||
|
||||
const { out, err } = await runCommand(`envs -cja ${appName}`);
|
||||
const { out, err } = await runCommand(`envs -cjf ${appName}`);
|
||||
|
||||
expect(JSON.parse(out.join(''))).to.deep.equal([
|
||||
{
|
||||
appName: 'test',
|
||||
fleetName: 'test',
|
||||
id: 120300,
|
||||
name: 'RESIN_SUPERVISOR_NATIVE_LOGGER',
|
||||
value: 'false',
|
||||
@ -122,18 +111,18 @@ describe('balena envs', function () {
|
||||
api.expectGetAppServiceVars();
|
||||
|
||||
const { out, err } = await runCommand(
|
||||
`envs -a ${appName} -s ${serviceName}`,
|
||||
`envs -f ${appName} -s ${serviceName}`,
|
||||
);
|
||||
|
||||
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 *
|
||||
ID NAME VALUE FLEET SERVICE
|
||||
120111 svar2 svar2-value test service2
|
||||
120101 var1 var1-val test *
|
||||
120102 var2 22 test *
|
||||
` + '\n',
|
||||
);
|
||||
expect(err.join('')).to.equal(appToFleetFlagWarn);
|
||||
expect(err.join('')).to.equal('');
|
||||
});
|
||||
|
||||
it('should successfully list env and service vars for a test fleet (-s flags)', async () => {
|
||||
@ -144,18 +133,18 @@ describe('balena envs', function () {
|
||||
api.expectGetAppServiceVars();
|
||||
|
||||
const { out, err } = await runCommand(
|
||||
`envs -a ${appName} -s ${serviceName}`,
|
||||
`envs -f ${appName} -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 *
|
||||
ID NAME VALUE FLEET SERVICE
|
||||
120110 svar1 svar1-value test ${serviceName}
|
||||
120101 var1 var1-val test *
|
||||
120102 var2 22 test *
|
||||
` + '\n',
|
||||
);
|
||||
expect(err.join('')).to.equal(appToFleetFlagWarn);
|
||||
expect(err.join('')).to.equal('');
|
||||
});
|
||||
|
||||
it('should successfully list env variables for a test device', async () => {
|
||||
@ -167,22 +156,29 @@ describe('balena envs', function () {
|
||||
api.expectGetDeviceServiceVars();
|
||||
|
||||
const uuid = shortUUID;
|
||||
const { out, err } = await runCommand(`envs -d ${uuid}`);
|
||||
|
||||
expect(out.join('')).to.equal(
|
||||
const result = await runCommand(`envs -d ${uuid}`);
|
||||
const { err } = result;
|
||||
let { out } = result;
|
||||
let expected =
|
||||
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',
|
||||
);
|
||||
|
||||
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';
|
||||
if (isV13()) {
|
||||
out = out.map((l) => l.replace(/ +/g, ' '));
|
||||
expected = expected
|
||||
.replace(/ +/g, ' ')
|
||||
.replace(' APPLICATION ', ' FLEET ')
|
||||
.replace(/ test /g, ' org/test ');
|
||||
}
|
||||
expect(out.join('')).to.equal(expected);
|
||||
expect(err.join('')).to.equal(appToFleetOutputWarn);
|
||||
});
|
||||
|
||||
@ -195,9 +191,7 @@ describe('balena envs', function () {
|
||||
api.expectGetDeviceServiceVars();
|
||||
|
||||
const { out, err } = await runCommand(`envs -jd ${shortUUID}`);
|
||||
|
||||
expect(JSON.parse(out.join(''))).to.deep.equal(
|
||||
JSON.parse(`[
|
||||
let expected = `[
|
||||
{ "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" },
|
||||
@ -206,9 +200,14 @@ describe('balena envs', function () {
|
||||
{ "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": "*" }
|
||||
]`),
|
||||
);
|
||||
|
||||
]`;
|
||||
if (isV13()) {
|
||||
expected = expected.replace(
|
||||
/"appName": "test"/g,
|
||||
'"fleetName": "org/test"',
|
||||
);
|
||||
}
|
||||
expect(JSON.parse(out.join(''))).to.deep.equal(JSON.parse(expected));
|
||||
expect(err.join('')).to.equal('');
|
||||
});
|
||||
|
||||
@ -218,16 +217,23 @@ describe('balena envs', function () {
|
||||
api.expectGetApplication();
|
||||
api.expectGetAppConfigVars();
|
||||
|
||||
const { out, err } = await runCommand(`envs -d ${shortUUID} --config`);
|
||||
|
||||
expect(out.join('')).to.equal(
|
||||
const result = await runCommand(`envs -d ${shortUUID} --config`);
|
||||
const { err } = result;
|
||||
let { out } = result;
|
||||
let expected =
|
||||
stripIndent`
|
||||
ID NAME VALUE APPLICATION DEVICE
|
||||
120300 RESIN_SUPERVISOR_NATIVE_LOGGER false test *
|
||||
120400 RESIN_SUPERVISOR_POLL_INTERVAL 900900 test ${shortUUID}
|
||||
` + '\n',
|
||||
);
|
||||
|
||||
ID NAME VALUE APPLICATION DEVICE
|
||||
120300 RESIN_SUPERVISOR_NATIVE_LOGGER false test *
|
||||
120400 RESIN_SUPERVISOR_POLL_INTERVAL 900900 test ${shortUUID}
|
||||
` + '\n';
|
||||
if (isV13()) {
|
||||
out = out.map((l) => l.replace(/ +/g, ' '));
|
||||
expected = expected
|
||||
.replace(/ +/g, ' ')
|
||||
.replace(' APPLICATION ', ' FLEET ')
|
||||
.replace(/ test /g, ' org/test ');
|
||||
}
|
||||
expect(out.join('')).to.equal(expected);
|
||||
expect(err.join('')).to.equal(appToFleetOutputWarn);
|
||||
});
|
||||
|
||||
@ -242,20 +248,27 @@ describe('balena envs', function () {
|
||||
api.expectGetDeviceEnvVars();
|
||||
|
||||
const uuid = shortUUID;
|
||||
const { out, err } = await runCommand(`envs -d ${uuid} -s ${serviceName}`);
|
||||
|
||||
expect(out.join('')).to.equal(
|
||||
const result = await runCommand(`envs -d ${uuid} -s ${serviceName}`);
|
||||
const { err } = result;
|
||||
let { out } = result;
|
||||
let expected =
|
||||
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',
|
||||
);
|
||||
|
||||
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';
|
||||
if (isV13()) {
|
||||
out = out.map((l) => l.replace(/ +/g, ' '));
|
||||
expected = expected
|
||||
.replace(/ +/g, ' ')
|
||||
.replace(' APPLICATION ', ' FLEET ')
|
||||
.replace(/ test /g, ' org/test ');
|
||||
}
|
||||
expect(out.join('')).to.equal(expected);
|
||||
expect(err.join('')).to.equal(appToFleetOutputWarn);
|
||||
});
|
||||
|
||||
@ -265,18 +278,24 @@ describe('balena envs', function () {
|
||||
api.expectGetDeviceServiceVars();
|
||||
|
||||
const uuid = shortUUID;
|
||||
|
||||
const { out, err } = await runCommand(`envs -d ${uuid}`);
|
||||
|
||||
expect(out.join('')).to.equal(
|
||||
const result = await runCommand(`envs -d ${uuid}`);
|
||||
const { err } = result;
|
||||
let { out } = result;
|
||||
let expected =
|
||||
stripIndent`
|
||||
ID NAME VALUE APPLICATION DEVICE SERVICE
|
||||
120120 svar3 svar3-value N/A ${uuid} service1
|
||||
120121 svar4 svar4-value N/A ${uuid} service2
|
||||
120203 var3 var3-val N/A ${uuid} *
|
||||
120204 var4 44 N/A ${uuid} *
|
||||
` + '\n',
|
||||
);
|
||||
` + '\n';
|
||||
if (isV13()) {
|
||||
out = out.map((l) => l.replace(/ +/g, ' '));
|
||||
expected = expected
|
||||
.replace(/ +/g, ' ')
|
||||
.replace(' APPLICATION ', ' FLEET ');
|
||||
}
|
||||
expect(out.join('')).to.equal(expected);
|
||||
expect(err.join('')).to.equal(appToFleetOutputWarn);
|
||||
});
|
||||
|
||||
@ -291,19 +310,27 @@ describe('balena envs', function () {
|
||||
api.expectGetDeviceServiceVars();
|
||||
|
||||
const uuid = shortUUID;
|
||||
const { out, err } = await runCommand(`envs -d ${uuid} -s ${serviceName}`);
|
||||
|
||||
expect(out.join('')).to.equal(
|
||||
const result = await runCommand(`envs -d ${uuid} -s ${serviceName}`);
|
||||
const { err } = result;
|
||||
let { out } = result;
|
||||
let expected =
|
||||
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',
|
||||
);
|
||||
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';
|
||||
if (isV13()) {
|
||||
out = out.map((l) => l.replace(/ +/g, ' '));
|
||||
expected = expected
|
||||
.replace(/ +/g, ' ')
|
||||
.replace(' APPLICATION ', ' FLEET ')
|
||||
.replace(/ test /g, ' org/test ');
|
||||
}
|
||||
expect(out.join('')).to.equal(expected);
|
||||
expect(err.join('')).to.equal(appToFleetOutputWarn);
|
||||
});
|
||||
|
||||
@ -320,17 +347,21 @@ describe('balena envs', function () {
|
||||
const { out, err } = await runCommand(
|
||||
`envs -d ${shortUUID} -js ${serviceName}`,
|
||||
);
|
||||
|
||||
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}" },
|
||||
{ "id": 120120, "appName": "test", "deviceUUID": "${fullUUID}", "name": "svar3", "value": "svar3-value", "serviceName": "${serviceName}" },
|
||||
{ "id": 120203, "appName": "test", "deviceUUID": "${fullUUID}", "name": "var3", "value": "var3-val", "serviceName": "*" },
|
||||
{ "id": 120204, "appName": "test", "deviceUUID": "${fullUUID}", "name": "var4", "value": "44", "serviceName": "*" }
|
||||
]`),
|
||||
);
|
||||
let expected = `[
|
||||
{ "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}" },
|
||||
{ "id": 120120, "appName": "test", "deviceUUID": "${fullUUID}", "name": "svar3", "value": "svar3-value", "serviceName": "${serviceName}" },
|
||||
{ "id": 120203, "appName": "test", "deviceUUID": "${fullUUID}", "name": "var3", "value": "var3-val", "serviceName": "*" },
|
||||
{ "id": 120204, "appName": "test", "deviceUUID": "${fullUUID}", "name": "var4", "value": "44", "serviceName": "*" }
|
||||
]`;
|
||||
if (isV13()) {
|
||||
expected = expected.replace(
|
||||
/"appName": "test"/g,
|
||||
'"fleetName": "org/test"',
|
||||
);
|
||||
}
|
||||
expect(JSON.parse(out.join(''))).to.deep.equal(JSON.parse(expected));
|
||||
expect(err.join('')).to.equal('');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user