-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(odbc): Add remote agent option in ODBC south connector and repla…
…ce params by connection string
- Loading branch information
1 parent
937d9fc
commit 5a8f151
Showing
11 changed files
with
839 additions
and
266 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,24 +103,7 @@ const items: Array<SouthConnectorItemDTO<SouthMSSQLItemSettings>> = [ | |
connectorId: 'southId', | ||
settings: { | ||
query: 'SELECT * FROM table', | ||
dateTimeFields: [ | ||
{ | ||
fieldName: 'anotherTimestamp', | ||
useAsReference: false, | ||
type: 'unix-epoch-ms', | ||
timezone: null, | ||
format: null, | ||
locale: null | ||
} as unknown as SouthMSSQLItemSettingsDateTimeFields, | ||
{ | ||
fieldName: 'timestamp', | ||
useAsReference: true, | ||
type: 'string', | ||
timezone: 'Europe/Paris', | ||
format: 'yyyy-MM-dd HH:mm:ss.SSS', | ||
locale: 'en-US' | ||
} | ||
], | ||
dateTimeFields: [], | ||
serialization: { | ||
type: 'csv', | ||
filename: '[email protected]', | ||
|
@@ -199,7 +182,7 @@ describe('SouthMSSQL with authentication', () => { | |
username: 'username', | ||
password: 'password', | ||
domain: 'domain', | ||
encryption: true, | ||
encryption: null, | ||
connectionTimeout: 1000, | ||
requestTimeout: 1000, | ||
trustServerCertificate: true | ||
|
@@ -286,7 +269,6 @@ describe('SouthMSSQL with authentication', () => { | |
connectionTimeout: configuration.settings.connectionTimeout, | ||
requestTimeout: configuration.settings.requestTimeout, | ||
options: { | ||
encrypt: configuration.settings.encryption, | ||
trustServerCertificate: configuration.settings.trustServerCertificate, | ||
useUTC: true | ||
}, | ||
|
@@ -320,7 +302,7 @@ describe('SouthMSSQL without authentication', () => { | |
username: null, | ||
password: null, | ||
domain: '', | ||
encryption: false, | ||
encryption: true, | ||
connectionTimeout: 1000, | ||
requestTimeout: 1000, | ||
trustServerCertificate: false | ||
|
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
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,100 @@ | ||
import SouthODBC from './south-odbc'; | ||
import DatabaseMock from '../../tests/__mocks__/database.mock'; | ||
import pino from 'pino'; | ||
// eslint-disable-next-line import/no-unresolved | ||
import PinoLogger from '../../tests/__mocks__/logger.mock'; | ||
import EncryptionService from '../../service/encryption.service'; | ||
import EncryptionServiceMock from '../../tests/__mocks__/encryption-service.mock'; | ||
import RepositoryService from '../../service/repository.service'; | ||
import RepositoryServiceMock from '../../tests/__mocks__/repository-service.mock'; | ||
import { SouthConnectorDTO, SouthConnectorItemDTO } from '../../../../shared/model/south-connector.model'; | ||
import { SouthODBCItemSettings, SouthODBCSettings } from '../../../../shared/model/south-settings.model'; | ||
|
||
jest.mock('../../service/utils'); | ||
jest.mock('odbc', () => { | ||
throw new Error('bad'); | ||
}); | ||
jest.mock('node:fs/promises'); | ||
|
||
const database = new DatabaseMock(); | ||
jest.mock( | ||
'../../service/south-cache.service', | ||
() => | ||
function () { | ||
return { | ||
createSouthCacheScanModeTable: jest.fn(), | ||
southCacheRepository: { | ||
database | ||
} | ||
}; | ||
} | ||
); | ||
|
||
jest.mock( | ||
'../../service/south-connector-metrics.service', | ||
() => | ||
function () { | ||
return { | ||
initMetrics: jest.fn(), | ||
updateMetrics: jest.fn(), | ||
get stream() { | ||
return { stream: 'myStream' }; | ||
}, | ||
metrics: { | ||
numberOfValuesRetrieved: 1, | ||
numberOfFilesRetrieved: 1 | ||
} | ||
}; | ||
} | ||
); | ||
const addValues = jest.fn(); | ||
const addFile = jest.fn(); | ||
|
||
const logger: pino.Logger = new PinoLogger(); | ||
const encryptionService: EncryptionService = new EncryptionServiceMock('', ''); | ||
const repositoryService: RepositoryService = new RepositoryServiceMock(); | ||
const items: Array<SouthConnectorItemDTO<SouthODBCItemSettings>> = []; | ||
|
||
let south: SouthODBC; | ||
|
||
// Spy on console info and error | ||
jest.spyOn(global.console, 'info').mockImplementation(() => {}); | ||
jest.spyOn(global.console, 'error').mockImplementation(() => {}); | ||
|
||
describe('SouthODBC without ODBC Library', () => { | ||
const configuration: SouthConnectorDTO<SouthODBCSettings> = { | ||
id: 'southId', | ||
name: 'south', | ||
type: 'odbc', | ||
description: 'my test connector', | ||
enabled: true, | ||
history: { | ||
maxInstantPerItem: true, | ||
maxReadInterval: 3600, | ||
readDelay: 0 | ||
}, | ||
settings: { | ||
remoteAgent: false, | ||
connectionString: 'Driver={SQL Server};SERVER=127.0.0.1;TrustServerCertificate=yes', | ||
password: 'password', | ||
connectionTimeout: 1000, | ||
requestTimeout: 1000 | ||
} | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
|
||
south = new SouthODBC(configuration, items, addValues, addFile, encryptionService, repositoryService, logger, 'baseFolder'); | ||
}); | ||
|
||
it('should throw error if library not loaded', async () => { | ||
await expect(south.testOdbcConnection()).rejects.toThrow(new Error('odbc library not loaded')); | ||
|
||
const startTime = '2020-01-01T00:00:00.000Z'; | ||
const endTime = '2022-01-01T00:00:00.000Z'; | ||
await expect(south.queryOdbcData({} as SouthConnectorItemDTO, startTime, endTime)).rejects.toThrow( | ||
new Error('odbc library not loaded') | ||
); | ||
}); | ||
}); |
Oops, something went wrong.