2020-05-13 19:30:30 +00:00
|
|
|
import * as Bluebird from 'bluebird';
|
|
|
|
import * as _ from 'lodash';
|
|
|
|
import { stub } from 'sinon';
|
|
|
|
|
|
|
|
import Network from '../src/compose/network';
|
|
|
|
|
|
|
|
import Service from '../src/compose/service';
|
|
|
|
import Volume from '../src/compose/volume';
|
|
|
|
import DeviceState from '../src/device-state';
|
2020-06-02 16:56:58 +00:00
|
|
|
import * as dockerUtils from '../src/lib/docker-utils';
|
2020-06-09 13:43:45 +00:00
|
|
|
import * as images from '../src/compose/images';
|
2020-05-13 19:30:30 +00:00
|
|
|
|
|
|
|
import chai = require('./lib/chai-config');
|
|
|
|
import prepare = require('./lib/prepare');
|
2020-06-08 09:33:19 +00:00
|
|
|
import * as db from '../src/db';
|
|
|
|
import * as dbFormat from '../src/device-state/db-format';
|
|
|
|
import * as targetStateCache from '../src/device-state/target-state-cache';
|
|
|
|
import * as config from '../src/config';
|
|
|
|
import { TargetApplication, TargetApplications } from '../src/types/state';
|
2020-05-13 19:30:30 +00:00
|
|
|
|
|
|
|
// tslint:disable-next-line
|
|
|
|
chai.use(require('chai-events'));
|
|
|
|
const { expect } = chai;
|
|
|
|
|
|
|
|
let availableImages: any[] | null;
|
|
|
|
let targetState: any[] | null;
|
|
|
|
|
|
|
|
const dependentStateFormat = {
|
|
|
|
appId: 1234,
|
|
|
|
image: 'foo/bar',
|
|
|
|
commit: 'bar',
|
|
|
|
releaseId: 3,
|
|
|
|
name: 'app',
|
|
|
|
config: { RESIN_FOO: 'var' },
|
|
|
|
environment: { FOO: 'var2' },
|
|
|
|
parentApp: 256,
|
|
|
|
imageId: 45,
|
|
|
|
};
|
|
|
|
|
|
|
|
const dependentStateFormatNormalised = {
|
|
|
|
appId: 1234,
|
|
|
|
image: 'foo/bar:latest',
|
|
|
|
commit: 'bar',
|
|
|
|
releaseId: 3,
|
|
|
|
name: 'app',
|
|
|
|
config: { RESIN_FOO: 'var' },
|
|
|
|
environment: { FOO: 'var2' },
|
|
|
|
parentApp: 256,
|
|
|
|
imageId: 45,
|
|
|
|
};
|
|
|
|
|
|
|
|
let currentState = (targetState = availableImages = null);
|
|
|
|
|
|
|
|
const dependentDBFormat = {
|
|
|
|
appId: 1234,
|
|
|
|
image: 'foo/bar:latest',
|
|
|
|
commit: 'bar',
|
|
|
|
releaseId: 3,
|
|
|
|
name: 'app',
|
|
|
|
config: JSON.stringify({ RESIN_FOO: 'var' }),
|
|
|
|
environment: JSON.stringify({ FOO: 'var2' }),
|
|
|
|
parentApp: 256,
|
|
|
|
imageId: 45,
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('ApplicationManager', function () {
|
2020-06-09 13:43:45 +00:00
|
|
|
const originalInspectByName = images.inspectByName;
|
2020-05-28 17:15:33 +00:00
|
|
|
before(async function () {
|
|
|
|
await prepare();
|
2020-05-13 19:30:30 +00:00
|
|
|
this.deviceState = new DeviceState({
|
|
|
|
apiBinder: null as any,
|
|
|
|
});
|
|
|
|
this.applications = this.deviceState.applications;
|
2020-06-09 13:43:45 +00:00
|
|
|
|
|
|
|
// @ts-expect-error assigning to a RO property
|
|
|
|
images.inspectByName = () =>
|
|
|
|
Promise.resolve({
|
2020-05-13 19:30:30 +00:00
|
|
|
Config: {
|
|
|
|
Cmd: ['someCommand'],
|
|
|
|
Entrypoint: ['theEntrypoint'],
|
|
|
|
Env: [],
|
|
|
|
Labels: {},
|
|
|
|
Volumes: [],
|
|
|
|
},
|
2020-06-09 13:43:45 +00:00
|
|
|
});
|
|
|
|
|
2020-06-02 16:56:58 +00:00
|
|
|
stub(dockerUtils, 'getNetworkGateway').returns(
|
2020-05-13 19:30:30 +00:00
|
|
|
Bluebird.Promise.resolve('172.17.0.1'),
|
|
|
|
);
|
2020-06-02 16:56:58 +00:00
|
|
|
stub(dockerUtils.docker, 'listContainers').returns(
|
2020-05-13 19:30:30 +00:00
|
|
|
Bluebird.Promise.resolve([]),
|
|
|
|
);
|
2020-06-02 16:56:58 +00:00
|
|
|
stub(dockerUtils.docker, 'listImages').returns(
|
2020-05-13 19:30:30 +00:00
|
|
|
Bluebird.Promise.resolve([]),
|
|
|
|
);
|
|
|
|
stub(Service as any, 'extendEnvVars').callsFake(function (env) {
|
|
|
|
env['ADDITIONAL_ENV_VAR'] = 'foo';
|
|
|
|
return env;
|
|
|
|
});
|
2020-06-08 09:33:19 +00:00
|
|
|
|
|
|
|
this.normaliseCurrent = async function (current: {
|
|
|
|
local: { apps: Dictionary<TargetApplication> };
|
2020-05-13 19:30:30 +00:00
|
|
|
}) {
|
2020-06-08 09:33:19 +00:00
|
|
|
const currentCloned: any = _.cloneDeep(current);
|
|
|
|
currentCloned.local.apps = {};
|
|
|
|
|
|
|
|
_.each(current.local.apps, (app, appId) => {
|
|
|
|
const appCloned = {
|
|
|
|
...app,
|
|
|
|
services: _.mapValues(app.services, (svc) =>
|
|
|
|
// @ts-ignore
|
|
|
|
Service.fromComposeObject(svc, { appName: 'test' }),
|
|
|
|
),
|
|
|
|
networks: _.mapValues(app.networks, (conf, name) =>
|
|
|
|
Network.fromComposeObject(name, parseInt(appId, 10), conf),
|
|
|
|
),
|
|
|
|
volumes: _.mapValues(app.volumes, (conf, name) =>
|
|
|
|
Volume.fromComposeObject(name, parseInt(appId, 10), conf),
|
|
|
|
),
|
|
|
|
};
|
|
|
|
currentCloned.local.apps[parseInt(appId, 10)] = appCloned;
|
2020-05-13 19:30:30 +00:00
|
|
|
});
|
2020-06-08 09:33:19 +00:00
|
|
|
return currentCloned;
|
2020-05-13 19:30:30 +00:00
|
|
|
};
|
|
|
|
|
2020-06-08 09:33:19 +00:00
|
|
|
this.normaliseTarget = async (
|
2020-05-13 19:30:30 +00:00
|
|
|
target: {
|
2020-06-08 09:33:19 +00:00
|
|
|
local: { apps: TargetApplications };
|
2020-05-13 19:30:30 +00:00
|
|
|
},
|
|
|
|
available: any,
|
|
|
|
) => {
|
2020-06-08 09:33:19 +00:00
|
|
|
const source = await config.get('apiEndpoint');
|
|
|
|
const cloned: any = _.cloneDeep(target);
|
|
|
|
|
|
|
|
// @ts-ignore types don't quite match up
|
|
|
|
await dbFormat.setApps(target.local.apps, source);
|
|
|
|
|
|
|
|
cloned.local.apps = await dbFormat.getApps();
|
|
|
|
|
|
|
|
// We mock what createTargetService does when an image is available
|
|
|
|
_.each(cloned.local.apps, (app) => {
|
|
|
|
_.each(app.services, (svc) => {
|
|
|
|
const img = _.find(available, (i) => i.name === svc.config.image);
|
|
|
|
if (img != null) {
|
|
|
|
svc.config.image = img.dockerImageId;
|
|
|
|
}
|
2020-05-13 19:30:30 +00:00
|
|
|
});
|
|
|
|
});
|
2020-06-08 09:33:19 +00:00
|
|
|
return cloned;
|
2020-05-13 19:30:30 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2020-06-08 09:33:19 +00:00
|
|
|
beforeEach(async () => {
|
|
|
|
({
|
|
|
|
currentState,
|
|
|
|
targetState,
|
|
|
|
availableImages,
|
|
|
|
} = require('./lib/application-manager-test-states'));
|
|
|
|
await db.models('app').del();
|
|
|
|
// @ts-expect-error modification of a RO property
|
|
|
|
targetStateCache.targetState = undefined;
|
|
|
|
});
|
2020-05-13 19:30:30 +00:00
|
|
|
|
2020-06-08 09:33:19 +00:00
|
|
|
after(async function () {
|
2020-06-09 13:43:45 +00:00
|
|
|
// @ts-expect-error Assigning to a RO property
|
|
|
|
images.inspectByName = originalInspectByName;
|
2020-06-02 16:56:58 +00:00
|
|
|
// @ts-expect-error restore on non-stubbed type
|
|
|
|
dockerUtils.getNetworkGateway.restore();
|
|
|
|
// @ts-expect-error restore on non-stubbed type
|
|
|
|
dockerUtils.docker.listContainers.restore();
|
|
|
|
// @ts-expect-error restore on non-stubbed type
|
|
|
|
dockerUtils.docker.listImages.restore();
|
2020-06-08 09:33:19 +00:00
|
|
|
// @ts-expect-error use of private function
|
|
|
|
Service.extendEnvVars.restore();
|
|
|
|
|
|
|
|
await db.models('app').del();
|
|
|
|
// @ts-expect-error modification of a RO property
|
|
|
|
targetStateCache.targetState = undefined;
|
2020-05-13 19:30:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should init', function () {
|
|
|
|
return this.applications.init();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('infers a start step when all that changes is a running state', function () {
|
|
|
|
return Bluebird.Promise.join(
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseCurrent(currentState[0]),
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseTarget(targetState[0], availableImages[0]),
|
|
|
|
(current, target) => {
|
|
|
|
const steps = this.applications._inferNextSteps(
|
|
|
|
false,
|
|
|
|
// @ts-ignore
|
|
|
|
availableImages[0],
|
|
|
|
[],
|
|
|
|
true,
|
|
|
|
current,
|
|
|
|
target,
|
|
|
|
false,
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
return expect(steps).to.eventually.deep.equal([
|
|
|
|
{
|
|
|
|
action: 'start',
|
2020-06-08 09:33:19 +00:00
|
|
|
current: current.local.apps['1234'].services[24],
|
|
|
|
target: target.local.apps['1234'].services[24],
|
2020-05-13 19:30:30 +00:00
|
|
|
serviceId: 24,
|
|
|
|
appId: 1234,
|
|
|
|
options: {},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('infers a kill step when a service has to be removed', function () {
|
|
|
|
return Bluebird.Promise.join(
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseCurrent(currentState[0]),
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseTarget(targetState[1], availableImages[0]),
|
|
|
|
(current, target) => {
|
|
|
|
const steps = this.applications._inferNextSteps(
|
|
|
|
false,
|
|
|
|
// @ts-ignore
|
|
|
|
availableImages[0],
|
|
|
|
[],
|
|
|
|
true,
|
|
|
|
current,
|
|
|
|
target,
|
|
|
|
false,
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
return expect(steps).to.eventually.deep.equal([
|
|
|
|
{
|
|
|
|
action: 'kill',
|
2020-06-08 09:33:19 +00:00
|
|
|
current: current.local.apps['1234'].services[24],
|
2020-05-13 19:30:30 +00:00
|
|
|
target: undefined,
|
|
|
|
serviceId: 24,
|
|
|
|
appId: 1234,
|
|
|
|
options: {},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('infers a fetch step when a service has to be updated', function () {
|
|
|
|
return Bluebird.Promise.join(
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseCurrent(currentState[0]),
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseTarget(targetState[2], availableImages[0]),
|
|
|
|
(current, target) => {
|
|
|
|
const steps = this.applications._inferNextSteps(
|
|
|
|
false,
|
|
|
|
// @ts-ignore
|
|
|
|
availableImages[0],
|
|
|
|
[],
|
|
|
|
true,
|
|
|
|
current,
|
|
|
|
target,
|
|
|
|
false,
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
return expect(steps).to.eventually.deep.equal([
|
|
|
|
{
|
|
|
|
action: 'fetch',
|
|
|
|
image: this.applications.imageForService(
|
2020-06-08 09:33:19 +00:00
|
|
|
target.local.apps['1234'].services[24],
|
2020-05-13 19:30:30 +00:00
|
|
|
),
|
|
|
|
serviceId: 24,
|
|
|
|
appId: 1234,
|
|
|
|
serviceName: 'anotherService',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not infer a fetch step when the download is already in progress', function () {
|
|
|
|
return Bluebird.Promise.join(
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseCurrent(currentState[0]),
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseTarget(targetState[2], availableImages[0]),
|
|
|
|
(current, target) => {
|
|
|
|
const steps = this.applications._inferNextSteps(
|
|
|
|
false,
|
|
|
|
// @ts-ignore
|
|
|
|
availableImages[0],
|
2020-06-08 09:33:19 +00:00
|
|
|
[target.local.apps['1234'].services[24].imageId],
|
2020-05-13 19:30:30 +00:00
|
|
|
true,
|
|
|
|
current,
|
|
|
|
target,
|
|
|
|
false,
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
return expect(steps).to.eventually.deep.equal([
|
|
|
|
{ action: 'noop', appId: 1234 },
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('infers a kill step when a service has to be updated but the strategy is kill-then-download', function () {
|
|
|
|
return Bluebird.Promise.join(
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseCurrent(currentState[0]),
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseTarget(targetState[3], availableImages[0]),
|
|
|
|
(current, target) => {
|
|
|
|
const steps = this.applications._inferNextSteps(
|
|
|
|
false,
|
|
|
|
// @ts-ignore
|
|
|
|
availableImages[0],
|
|
|
|
[],
|
|
|
|
true,
|
|
|
|
current,
|
|
|
|
target,
|
|
|
|
false,
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
return expect(steps).to.eventually.deep.equal([
|
|
|
|
{
|
|
|
|
action: 'kill',
|
2020-06-08 09:33:19 +00:00
|
|
|
current: current.local.apps['1234'].services[24],
|
|
|
|
target: target.local.apps['1234'].services[24],
|
2020-05-13 19:30:30 +00:00
|
|
|
serviceId: 24,
|
|
|
|
appId: 1234,
|
|
|
|
options: {},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not infer to kill a service with default strategy if a dependency is not downloaded', function () {
|
|
|
|
return Bluebird.Promise.join(
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseCurrent(currentState[4]),
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseTarget(targetState[4], availableImages[2]),
|
|
|
|
(current, target) => {
|
|
|
|
const steps = this.applications._inferNextSteps(
|
|
|
|
false,
|
|
|
|
// @ts-ignore
|
|
|
|
availableImages[2],
|
|
|
|
[],
|
|
|
|
true,
|
|
|
|
current,
|
|
|
|
target,
|
|
|
|
false,
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
return expect(steps).to.eventually.have.deep.members([
|
|
|
|
{
|
|
|
|
action: 'fetch',
|
|
|
|
image: this.applications.imageForService(
|
2020-06-08 09:33:19 +00:00
|
|
|
target.local.apps['1234'].services[23],
|
2020-05-13 19:30:30 +00:00
|
|
|
),
|
|
|
|
serviceId: 23,
|
|
|
|
appId: 1234,
|
|
|
|
serviceName: 'aservice',
|
|
|
|
},
|
|
|
|
{ action: 'noop', appId: 1234 },
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('infers to kill several services as long as there is no unmet dependency', function () {
|
|
|
|
return Bluebird.Promise.join(
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseCurrent(currentState[0]),
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseTarget(targetState[5], availableImages[1]),
|
|
|
|
(current, target) => {
|
|
|
|
const steps = this.applications._inferNextSteps(
|
|
|
|
false,
|
|
|
|
// @ts-ignore
|
|
|
|
availableImages[1],
|
|
|
|
[],
|
|
|
|
true,
|
|
|
|
current,
|
|
|
|
target,
|
|
|
|
false,
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
return expect(steps).to.eventually.have.deep.members([
|
|
|
|
{
|
|
|
|
action: 'kill',
|
2020-06-08 09:33:19 +00:00
|
|
|
current: current.local.apps['1234'].services[23],
|
|
|
|
target: target.local.apps['1234'].services[23],
|
2020-05-13 19:30:30 +00:00
|
|
|
serviceId: 23,
|
|
|
|
appId: 1234,
|
|
|
|
options: {},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: 'kill',
|
2020-06-08 09:33:19 +00:00
|
|
|
current: current.local.apps['1234'].services[24],
|
|
|
|
target: target.local.apps['1234'].services[24],
|
2020-05-13 19:30:30 +00:00
|
|
|
serviceId: 24,
|
|
|
|
appId: 1234,
|
|
|
|
options: {},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('infers to start the dependency first', function () {
|
|
|
|
return Bluebird.Promise.join(
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseCurrent(currentState[1]),
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseTarget(targetState[4], availableImages[1]),
|
|
|
|
(current, target) => {
|
|
|
|
const steps = this.applications._inferNextSteps(
|
|
|
|
false,
|
|
|
|
// @ts-ignore
|
|
|
|
availableImages[1],
|
|
|
|
[],
|
|
|
|
true,
|
|
|
|
current,
|
|
|
|
target,
|
|
|
|
false,
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
return expect(steps).to.eventually.have.deep.members([
|
|
|
|
{
|
|
|
|
action: 'start',
|
|
|
|
current: null,
|
2020-06-08 09:33:19 +00:00
|
|
|
target: target.local.apps['1234'].services[23],
|
2020-05-13 19:30:30 +00:00
|
|
|
serviceId: 23,
|
|
|
|
appId: 1234,
|
|
|
|
options: {},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('infers to start a service once its dependency has been met', function () {
|
|
|
|
return Bluebird.Promise.join(
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseCurrent(currentState[2]),
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseTarget(targetState[4], availableImages[1]),
|
|
|
|
(current, target) => {
|
|
|
|
const steps = this.applications._inferNextSteps(
|
|
|
|
false,
|
|
|
|
// @ts-ignore
|
|
|
|
availableImages[1],
|
|
|
|
[],
|
|
|
|
true,
|
|
|
|
current,
|
|
|
|
target,
|
|
|
|
false,
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
return expect(steps).to.eventually.have.deep.members([
|
|
|
|
{
|
|
|
|
action: 'start',
|
|
|
|
current: null,
|
2020-06-08 09:33:19 +00:00
|
|
|
target: target.local.apps['1234'].services[24],
|
2020-05-13 19:30:30 +00:00
|
|
|
serviceId: 24,
|
|
|
|
appId: 1234,
|
|
|
|
options: {},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('infers to remove spurious containers', function () {
|
|
|
|
return Bluebird.Promise.join(
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseCurrent(currentState[3]),
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseTarget(targetState[4], availableImages[1]),
|
|
|
|
(current, target) => {
|
|
|
|
const steps = this.applications._inferNextSteps(
|
|
|
|
false,
|
|
|
|
// @ts-ignore
|
|
|
|
availableImages[1],
|
|
|
|
[],
|
|
|
|
true,
|
|
|
|
current,
|
|
|
|
target,
|
|
|
|
false,
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
return expect(steps).to.eventually.have.deep.members([
|
|
|
|
{
|
|
|
|
action: 'kill',
|
2020-06-08 09:33:19 +00:00
|
|
|
current: current.local.apps['1234'].services[23],
|
2020-05-13 19:30:30 +00:00
|
|
|
target: undefined,
|
|
|
|
serviceId: 23,
|
|
|
|
appId: 1234,
|
|
|
|
options: {},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: 'start',
|
|
|
|
current: null,
|
2020-06-08 09:33:19 +00:00
|
|
|
target: target.local.apps['1234'].services[24],
|
2020-05-13 19:30:30 +00:00
|
|
|
serviceId: 24,
|
|
|
|
appId: 1234,
|
|
|
|
options: {},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('converts a dependent app from a state format to a db format, normalising the image name', function () {
|
|
|
|
const app = this.applications.proxyvisor.normaliseDependentAppForDB(
|
|
|
|
dependentStateFormat,
|
|
|
|
);
|
|
|
|
return expect(app).to.eventually.deep.equal(dependentDBFormat);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('converts a dependent app in DB format into state format', function () {
|
|
|
|
const app = this.applications.proxyvisor.normaliseDependentAppFromDB(
|
|
|
|
dependentDBFormat,
|
|
|
|
);
|
|
|
|
return expect(app).to.eventually.deep.equal(dependentStateFormatNormalised);
|
|
|
|
});
|
|
|
|
|
|
|
|
return describe('Volumes', function () {
|
|
|
|
before(function () {
|
|
|
|
return stub(this.applications, 'removeAllVolumesForApp').returns(
|
|
|
|
Bluebird.Promise.resolve([
|
|
|
|
{
|
|
|
|
action: 'removeVolume',
|
2020-06-08 12:57:31 +00:00
|
|
|
current: Volume.fromComposeObject('my_volume', 12, {}),
|
2020-05-13 19:30:30 +00:00
|
|
|
},
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
return this.applications.removeAllVolumesForApp.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not remove volumes when they are no longer referenced', function () {
|
|
|
|
return Bluebird.Promise.join(
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseCurrent(currentState[6]),
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseTarget(targetState[0], availableImages[0]),
|
|
|
|
(current, target) => {
|
|
|
|
return this.applications
|
|
|
|
._inferNextSteps(
|
|
|
|
false,
|
|
|
|
// @ts-ignore
|
|
|
|
availableImages[0],
|
|
|
|
[],
|
|
|
|
true,
|
|
|
|
current,
|
|
|
|
target,
|
|
|
|
false,
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
)
|
|
|
|
.then(
|
|
|
|
// @ts-ignore
|
|
|
|
(steps) =>
|
|
|
|
expect(
|
|
|
|
_.every(steps, (s) => s.action !== 'removeVolume'),
|
|
|
|
'Volumes from current app should not be removed',
|
|
|
|
).to.be.true,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-06-08 09:33:19 +00:00
|
|
|
it('should remove volumes from previous applications', function () {
|
2020-05-13 19:30:30 +00:00
|
|
|
return Bluebird.Promise.join(
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseCurrent(currentState[5]),
|
|
|
|
// @ts-ignore
|
|
|
|
this.normaliseTarget(targetState[6], []),
|
|
|
|
(current, target) => {
|
|
|
|
return (
|
|
|
|
this.applications
|
|
|
|
._inferNextSteps(
|
|
|
|
false,
|
|
|
|
[],
|
|
|
|
[],
|
|
|
|
true,
|
|
|
|
current,
|
|
|
|
target,
|
|
|
|
false,
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
)
|
|
|
|
// tslint:disable-next-line
|
|
|
|
.then(function (steps: { current: any }[]) {
|
|
|
|
expect(steps).to.have.length(1);
|
|
|
|
expect(steps[0])
|
|
|
|
.to.have.property('action')
|
|
|
|
.that.equals('removeVolume');
|
|
|
|
return expect(steps[0].current)
|
|
|
|
.to.have.property('appId')
|
|
|
|
.that.equals(12);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|