mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-06-13 04:48:15 +00:00
device-state: Convert to a singleton
Change-type: patch Signed-off-by: Rich Bayliss <rich@balena.io> Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
@ -10,8 +10,8 @@ import * as config from '../../src/config';
|
||||
import * as db from '../../src/db';
|
||||
import { createV1Api } from '../../src/device-api/v1';
|
||||
import { createV2Api } from '../../src/device-api/v2';
|
||||
import * as APIBinder from '../../src/api-binder';
|
||||
import DeviceState from '../../src/device-state';
|
||||
import * as apiBinder from '../../src/api-binder';
|
||||
import * as deviceState from '../../src/device-state';
|
||||
import SupervisorAPI from '../../src/supervisor-api';
|
||||
|
||||
const DB_PATH = './test/data/supervisor-api.sqlite';
|
||||
@ -67,14 +67,12 @@ const STUBBED_VALUES = {
|
||||
|
||||
async function create(): Promise<SupervisorAPI> {
|
||||
// Get SupervisorAPI construct options
|
||||
const { deviceState, apiBinder } = await createAPIOpts();
|
||||
await createAPIOpts();
|
||||
|
||||
// Stub functions
|
||||
setupStubs();
|
||||
// Create ApplicationManager
|
||||
const appManager = new ApplicationManager({
|
||||
deviceState,
|
||||
apiBinder: null,
|
||||
});
|
||||
const appManager = new ApplicationManager();
|
||||
// Create SupervisorAPI
|
||||
const api = new SupervisorAPI({
|
||||
routers: [deviceState.router, buildRoutes(appManager)],
|
||||
@ -101,19 +99,12 @@ async function cleanUp(): Promise<void> {
|
||||
return restoreStubs();
|
||||
}
|
||||
|
||||
async function createAPIOpts(): Promise<SupervisorAPIOpts> {
|
||||
async function createAPIOpts(): Promise<void> {
|
||||
await db.initialized;
|
||||
await deviceState.initialized;
|
||||
|
||||
// Initialize and set values for mocked Config
|
||||
await initConfig();
|
||||
// Create deviceState
|
||||
const deviceState = new DeviceState({
|
||||
apiBinder: null as any,
|
||||
});
|
||||
const apiBinder = APIBinder;
|
||||
return {
|
||||
deviceState,
|
||||
apiBinder,
|
||||
};
|
||||
}
|
||||
|
||||
async function initConfig(): Promise<void> {
|
||||
@ -168,9 +159,4 @@ function restoreStubs() {
|
||||
serviceManager.getAllByAppId = originalSvcGetAppId;
|
||||
}
|
||||
|
||||
interface SupervisorAPIOpts {
|
||||
deviceState: DeviceState;
|
||||
apiBinder: typeof APIBinder;
|
||||
}
|
||||
|
||||
export = { create, cleanUp, STUBBED_VALUES };
|
||||
|
Reference in New Issue
Block a user