mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-01-18 18:56:24 +00:00
Migrate compose/app and compose/app-manager tests
compose/app is run as part of the unit test suite compose/application-manager is run as part of the integration test suite
This commit is contained in:
parent
a69fbf6eac
commit
b81294431e
@ -13,8 +13,8 @@ testfs:
|
|||||||
from: test/data/mnt/boot/config.txt
|
from: test/data/mnt/boot/config.txt
|
||||||
/mnt/boot/device-type.json:
|
/mnt/boot/device-type.json:
|
||||||
from: test/data/mnt/boot/device-type.json
|
from: test/data/mnt/boot/device-type.json
|
||||||
/mnt/root/etc/os-release:
|
/etc/os-release:
|
||||||
from: test/data/etc/os-release
|
from: test/data/etc/os-release
|
||||||
# The `keep` list defines files that already exist in the
|
# The `keep` list defines files that already exist in the
|
||||||
# filesystem and need to be backed up before setting up the test environment
|
# filesystem and need to be backed up before setting up the test environment
|
||||||
keep: []
|
keep: []
|
||||||
|
@ -11,10 +11,8 @@ import * as networkManager from '~/src/compose/network-manager';
|
|||||||
import Service from '~/src/compose/service';
|
import Service from '~/src/compose/service';
|
||||||
import { ServiceComposeConfig } from '~/src/compose/types/service';
|
import { ServiceComposeConfig } from '~/src/compose/types/service';
|
||||||
import Volume from '~/src/compose/volume';
|
import Volume from '~/src/compose/volume';
|
||||||
import log from '~/lib/supervisor-console';
|
|
||||||
import { InstancedAppState } from '~/src/types/state';
|
import { InstancedAppState } from '~/src/types/state';
|
||||||
|
import * as config from '~/src/config';
|
||||||
import * as dbHelper from '~/test-lib/db-helper';
|
|
||||||
|
|
||||||
const DEFAULT_NETWORK = Network.fromComposeObject('default', 1, 'appuuid', {});
|
const DEFAULT_NETWORK = Network.fromComposeObject('default', 1, 'appuuid', {});
|
||||||
|
|
||||||
@ -163,46 +161,46 @@ function createCurrentState({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: application manager inferNextSteps still queries some stuff from
|
||||||
|
// the engine instead of receiving that information as parameter. Refactoring
|
||||||
|
// the method to be more of a pure function would allow us to move a lot of these tests
|
||||||
|
// to unit tests, leaving the need of integration tests just for more complex stuff that
|
||||||
|
// the application-manager also does and that is not currently tested.
|
||||||
|
// TODO: also, there is some redundancy between what is tested here and what is tested in
|
||||||
|
// the app spec, remove that redundancy to simplify the tests
|
||||||
describe('compose/application-manager', () => {
|
describe('compose/application-manager', () => {
|
||||||
let testDb: dbHelper.TestDatabase;
|
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
testDb = await dbHelper.createDB();
|
|
||||||
|
|
||||||
// disable log output during testing
|
|
||||||
sinon.stub(log, 'debug');
|
|
||||||
sinon.stub(log, 'warn');
|
|
||||||
sinon.stub(log, 'info');
|
|
||||||
sinon.stub(log, 'event');
|
|
||||||
sinon.stub(log, 'success');
|
|
||||||
|
|
||||||
// Stub methods that depend on external dependencies
|
// Stub methods that depend on external dependencies
|
||||||
stub(imageManager, 'isCleanupNeeded');
|
stub(imageManager, 'isCleanupNeeded');
|
||||||
stub(networkManager, 'supervisorNetworkReady');
|
stub(networkManager, 'supervisorNetworkReady');
|
||||||
|
|
||||||
|
// Service.fromComposeObject gets api keys from the database
|
||||||
|
// which also depend on the local mode. This ensures the database
|
||||||
|
// is initialized. This can be removed when ApplicationManager and Service
|
||||||
|
// a refactored to work as pure functions
|
||||||
|
await config.initialized();
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// Do not check for cleanup images by default
|
// Do not check for cleanup images by default
|
||||||
(imageManager.isCleanupNeeded as sinon.SinonStub).resolves(false);
|
(imageManager.isCleanupNeeded as sinon.SinonStub).resolves(false);
|
||||||
// Do not check for network
|
// Do not check for network
|
||||||
|
// TODO: supervisorNetworkReady not only checks for a docker network, it also checks for the
|
||||||
|
// network interface to be created. That makes it harder to integration test with an external
|
||||||
|
// docker socket
|
||||||
(networkManager.supervisorNetworkReady as sinon.SinonStub).resolves(true);
|
(networkManager.supervisorNetworkReady as sinon.SinonStub).resolves(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
after(() => {
|
||||||
await testDb.reset();
|
// Restore stubs
|
||||||
|
(imageManager.isCleanupNeeded as sinon.SinonStub).restore();
|
||||||
|
(networkManager.supervisorNetworkReady as sinon.SinonStub).restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
after(async () => {
|
// TODO: we don't test application manager initialization as it sets up a bunch of timers
|
||||||
try {
|
// and listeners that may affect other tests. This is a bad pattern and it needs to be purged
|
||||||
await testDb.destroy();
|
// from the codebase
|
||||||
} catch {
|
it.skip('should init', async () => {
|
||||||
/* noop */
|
|
||||||
}
|
|
||||||
// Restore stubbed methods
|
|
||||||
sinon.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should init', async () => {
|
|
||||||
await applicationManager.initialized();
|
await applicationManager.initialized();
|
||||||
});
|
});
|
||||||
|
|
@ -1,5 +1,4 @@
|
|||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import * as sinon from 'sinon';
|
|
||||||
import App from '~/src/compose/app';
|
import App from '~/src/compose/app';
|
||||||
import {
|
import {
|
||||||
CompositionStep,
|
CompositionStep,
|
||||||
@ -10,7 +9,6 @@ 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 { ServiceComposeConfig } from '~/src/compose/types/service';
|
||||||
import Volume from '~/src/compose/volume';
|
import Volume from '~/src/compose/volume';
|
||||||
import log from '~/lib/supervisor-console';
|
|
||||||
|
|
||||||
const defaultContext = {
|
const defaultContext = {
|
||||||
localMode: false,
|
localMode: false,
|
||||||
@ -117,19 +115,6 @@ function expectNoStep(action: CompositionStepAction, steps: CompositionStep[]) {
|
|||||||
const defaultNetwork = Network.fromComposeObject('default', 1, 'appuuid', {});
|
const defaultNetwork = Network.fromComposeObject('default', 1, 'appuuid', {});
|
||||||
|
|
||||||
describe('compose/app', () => {
|
describe('compose/app', () => {
|
||||||
before(() => {
|
|
||||||
// disable log output during testing
|
|
||||||
sinon.stub(log, 'debug');
|
|
||||||
sinon.stub(log, 'warn');
|
|
||||||
sinon.stub(log, 'info');
|
|
||||||
sinon.stub(log, 'event');
|
|
||||||
sinon.stub(log, 'success');
|
|
||||||
});
|
|
||||||
|
|
||||||
after(() => {
|
|
||||||
// Restore stubbed methods
|
|
||||||
sinon.restore();
|
|
||||||
});
|
|
||||||
describe('volume state behavior', () => {
|
describe('volume state behavior', () => {
|
||||||
it('should correctly infer a volume create step', () => {
|
it('should correctly infer a volume create step', () => {
|
||||||
// Setup current and target apps
|
// Setup current and target apps
|
Loading…
Reference in New Issue
Block a user