Update tests removing dependency on db ids

This commit is contained in:
Felipe Lalanne 2021-07-23 12:48:27 -04:00
parent b67f94802d
commit 50aab3ba78
3 changed files with 324 additions and 524 deletions

View File

@ -86,7 +86,6 @@ describe('DB Format', () => {
expect(app).to.be.an.instanceOf(App);
expect(app).to.have.property('appId').that.equals(1);
expect(app).to.have.property('commit').that.equals('abcdef');
expect(app).to.have.property('releaseId').that.equals(123);
expect(app).to.have.property('appName').that.equals('test-app');
expect(app)
.to.have.property('source')

View File

@ -15,9 +15,9 @@ import log from '../../../src/lib/supervisor-console';
const defaultContext = {
localMode: false,
availableImages: [],
availableImages: [] as Image[],
containerIds: {},
downloading: [],
downloading: [] as string[],
};
function createApp({
@ -42,26 +42,22 @@ function createApp({
}
async function createService(
conf = {} as Partial<ServiceComposeConfig>,
{
appId = 1,
serviceName = 'test',
releaseId = 2,
serviceId = 3,
imageId = 4,
state = {} as Partial<Service>,
} = {},
commit = 'test-commit',
...conf
} = {} as Partial<ServiceComposeConfig>,
{ state = {} as Partial<Service>, options = {} as any } = {},
) {
const svc = await Service.fromComposeObject(
{
appId,
serviceName,
releaseId,
serviceId,
imageId,
commit,
...conf,
},
{} as any,
options,
);
// Add additonal configuration
@ -71,6 +67,18 @@ async function createService(
return svc;
}
function createImage(
{
appId = 1,
dependent = 0,
name = 'test-image',
serviceName = 'test',
...extra
} = {} as Partial<Image>,
) {
return { appId, dependent, name, serviceName, ...extra } as Image;
}
const expectSteps = (
action: CompositionStepAction,
steps: CompositionStep[],
@ -298,15 +306,10 @@ describe('compose/app', () => {
...defaultContext,
...{
availableImages: [
{
createImage({
appId: service.appId,
dependent: 0,
imageId: service.imageId,
releaseId: service.releaseId,
serviceId: service.serviceId,
name: 'test-image',
serviceName: service.serviceName,
} as Image,
}),
],
},
};
@ -488,7 +491,7 @@ describe('compose/app', () => {
networks: [Network.fromComposeObject('test-network', 1, {})],
});
const target = createApp({
services: [await createService({})],
services: [await createService()],
networks: [],
isTarget: true,
});
@ -557,24 +560,13 @@ describe('compose/app', () => {
it('should create a kill step for service which is no longer referenced', async () => {
const current = createApp({
services: [
await createService(
{},
{ appId: 1, serviceName: 'main', releaseId: 1, serviceId: 1 },
),
await createService(
{},
{ appId: 1, serviceName: 'aux', releaseId: 1, serviceId: 2 },
),
await createService({ appId: 1, serviceName: 'main' }),
await createService({ appId: 1, serviceName: 'aux' }),
],
networks: [Network.fromComposeObject('test-network', 1, {})],
});
const target = createApp({
services: [
await createService(
{},
{ appId: 1, serviceName: 'main', releaseId: 1, serviceId: 1 },
),
],
services: [await createService({ appId: 1, serviceName: 'main' })],
networks: [Network.fromComposeObject('test-network', 1, {})],
isTarget: true,
});
@ -590,8 +582,8 @@ describe('compose/app', () => {
const current = createApp({
services: [
await createService(
{},
{ serviceName: 'main', state: { status: 'Stopping' } },
{ serviceName: 'main' },
{ state: { status: 'Stopping' } },
),
],
});
@ -608,13 +600,13 @@ describe('compose/app', () => {
const current = createApp({
services: [
await createService(
{},
{ serviceName: 'main', state: { status: 'Dead' } },
{ serviceName: 'main' },
{ state: { status: 'Dead' } },
),
],
});
const target = createApp({
services: [await createService({}, { serviceName: 'main' })],
services: [await createService({ serviceName: 'main' })],
isTarget: true,
});
@ -630,8 +622,8 @@ describe('compose/app', () => {
const current = createApp({
services: [
await createService(
{},
{ serviceName: 'main', state: { status: 'Dead' } },
{ serviceName: 'main' },
{ state: { status: 'Dead' } },
),
],
});
@ -649,13 +641,13 @@ describe('compose/app', () => {
const current = createApp({ services: [] });
const target = createApp({
services: [
await createService({}, { serviceName: 'main', imageId: 123 }),
await createService({ image: 'main-image', serviceName: 'main' }),
],
isTarget: true,
});
const steps = current.nextStepsForAppUpdate(
{ ...defaultContext, ...{ downloading: [123] } },
{ ...defaultContext, ...{ downloading: ['main-image'] } },
target,
);
expectSteps('noop', steps);
@ -665,12 +657,12 @@ describe('compose/app', () => {
it('should emit an updateMetadata step when a service has not changed but the release has', async () => {
const current = createApp({
services: [
await createService({}, { serviceName: 'main', releaseId: 1 }),
await createService({ serviceName: 'main', commit: 'old-release' }),
],
});
const target = createApp({
services: [
await createService({}, { serviceName: 'main', releaseId: 2 }),
await createService({ serviceName: 'main', commit: 'new-release' }),
],
isTarget: true,
});
@ -680,20 +672,20 @@ describe('compose/app', () => {
expect(updateMetadataStep)
.to.have.property('current')
.to.deep.include({ serviceName: 'main', releaseId: 1 });
.to.deep.include({ serviceName: 'main', commit: 'old-release' });
expect(updateMetadataStep)
.to.have.property('target')
.to.deep.include({ serviceName: 'main', releaseId: 2 });
.to.deep.include({ serviceName: 'main', commit: 'new-release' });
});
it('should stop a container which has `running: false` as its target', async () => {
const current = createApp({
services: [await createService({}, { serviceName: 'main' })],
services: [await createService({ serviceName: 'main' })],
});
const target = createApp({
services: [
await createService({ running: false }, { serviceName: 'main' }),
await createService({ running: false, serviceName: 'main' }),
],
isTarget: true,
});
@ -745,30 +737,23 @@ describe('compose/app', () => {
...defaultContext,
...{
availableImages: [
{
appId: 1,
dependent: 0,
imageId: 1,
releaseId: 1,
serviceId: 1,
name: 'main-image',
serviceName: 'main',
},
createImage({ appId: 1, serviceName: 'main', name: 'main-image' }),
],
},
};
const current = createApp({
services: [await createService({}, { appId: 1, serviceName: 'main' })],
services: [await createService({ appId: 1, serviceName: 'main' })],
// Default network was already created
networks: [defaultNetwork],
});
const target = createApp({
services: [
await createService(
{ privileged: true },
{ appId: 1, serviceName: 'main' },
),
await createService({
privileged: true,
appId: 1,
serviceName: 'main',
}),
],
networks: [defaultNetwork],
isTarget: true,
@ -809,36 +794,20 @@ describe('compose/app', () => {
it('should not start a container when it depends on a service which is being installed', async () => {
const availableImages = [
{
appId: 1,
dependent: 0,
imageId: 1,
releaseId: 1,
serviceId: 1,
name: 'main-image',
serviceName: 'main',
},
{
appId: 1,
dependent: 0,
imageId: 2,
releaseId: 1,
serviceId: 2,
name: 'dep-image',
serviceName: 'dep',
},
createImage({ appId: 1, serviceName: 'main', name: 'main-image' }),
createImage({ appId: 1, serviceName: 'dep', name: 'dep-image' }),
];
const contextWithImages = { ...defaultContext, ...{ availableImages } };
const current = createApp({
services: [
await createService(
{ running: false },
{
running: false,
appId: 1,
serviceName: 'dep',
serviceId: 2,
imageId: 2,
},
{
state: {
status: 'Installing',
containerId: 'dep-id',
@ -850,25 +819,15 @@ describe('compose/app', () => {
});
const target = createApp({
services: [
await createService(
{},
{
appId: 1,
serviceName: 'main',
serviceId: 1,
imageId: 1,
state: { dependsOn: ['dep'] },
},
),
await createService(
{},
{
appId: 1,
serviceName: 'dep',
serviceId: 2,
imageId: 2,
},
),
await createService({
appId: 1,
serviceName: 'main',
dependsOn: ['dep'],
}),
await createService({
appId: 1,
serviceName: 'dep',
}),
],
networks: [defaultNetwork],
isTarget: true,
@ -889,16 +848,8 @@ describe('compose/app', () => {
const intermediate = createApp({
services: [
await createService(
{},
{
appId: 1,
serviceName: 'dep',
serviceId: 2,
imageId: 2,
state: {
containerId: 'dep-id',
},
},
{ appId: 1, serviceName: 'dep' },
{ state: { containerId: 'dep-id' } },
),
],
networks: [defaultNetwork],
@ -931,26 +882,18 @@ describe('compose/app', () => {
...defaultContext,
...{
availableImages: [
{
appId: 1,
dependent: 0,
imageId: 1,
releaseId: 1,
serviceId: 1,
name: 'main-image',
serviceName: 'main',
},
createImage({ appId: 1, name: 'main-image', serviceName: 'main' }),
],
},
};
const current = createApp({
services: [
await createService({ running: false }, { serviceName: 'main' }),
await createService({ running: false, serviceName: 'main' }),
],
networks: [defaultNetwork],
});
const target = createApp({
services: [await createService({}, { serviceName: 'main' })],
services: [await createService({ serviceName: 'main' })],
networks: [defaultNetwork],
isTarget: true,
});
@ -969,15 +912,7 @@ describe('compose/app', () => {
...defaultContext,
...{
availableImages: [
{
appId: 1,
dependent: 0,
imageId: 1,
releaseId: 1,
serviceId: 1,
name: 'main-image',
serviceName: 'main',
},
createImage({ appId: 1, name: 'main-image', serviceName: 'main' }),
],
},
};
@ -988,31 +923,23 @@ describe('compose/app', () => {
const current = createApp({
services: [
await createService(
{ labels, image: 'main-image' },
{
appId: 1,
serviceName: 'main',
releaseId: 1,
serviceId: 1,
imageId: 1,
},
),
await createService({
labels,
image: 'main-image',
serviceName: 'main',
commit: 'old-release',
}),
],
networks: [defaultNetwork],
});
const target = createApp({
services: [
await createService(
{ labels, image: 'main-image-2' },
{
appId: 1,
serviceName: 'main',
releaseId: 2, // new release
serviceId: 1,
imageId: 2, // new image id
},
),
await createService({
labels,
image: 'main-image-2',
serviceName: 'main',
commit: 'new-release',
}),
],
networks: [defaultNetwork],
isTarget: true,
@ -1049,86 +976,52 @@ describe('compose/app', () => {
const contextWithImages = {
...defaultContext,
...{
downloading: [4], // The depended service image is being downloaded
downloading: ['dep-image-2'], // The depended service image is being downloaded
availableImages: [
{
createImage({ appId: 1, name: 'main-image', serviceName: 'main' }),
createImage({ appId: 1, name: 'dep-image', serviceName: 'dep' }),
createImage({
appId: 1,
releaseId: 1,
dependent: 0,
name: 'main-image',
imageId: 1,
serviceName: 'main',
serviceId: 1,
},
{
appId: 1,
releaseId: 1,
dependent: 0,
name: 'dep-image',
imageId: 2,
serviceName: 'dep',
serviceId: 2,
},
{
appId: 1,
releaseId: 2,
dependent: 0,
name: 'main-image-2',
imageId: 3,
serviceName: 'main',
serviceId: 1,
},
}),
],
},
};
const current = createApp({
services: [
await createService(
{ image: 'main-image', dependsOn: ['dep'] },
{
appId: 1,
serviceName: 'main',
releaseId: 1,
serviceId: 1,
imageId: 1,
},
),
await createService(
{ image: 'dep-image' },
{
appId: 1,
serviceName: 'dep',
releaseId: 1,
serviceId: 2,
imageId: 2,
},
),
await createService({
image: 'main-image',
dependsOn: ['dep'],
appId: 1,
serviceName: 'main',
commit: 'old-release',
}),
await createService({
image: 'dep-image',
appId: 1,
serviceName: 'dep',
commit: 'old-release',
}),
],
networks: [defaultNetwork],
});
const target = createApp({
services: [
await createService(
{ image: 'main-image-2', dependsOn: ['dep'] },
{
appId: 1,
serviceName: 'main',
releaseId: 2, // new release
serviceId: 1,
imageId: 3, // image has changed
},
),
await createService(
{ image: 'dep-image-2' },
{
appId: 1,
serviceName: 'dep',
releaseId: 2,
serviceId: 2,
imageId: 4,
},
),
await createService({
image: 'main-image-2',
dependsOn: ['dep'],
appId: 1,
serviceName: 'main',
commit: 'new-release',
}),
await createService({
image: 'dep-image-2',
appId: 1,
serviceName: 'dep',
commit: 'new-release',
}),
],
networks: [defaultNetwork],
isTarget: true,
@ -1144,44 +1037,34 @@ describe('compose/app', () => {
...defaultContext,
...{
availableImages: [
{
createImage({ appId: 1, name: 'main-image', serviceName: 'main' }),
createImage({
appId: 1,
releaseId: 1,
dependent: 0,
name: 'main-image',
imageId: 1,
serviceName: 'main',
serviceId: 1,
},
{
appId: 1,
releaseId: 2,
dependent: 0,
name: 'main-image-2',
imageId: 2,
serviceName: 'main',
serviceId: 1,
},
}),
],
},
};
const current = createApp({
services: [
await createService(
{ image: 'main-image' },
{ serviceName: 'main', releaseId: 1, serviceId: 1, imageId: 1 },
),
await createService({
image: 'main-image',
serviceName: 'main',
commit: 'old-release',
}),
],
networks: [defaultNetwork],
});
const target = createApp({
services: [
await createService(
{ image: 'main-image-2' },
await createService({
image: 'main-image-2',
// new release as target
{ serviceName: 'main', releaseId: 2, serviceId: 1, imageId: 2 },
),
serviceName: 'main',
commit: 'new-release',
}),
],
networks: [defaultNetwork],
isTarget: true,
@ -1238,7 +1121,7 @@ describe('compose/app', () => {
it('should not create a service when a network it depends on is not ready', async () => {
const current = createApp({ networks: [defaultNetwork] });
const target = createApp({
services: [await createService({ networks: ['test'] }, { appId: 1 })],
services: [await createService({ networks: ['test'], appId: 1 })],
networks: [defaultNetwork, Network.fromComposeObject('test', 1, {})],
isTarget: true,
});
@ -1256,50 +1139,30 @@ describe('compose/app', () => {
it('should create several kill steps as long as there are no unmet dependencies', async () => {
const current = createApp({
services: [
await createService(
{},
{
appId: 1,
serviceName: 'one',
releaseId: 1,
serviceId: 1,
imageId: 1,
},
),
await createService(
{},
{
appId: 1,
serviceName: 'two',
releaseId: 1,
serviceId: 2,
imageId: 2,
},
),
await createService(
{},
{
appId: 1,
serviceName: 'three',
releaseId: 1,
serviceId: 3,
imageId: 3,
},
),
await createService({
appId: 1,
serviceName: 'one',
commit: 'old-release',
}),
await createService({
appId: 1,
serviceName: 'two',
commit: 'old-release',
}),
await createService({
appId: 1,
serviceName: 'three',
commit: 'old-release',
}),
],
});
const target = createApp({
services: [
await createService(
{},
{
appId: 1,
serviceName: 'three',
releaseId: 1,
serviceId: 3,
imageId: 3,
},
),
await createService({
appId: 1,
serviceName: 'three',
commit: 'new-release',
}),
],
isTarget: true,
});
@ -1313,7 +1176,7 @@ describe('compose/app', () => {
it('should emit a fetch step when an image has not been downloaded for a service', async () => {
const current = createApp({ services: [] });
const target = createApp({
services: [await createService({}, { serviceName: 'main' })],
services: [await createService({ serviceName: 'main' })],
isTarget: true,
});
@ -1328,13 +1191,13 @@ describe('compose/app', () => {
const contextWithDownloading = {
...defaultContext,
...{
downloading: [1],
downloading: ['image2'],
},
};
const current = createApp({ services: [] });
const target = createApp({
services: [
await createService({}, { serviceName: 'main', imageId: 1 }),
await createService({ image: 'image2', serviceName: 'main' }),
],
isTarget: true,
});

View File

@ -18,24 +18,25 @@ import * as dbHelper from '../../lib/db-helper';
const DEFAULT_NETWORK = Network.fromComposeObject('default', 1, {});
async function createService(
conf = {} as Partial<ServiceComposeConfig>,
{
appId = 1,
serviceName = 'main',
releaseId = 1,
serviceId = 1,
imageId = 1,
state = {} as Partial<Service>,
options = {} as any,
} = {},
commit = 'main-commit',
...conf
} = {} as Partial<ServiceComposeConfig>,
{ state = {} as Partial<Service>, options = {} as any } = {},
) {
const svc = await Service.fromComposeObject(
{
appId,
serviceName,
releaseId,
serviceId,
imageId,
commit,
// db ids should not be used for target state calculation, but images
// are compared using _.isEqual so leaving this here to have image comparisons
// match
serviceId: 1,
imageId: 1,
releaseId: 1,
...conf,
},
options,
@ -48,11 +49,28 @@ async function createService(
return svc;
}
function createImage(svc: Service) {
function createImage(
{
appId = 1,
dependent = 0,
name = 'test-image',
serviceName = 'test',
...extra
} = {} as Partial<Image>,
) {
return {
dockerImageId: svc.config.image,
...imageManager.imageFromService(svc),
};
appId,
dependent,
name,
serviceName,
// db ids should not be used for target state calculation, but images
// are compared using _.isEqual so leaving this here to have image comparisons
// match
imageId: 1,
releaseId: 1,
serviceId: 1,
...extra,
} as Image;
}
function createApps(
@ -110,8 +128,12 @@ function createCurrentState({
services = [] as Service[],
networks = [] as Network[],
volumes = [] as Volume[],
images = services.map((s) => createImage(s)) as Image[],
downloading = [] as number[],
images = services.map((s) => ({
// Infer images from services by default
dockerImageId: s.config.image,
...imageManager.imageFromService(s),
})) as Image[],
downloading = [] as string[],
}) {
const currentApps = createApps({ services, networks, volumes });
@ -183,7 +205,7 @@ describe('compose/application-manager', () => {
it('infers a start step when all that changes is a running state', async () => {
const targetApps = createApps(
{
services: [await createService({ running: true }, { appId: 1 })],
services: [await createService({ running: true, appId: 1 })],
networks: [DEFAULT_NETWORK],
},
true,
@ -194,7 +216,7 @@ describe('compose/application-manager', () => {
downloading,
containerIdsByAppId,
} = createCurrentState({
services: [await createService({ running: false }, { appId: 1 })],
services: [await createService({ running: false, appId: 1 })],
networks: [DEFAULT_NETWORK],
});
@ -251,12 +273,7 @@ describe('compose/application-manager', () => {
it('infers a fetch step when a service has to be updated', async () => {
const targetApps = createApps(
{
services: [
await createService(
{ image: 'image-new' },
{ appId: 1, imageId: 2, options: {} },
),
],
services: [await createService({ image: 'image-new', appId: 1 })],
networks: [DEFAULT_NETWORK],
},
true,
@ -267,7 +284,7 @@ describe('compose/application-manager', () => {
downloading,
containerIdsByAppId,
} = createCurrentState({
services: [await createService({}, { appId: 1, imageId: 1 })],
services: [await createService({ appId: 1 })],
networks: [DEFAULT_NETWORK],
images: [],
});
@ -291,9 +308,7 @@ describe('compose/application-manager', () => {
it('does not infer a fetch step when the download is already in progress', async () => {
const targetApps = createApps(
{
services: [
await createService({ image: 'image-new' }, { appId: 1, imageId: 2 }),
],
services: [await createService({ image: 'image-new', appId: 1 })],
networks: [DEFAULT_NETWORK],
},
true,
@ -304,9 +319,9 @@ describe('compose/application-manager', () => {
downloading,
containerIdsByAppId,
} = createCurrentState({
services: [await createService({}, { appId: 1, imageId: 1 })],
services: [await createService({ appId: 1 })],
networks: [DEFAULT_NETWORK],
downloading: [2],
downloading: ['image-new'],
});
const [noopStep, ...nextSteps] = await applicationManager.inferNextSteps(
@ -330,10 +345,12 @@ describe('compose/application-manager', () => {
const targetApps = createApps(
{
services: [
await createService(
{ image: 'image-new', labels },
{ appId: 1, imageId: 2 },
),
await createService({
image: 'image-new',
labels,
appId: 1,
commit: 'new-release',
}),
],
networks: [DEFAULT_NETWORK],
},
@ -346,10 +363,12 @@ describe('compose/application-manager', () => {
containerIdsByAppId,
} = createCurrentState({
services: [
await createService(
{ image: 'image-old', labels },
{ appId: 1, imageId: 1 },
),
await createService({
image: 'image-old',
labels,
appId: 1,
commit: 'old-release',
}),
],
networks: [DEFAULT_NETWORK],
});
@ -374,26 +393,19 @@ describe('compose/application-manager', () => {
const targetApps = createApps(
{
services: [
await createService(
{ image: 'main-image', dependsOn: ['dep'] },
{
appId: 1,
imageId: 3,
serviceId: 1,
serviceName: 'main',
releaseId: 2,
},
),
await createService(
{ image: 'dep-image' },
{
appId: 1,
imageId: 4,
serviceId: 2,
serviceName: 'dep',
releaseId: 2,
},
),
await createService({
image: 'main-image',
dependsOn: ['dep'],
appId: 1,
commit: 'new-release',
serviceName: 'main',
}),
await createService({
image: 'dep-image',
appId: 1,
commit: 'new-release',
serviceName: 'dep',
}),
],
networks: [DEFAULT_NETWORK],
},
@ -406,28 +418,27 @@ describe('compose/application-manager', () => {
containerIdsByAppId,
} = createCurrentState({
services: [
await createService(
{ dependsOn: ['dep'] },
{ appId: 1, imageId: 1, serviceId: 1, serviceName: 'main' },
),
await createService(
{},
{ appId: 1, imageId: 2, serviceId: 2, serviceName: 'dep' },
),
await createService({
dependsOn: ['dep'],
appId: 1,
commit: 'old-release',
serviceName: 'main',
}),
await createService({
appId: 1,
commit: 'old-release',
serviceName: 'dep',
}),
],
networks: [DEFAULT_NETWORK],
downloading: [4], // dep-image is still being downloaded
downloading: ['dep-image'], // dep-image is still being downloaded
images: [
// main-image was already downloaded
{
createImage({
appId: 1,
releaseId: 2,
name: 'main-image',
imageId: 3,
serviceName: 'main',
serviceId: 1,
dependent: 0,
},
}),
],
});
@ -449,26 +460,19 @@ describe('compose/application-manager', () => {
const targetApps = createApps(
{
services: [
await createService(
{ image: 'main-image', dependsOn: ['dep'] },
{
appId: 1,
imageId: 3,
serviceId: 1,
serviceName: 'main',
releaseId: 2,
},
),
await createService(
{ image: 'dep-image' },
{
appId: 1,
imageId: 4,
serviceId: 2,
serviceName: 'dep',
releaseId: 2,
},
),
await createService({
image: 'main-image',
dependsOn: ['dep'],
appId: 1,
commit: 'new-release',
serviceName: 'main',
}),
await createService({
image: 'dep-image',
appId: 1,
commit: 'new-release',
serviceName: 'dep',
}),
],
networks: [DEFAULT_NETWORK],
},
@ -482,36 +486,31 @@ describe('compose/application-manager', () => {
containerIdsByAppId,
} = createCurrentState({
services: [
await createService(
{ dependsOn: ['dep'] },
{ appId: 1, imageId: 1, serviceId: 1, serviceName: 'main' },
),
await createService(
{},
{ appId: 1, imageId: 2, serviceId: 2, serviceName: 'dep' },
),
await createService({
dependsOn: ['dep'],
appId: 1,
commit: 'old-release',
serviceName: 'main',
}),
await createService({
appId: 1,
commit: 'old-release',
serviceName: 'dep',
}),
],
networks: [DEFAULT_NETWORK],
images: [
// Both images have been downloaded
{
createImage({
appId: 1,
releaseId: 2,
name: 'main-image',
imageId: 3,
serviceName: 'main',
serviceId: 1,
dependent: 0,
},
{
}),
createImage({
appId: 1,
releaseId: 2,
name: 'dep-image',
imageId: 4,
serviceName: 'dep',
serviceId: 2,
dependent: 0,
},
}),
],
});
@ -542,22 +541,17 @@ describe('compose/application-manager', () => {
const targetApps = createApps(
{
services: [
await createService(
{ image: 'main-image', dependsOn: ['dep'] },
{
imageId: 1,
serviceId: 1,
serviceName: 'main',
},
),
await createService(
{ image: 'dep-image' },
{
imageId: 2,
serviceId: 2,
serviceName: 'dep',
},
),
await createService({
image: 'main-image',
dependsOn: ['dep'],
serviceName: 'main',
commit: 'new-release',
}),
await createService({
image: 'dep-image',
serviceName: 'dep',
commit: 'new-release',
}),
],
networks: [DEFAULT_NETWORK],
},
@ -574,24 +568,16 @@ describe('compose/application-manager', () => {
networks: [DEFAULT_NETWORK],
images: [
// Both images have been downloaded
{
createImage({
appId: 1,
releaseId: 1,
name: 'main-image',
imageId: 1,
serviceName: 'main',
serviceId: 1,
dependent: 0,
},
{
}),
createImage({
appId: 1,
releaseId: 1,
name: 'dep-image',
imageId: 2,
serviceName: 'dep',
serviceId: 2,
dependent: 0,
},
}),
],
});
@ -619,22 +605,17 @@ describe('compose/application-manager', () => {
const targetApps = createApps(
{
services: [
await createService(
{ image: 'main-image', dependsOn: ['dep'] },
{
imageId: 1,
serviceId: 1,
serviceName: 'main',
},
),
await createService(
{ image: 'dep-image' },
{
imageId: 2,
serviceId: 2,
serviceName: 'dep',
},
),
await createService({
image: 'main-image',
dependsOn: ['dep'],
serviceName: 'main',
commit: 'new-release',
}),
await createService({
image: 'dep-image',
serviceName: 'dep',
commit: 'new-release',
}),
],
networks: [DEFAULT_NETWORK],
},
@ -648,36 +629,25 @@ describe('compose/application-manager', () => {
containerIdsByAppId,
} = createCurrentState({
services: [
await createService(
{ image: 'dep-image' },
{
imageId: 2,
serviceId: 2,
serviceName: 'dep',
},
),
await createService({
image: 'dep-image',
serviceName: 'dep',
commit: 'new-release',
}),
],
networks: [DEFAULT_NETWORK],
images: [
// Both images have been downloaded
{
createImage({
appId: 1,
releaseId: 1,
name: 'main-image',
imageId: 1,
serviceName: 'main',
serviceId: 1,
dependent: 0,
},
{
}),
createImage({
appId: 1,
releaseId: 1,
name: 'dep-image',
imageId: 2,
serviceName: 'dep',
serviceId: 2,
dependent: 0,
},
}),
],
});
@ -714,27 +684,15 @@ describe('compose/application-manager', () => {
downloading,
containerIdsByAppId,
} = createCurrentState({
services: [
await createService(
{},
{
appId: 5,
serviceName: 'old-service',
},
),
],
services: [await createService({ appId: 5, serviceName: 'old-service' })],
networks: [DEFAULT_NETWORK],
images: [
// Both images have been downloaded
{
// Image has been downloaded
createImage({
appId: 1,
releaseId: 1,
name: 'main-image',
imageId: 1,
serviceName: 'main',
serviceId: 1,
dependent: 0,
},
}),
],
});
@ -822,7 +780,7 @@ describe('compose/application-manager', () => {
(networkManager.supervisorNetworkReady as sinon.SinonStub).resolves(false);
const targetApps = createApps(
{ services: [await createService({})], networks: [DEFAULT_NETWORK] },
{ services: [await createService()], networks: [DEFAULT_NETWORK] },
true,
);
const {
@ -955,26 +913,18 @@ describe('compose/application-manager', () => {
networks: [DEFAULT_NETWORK],
images: [
// An image for a service that no longer exists
{
createImage({
name: 'old-image',
appId: 5,
serviceId: 5,
serviceName: 'old-service',
imageId: 5,
dependent: 0,
releaseId: 5,
dockerImageId: 'sha256:aaaa',
},
{
}),
createImage({
name: 'main-image',
appId: 1,
serviceId: 1,
serviceName: 'main',
imageId: 1,
dependent: 0,
releaseId: 1,
dockerImageId: 'sha256:bbbb',
},
}),
],
});
@ -1021,26 +971,18 @@ describe('compose/application-manager', () => {
networks: [DEFAULT_NETWORK],
images: [
// An image for a service that no longer exists
{
createImage({
name: 'old-image',
appId: 5,
serviceId: 5,
serviceName: 'old-service',
imageId: 5,
dependent: 0,
releaseId: 5,
dockerImageId: 'sha256:aaaa',
},
{
}),
createImage({
name: 'main-image',
appId: 1,
serviceId: 1,
serviceName: 'main',
imageId: 1,
dependent: 0,
releaseId: 1,
dockerImageId: 'sha256:bbbb',
},
}),
],
});
@ -1109,14 +1051,18 @@ describe('compose/application-manager', () => {
const targetApps = createApps(
{
services: [
await createService(
{ running: true, image: 'main-image-1' },
{ appId: 1, serviceId: 1, imageId: 1 },
),
await createService(
{ running: true, image: 'main-image-2' },
{ appId: 2, serviceId: 2, imageId: 2 },
),
await createService({
running: true,
image: 'main-image-1',
appId: 1,
commit: 'commit-for-app-1',
}),
await createService({
running: true,
image: 'main-image-2',
appId: 2,
commit: 'commit-for-app-2',
}),
],
networks: [
// Default networks for two apps
@ -1139,24 +1085,16 @@ describe('compose/application-manager', () => {
Network.fromComposeObject('default', 2, {}),
],
images: [
{
createImage({
name: 'main-image-1',
appId: 1,
serviceId: 1,
serviceName: 'main',
imageId: 1,
dependent: 0,
releaseId: 1,
},
{
}),
createImage({
name: 'main-image-2',
appId: 2,
serviceId: 2,
serviceName: 'main',
imageId: 2,
dependent: 0,
releaseId: 1,
},
}),
],
});