mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-19 05:37:53 +00:00
Use the state-helper functions in app module tests
This commit is contained in:
parent
f37ee1b890
commit
5a84f22736
@ -7,9 +7,10 @@ import {
|
|||||||
import { Image } from '~/src/compose/images';
|
import { Image } from '~/src/compose/images';
|
||||||
import Network from '~/src/compose/network';
|
import Network from '~/src/compose/network';
|
||||||
import Service from '~/src/compose/service';
|
import Service from '~/src/compose/service';
|
||||||
import { ServiceComposeConfig } from '~/src/compose/types/service';
|
|
||||||
import Volume from '~/src/compose/volume';
|
import Volume from '~/src/compose/volume';
|
||||||
|
|
||||||
|
import { createService, createImage } from '~/test-lib/state-helper';
|
||||||
|
|
||||||
const defaultContext = {
|
const defaultContext = {
|
||||||
keepVolumes: false,
|
keepVolumes: false,
|
||||||
availableImages: [] as Image[],
|
availableImages: [] as Image[],
|
||||||
@ -37,55 +38,6 @@ function createApp({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createService(
|
|
||||||
{
|
|
||||||
appId = 1,
|
|
||||||
appUuid = 'appuuid',
|
|
||||||
serviceName = 'test',
|
|
||||||
commit = 'test-commit',
|
|
||||||
...conf
|
|
||||||
} = {} as Partial<ServiceComposeConfig>,
|
|
||||||
{ state = {} as Partial<Service>, options = {} as any } = {},
|
|
||||||
) {
|
|
||||||
const svc = await Service.fromComposeObject(
|
|
||||||
{
|
|
||||||
appId,
|
|
||||||
appUuid,
|
|
||||||
serviceName,
|
|
||||||
commit,
|
|
||||||
running: true,
|
|
||||||
...conf,
|
|
||||||
},
|
|
||||||
options,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Add additonal configuration
|
|
||||||
for (const k of Object.keys(state)) {
|
|
||||||
(svc as any)[k] = (state as any)[k];
|
|
||||||
}
|
|
||||||
return svc;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createImage(
|
|
||||||
{
|
|
||||||
appId = 1,
|
|
||||||
appUuid = 'appuuid',
|
|
||||||
name = 'test-image',
|
|
||||||
serviceName = 'test',
|
|
||||||
commit = 'test-commit',
|
|
||||||
...extra
|
|
||||||
} = {} as Partial<Image>,
|
|
||||||
) {
|
|
||||||
return {
|
|
||||||
appId,
|
|
||||||
appUuid,
|
|
||||||
commit,
|
|
||||||
name,
|
|
||||||
serviceName,
|
|
||||||
...extra,
|
|
||||||
} as Image;
|
|
||||||
}
|
|
||||||
|
|
||||||
const expectSteps = (
|
const expectSteps = (
|
||||||
action: CompositionStepAction,
|
action: CompositionStepAction,
|
||||||
steps: CompositionStep[],
|
steps: CompositionStep[],
|
||||||
@ -234,6 +186,7 @@ describe('compose/app', () => {
|
|||||||
const current = createApp({
|
const current = createApp({
|
||||||
services: [
|
services: [
|
||||||
await createService({
|
await createService({
|
||||||
|
serviceName: 'test',
|
||||||
composition: { volumes: ['test-volume:/data'] },
|
composition: { volumes: ['test-volume:/data'] },
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@ -242,6 +195,7 @@ describe('compose/app', () => {
|
|||||||
const target = createApp({
|
const target = createApp({
|
||||||
services: [
|
services: [
|
||||||
await createService({
|
await createService({
|
||||||
|
serviceName: 'test',
|
||||||
composition: { volumes: ['test-volume:/data'] },
|
composition: { volumes: ['test-volume:/data'] },
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@ -277,6 +231,7 @@ describe('compose/app', () => {
|
|||||||
|
|
||||||
it('should not output a kill step for a service which is already stopping when changing a volume', async () => {
|
it('should not output a kill step for a service which is already stopping when changing a volume', async () => {
|
||||||
const service = await createService({
|
const service = await createService({
|
||||||
|
serviceName: 'test',
|
||||||
composition: { volumes: ['test-volume:/data'] },
|
composition: { volumes: ['test-volume:/data'] },
|
||||||
});
|
});
|
||||||
service.status = 'Stopping';
|
service.status = 'Stopping';
|
||||||
@ -516,6 +471,7 @@ describe('compose/app', () => {
|
|||||||
await createService({
|
await createService({
|
||||||
appId: 1,
|
appId: 1,
|
||||||
appUuid: 'deadbeef',
|
appUuid: 'deadbeef',
|
||||||
|
serviceName: 'test',
|
||||||
composition: { networks: ['test-network'] },
|
composition: { networks: ['test-network'] },
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@ -528,6 +484,7 @@ describe('compose/app', () => {
|
|||||||
await createService({
|
await createService({
|
||||||
appId: 1,
|
appId: 1,
|
||||||
appUuid: 'deadbeef',
|
appUuid: 'deadbeef',
|
||||||
|
serviceName: 'test',
|
||||||
composition: { networks: ['test-network'] },
|
composition: { networks: ['test-network'] },
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@ -625,6 +582,7 @@ describe('compose/app', () => {
|
|||||||
await createService({
|
await createService({
|
||||||
appId: 1,
|
appId: 1,
|
||||||
appUuid: 'deadbeef',
|
appUuid: 'deadbeef',
|
||||||
|
serviceName: 'test',
|
||||||
composition: { networks: ['test-network'] },
|
composition: { networks: ['test-network'] },
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@ -634,7 +592,9 @@ describe('compose/app', () => {
|
|||||||
});
|
});
|
||||||
const target = createApp({
|
const target = createApp({
|
||||||
appUuid: 'deadbeef',
|
appUuid: 'deadbeef',
|
||||||
services: [await createService({ appUuid: 'deadbeef' })],
|
services: [
|
||||||
|
await createService({ appUuid: 'deadbeef', serviceName: 'test' }),
|
||||||
|
],
|
||||||
networks: [],
|
networks: [],
|
||||||
isTarget: true,
|
isTarget: true,
|
||||||
});
|
});
|
||||||
@ -655,6 +615,7 @@ describe('compose/app', () => {
|
|||||||
const current = createApp({
|
const current = createApp({
|
||||||
services: [
|
services: [
|
||||||
await createService({
|
await createService({
|
||||||
|
serviceName: 'test',
|
||||||
composition: { networks: ['test-network'] },
|
composition: { networks: ['test-network'] },
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@ -663,6 +624,7 @@ describe('compose/app', () => {
|
|||||||
const target = createApp({
|
const target = createApp({
|
||||||
services: [
|
services: [
|
||||||
await createService({
|
await createService({
|
||||||
|
serviceName: 'test',
|
||||||
composition: { networks: { 'test-network': {} } },
|
composition: { networks: { 'test-network': {} } },
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@ -1450,11 +1412,12 @@ describe('compose/app', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const current = createApp({
|
const current = createApp({
|
||||||
services: [await createService({ labels })],
|
services: [await createService({ serviceName: 'test', labels })],
|
||||||
});
|
});
|
||||||
const target = createApp({
|
const target = createApp({
|
||||||
services: [
|
services: [
|
||||||
await createService({
|
await createService({
|
||||||
|
serviceName: 'test',
|
||||||
labels,
|
labels,
|
||||||
composition: {
|
composition: {
|
||||||
privileged: true,
|
privileged: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user