2020-05-11 01:03:16 +00:00
|
|
|
import { SinonStub, stub } from 'sinon';
|
2021-04-26 19:54:04 +00:00
|
|
|
import { expect } from 'chai';
|
2020-07-21 15:25:47 +00:00
|
|
|
import * as _ from 'lodash';
|
2020-05-11 01:03:16 +00:00
|
|
|
|
2022-08-17 23:35:08 +00:00
|
|
|
import * as apiBinder from '~/src/api-binder';
|
|
|
|
import * as applicationManager from '~/src/compose/application-manager';
|
|
|
|
import * as deviceState from '~/src/device-state';
|
|
|
|
import * as constants from '~/src/lib/constants';
|
|
|
|
import { docker } from '~/lib/docker-utils';
|
|
|
|
import { Supervisor } from '~/src/supervisor';
|
2020-03-31 16:01:29 +00:00
|
|
|
|
|
|
|
describe('Startup', () => {
|
2020-05-11 01:03:16 +00:00
|
|
|
let startStub: SinonStub;
|
|
|
|
let vpnStatusPathStub: SinonStub;
|
|
|
|
let deviceStateStub: SinonStub;
|
|
|
|
let dockerStub: SinonStub;
|
|
|
|
|
2020-07-21 15:25:47 +00:00
|
|
|
before(async () => {
|
|
|
|
startStub = stub(apiBinder as any, 'start').resolves();
|
|
|
|
deviceStateStub = stub(deviceState, 'applyTarget').resolves();
|
2020-08-13 12:25:39 +00:00
|
|
|
// @ts-expect-error
|
|
|
|
applicationManager.initialized = Promise.resolve();
|
2020-05-11 01:03:16 +00:00
|
|
|
vpnStatusPathStub = stub(constants, 'vpnStatusPath').returns('');
|
2020-06-02 16:56:58 +00:00
|
|
|
dockerStub = stub(docker, 'listContainers').returns(Promise.resolve([]));
|
2020-05-11 01:03:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
after(() => {
|
|
|
|
startStub.restore();
|
|
|
|
vpnStatusPathStub.restore();
|
|
|
|
deviceStateStub.restore();
|
|
|
|
dockerStub.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should startup correctly', async () => {
|
2020-03-31 16:01:29 +00:00
|
|
|
const supervisor = new Supervisor();
|
2020-07-21 15:25:47 +00:00
|
|
|
await supervisor.init();
|
|
|
|
|
2020-03-31 16:01:29 +00:00
|
|
|
// Cast as any to access private properties
|
|
|
|
const anySupervisor = supervisor as any;
|
|
|
|
expect(anySupervisor.db).to.not.be.null;
|
|
|
|
expect(anySupervisor.config).to.not.be.null;
|
|
|
|
expect(anySupervisor.logger).to.not.be.null;
|
|
|
|
expect(anySupervisor.deviceState).to.not.be.null;
|
|
|
|
expect(anySupervisor.apiBinder).to.not.be.null;
|
|
|
|
});
|
|
|
|
});
|