-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OGUI-1550] Fix issues with status service when missing components (#…
…2580) * renames StatusService to StatusController as it deals with HTTP requests * moves StatusController to controller folder * Improves StatusController by: * using naming conventions for private variables * initializing logger in constructor rather than on module import * Fixes bug in which if mysql configuration was missing, live mode would not work on front-end due to incorrect response on status
- Loading branch information
Showing
4 changed files
with
232 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
184 changes: 184 additions & 0 deletions
184
InfoLogger/test/lib/controller/mocha-status-controller.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
/** | ||
* @license | ||
* Copyright 2019-2020 CERN and copyright holders of ALICE O2. | ||
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders. | ||
* All rights not expressly granted are reserved. | ||
* | ||
* This software is distributed under the terms of the GNU General Public | ||
* License v3 (GPL Version 3), copied verbatim in the file "COPYING". | ||
* | ||
* In applying this license CERN does not waive the privileges and immunities | ||
* granted to it by virtue of its status as an Intergovernmental Organization | ||
* or submit itself to any jurisdiction. | ||
*/ | ||
|
||
const sinon = require('sinon'); | ||
const assert = require('assert'); | ||
const config = require('./../../test-config.js'); | ||
|
||
const { StatusController } = require('./../../../lib/controller/StatusController.js'); | ||
|
||
describe('Status Service test suite', () => { | ||
config.mysql = { | ||
host: 'localhost', | ||
port: 6103, | ||
database: 'INFOLOGGER', | ||
}; | ||
describe('Creating a new StatusController instance', () => { | ||
it('should successfully initialize StatusController', () => { | ||
assert.doesNotThrow(() => new StatusController({ hostname: 'localhost', port: 8080 }, {})); | ||
}); | ||
}); | ||
|
||
describe('`_getProjectInfo()` tests', () => { | ||
it('should successfully return ilg info even if version is missing', () => { | ||
const statusController = new StatusController(config, undefined); | ||
const info = { | ||
hostname: 'localhost', | ||
port: 8080, | ||
status: { ok: true }, | ||
name: 'TST', | ||
clients: -1, | ||
version: 'unknown', | ||
}; | ||
assert.deepStrictEqual(statusController._getProjectInfo(), info); | ||
}); | ||
|
||
it('should successfully return ilg version even if http configuration is missing', () => { | ||
const statusController = new StatusController({}, { version: '1.9.2' }); | ||
const info = { version: '1.9.2', clients: -1 }; | ||
assert.deepStrictEqual(statusController._getProjectInfo(), info); | ||
}); | ||
|
||
it('should successfully add project version if package.json was provided', () => { | ||
const statusController = new StatusController(config, { version: '1.9.2' }); | ||
const info = { | ||
hostname: 'localhost', port: 8080, status: { ok: true }, version: '1.9.2', name: 'TST', clients: -1, | ||
}; | ||
assert.deepStrictEqual(statusController._getProjectInfo(), info); | ||
}); | ||
}); | ||
|
||
describe('`_getLiveSourceStatus()` tests', () => { | ||
it('should successfully return InfoLogger Server info with status ok false if live source is missing', () => { | ||
const statusController = new StatusController(config, undefined); | ||
const info = { | ||
host: 'localhost', port: 6102, status: { ok: false, message: 'Unable to connect to InfoLogger Server' }, | ||
}; | ||
assert.deepStrictEqual(statusController._getLiveSourceStatus(config.infoLoggerServer), info); | ||
}); | ||
|
||
it('should successfully return InfoLogger Server info with status ok when live source is present', () => { | ||
const statusController = new StatusController(config, undefined); | ||
statusController.liveSource = { isAvailable: true, onconnect: () => true }; | ||
|
||
const info = { host: 'localhost', port: 6102, status: { ok: true } }; | ||
assert.deepStrictEqual(statusController._getLiveSourceStatus(config.infoLoggerServer), info); | ||
}); | ||
}); | ||
|
||
describe('`_getDataSourceStatus()` tests', () => { | ||
it('should successfully return mysql info with status ok false if data source is missing', async () => { | ||
const statusController = new StatusController(config, undefined); | ||
const info = { | ||
host: 'localhost', | ||
port: 6103, | ||
database: 'INFOLOGGER', | ||
status: { | ||
ok: false, message: 'There was no data source set up', | ||
}, | ||
}; | ||
const mysql = await statusController._getDataSourceStatus(config.mysql); | ||
assert.deepStrictEqual(mysql, info); | ||
}); | ||
|
||
it( | ||
'should successfully return mysql info with status ok true when data source is present and connected', | ||
async () => { | ||
const statusController = new StatusController(config, undefined); | ||
const info = { host: 'localhost', port: 6103, database: 'INFOLOGGER', status: { ok: true } }; | ||
|
||
const dataSource = { | ||
isConnectionUpAndRunning: sinon.stub().resolves(), | ||
}; | ||
statusController.querySource = dataSource; | ||
const mysql = await statusController._getDataSourceStatus(config.mysql); | ||
assert.deepStrictEqual(mysql, info); | ||
}, | ||
); | ||
|
||
it( | ||
'should successfully return mysql info with status ok false when data source is present but it is not connected', | ||
async () => { | ||
const statusController = new StatusController(config, undefined); | ||
const info = { | ||
host: 'localhost', | ||
port: 6103, | ||
database: 'INFOLOGGER', | ||
status: { | ||
ok: false, message: 'Could not connect', | ||
}, | ||
}; | ||
|
||
const dataSource = { | ||
isConnectionUpAndRunning: sinon.stub().rejects(new Error('Could not connect')), | ||
}; | ||
statusController.querySource = dataSource; | ||
const mysql = await statusController._getDataSourceStatus(config.mysql); | ||
assert.deepStrictEqual(mysql, info); | ||
}, | ||
); | ||
}); | ||
|
||
describe('`frameworkInfo()` tests', () => { | ||
it('should successfully send response with built JSON information', async () => { | ||
const statusController = new StatusController(config, undefined); | ||
const res = { | ||
status: sinon.stub().returnsThis(), | ||
json: sinon.stub(), | ||
}; | ||
await statusController.frameworkInfo(undefined, res); | ||
|
||
const info = { | ||
'infoLogger-gui': { | ||
hostname: 'localhost', | ||
port: 8080, | ||
status: { ok: true }, | ||
name: 'TST', | ||
clients: -1, | ||
version: 'unknown', | ||
}, | ||
mysql: { | ||
host: 'localhost', | ||
port: 6103, | ||
database: 'INFOLOGGER', | ||
status: { | ||
ok: false, message: 'There was no data source set up', | ||
}, | ||
}, | ||
infoLoggerServer: { | ||
host: 'localhost', port: 6102, status: { ok: false, message: 'Unable to connect to InfoLogger Server' }, | ||
}, | ||
}; | ||
|
||
assert.ok(res.status.calledWith(200)); | ||
assert.ok(res.json.calledWith(info)); | ||
}); | ||
}); | ||
|
||
describe('`getILGStatus()` tests', () => { | ||
it('should successfully send response with JSON information about ILG', async () => { | ||
const statusController = new StatusController(config, undefined); | ||
const res = { | ||
status: sinon.stub().returnsThis(), | ||
json: sinon.stub(), | ||
}; | ||
await statusController.getILGStatus(undefined, res); | ||
|
||
const info = { status: { ok: true }, clients: -1, version: 'unknown' }; | ||
|
||
assert.ok(res.status.calledWith(200)); | ||
assert.ok(res.json.calledWith(info)); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.