2020-05-11 01:03:16 +00:00
|
|
|
import { SinonStub, stub } from 'sinon';
|
|
|
|
|
|
|
|
import APIBinder from '../src/api-binder';
|
|
|
|
import { ApplicationManager } from '../src/application-manager';
|
|
|
|
import DeviceState from '../src/device-state';
|
|
|
|
import * as constants from '../src/lib/constants';
|
2020-06-02 16:56:58 +00:00
|
|
|
import { docker } from '../src/lib/docker-utils';
|
2020-03-31 16:01:29 +00:00
|
|
|
import { Supervisor } from '../src/supervisor';
|
|
|
|
import { expect } from './lib/chai-config';
|
|
|
|
|
|
|
|
describe('Startup', () => {
|
2020-05-11 01:03:16 +00:00
|
|
|
let initClientStub: SinonStub;
|
|
|
|
let startStub: SinonStub;
|
|
|
|
let vpnStatusPathStub: SinonStub;
|
|
|
|
let appManagerStub: SinonStub;
|
|
|
|
let deviceStateStub: SinonStub;
|
|
|
|
let dockerStub: SinonStub;
|
|
|
|
|
|
|
|
before(() => {
|
|
|
|
initClientStub = stub(APIBinder.prototype as any, 'initClient').returns(
|
|
|
|
Promise.resolve(),
|
|
|
|
);
|
|
|
|
startStub = stub(APIBinder.prototype as any, 'start').returns(
|
|
|
|
Promise.resolve(),
|
|
|
|
);
|
|
|
|
appManagerStub = stub(ApplicationManager.prototype, 'init').returns(
|
|
|
|
Promise.resolve(),
|
|
|
|
);
|
|
|
|
vpnStatusPathStub = stub(constants, 'vpnStatusPath').returns('');
|
|
|
|
deviceStateStub = stub(DeviceState.prototype as any, 'applyTarget').returns(
|
|
|
|
Promise.resolve(),
|
|
|
|
);
|
2020-06-02 16:56:58 +00:00
|
|
|
dockerStub = stub(docker, 'listContainers').returns(Promise.resolve([]));
|
2020-05-11 01:03:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
after(() => {
|
|
|
|
initClientStub.restore();
|
|
|
|
startStub.restore();
|
|
|
|
appManagerStub.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-05-11 01:03:16 +00:00
|
|
|
expect(await supervisor.init()).to.not.throw;
|
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;
|
|
|
|
});
|
|
|
|
});
|