@itentialopensource/adapter-winston_syslog 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +5 -0
- package/.eslintrc.js +18 -0
- package/.jshintrc +3 -0
- package/CHANGELOG.md +9 -0
- package/LICENSE +201 -0
- package/README.md +285 -0
- package/adapter.js +250 -0
- package/adapterBase.js +1782 -0
- package/entities/.generic/action.json +214 -0
- package/entities/.generic/schema.json +28 -0
- package/entities/.system/action.json +50 -0
- package/entities/.system/mockdatafiles/getToken-default.json +3 -0
- package/entities/.system/mockdatafiles/healthcheck-default.json +3 -0
- package/entities/.system/schema.json +19 -0
- package/entities/.system/schemaTokenReq.json +53 -0
- package/entities/.system/schemaTokenResp.json +53 -0
- package/error.json +190 -0
- package/package.json +87 -0
- package/pronghorn.json +93 -0
- package/propertiesDecorators.json +14 -0
- package/propertiesSchema.json +1243 -0
- package/refs?service=git-upload-pack +0 -0
- package/report/adapterInfo.json +10 -0
- package/sampleProperties.json +60 -0
- package/test/integration/adapterTestIntegration.js +329 -0
- package/test/unit/adapterBaseTestUnit.js +949 -0
- package/test/unit/adapterTestUnit.js +1207 -0
- package/utils/adapterInfo.js +206 -0
- package/utils/addAuth.js +94 -0
- package/utils/artifactize.js +146 -0
- package/utils/basicGet.js +50 -0
- package/utils/checkMigrate.js +63 -0
- package/utils/entitiesToDB.js +179 -0
- package/utils/findPath.js +74 -0
- package/utils/modify.js +154 -0
- package/utils/packModificationScript.js +35 -0
- package/utils/patches2bundledDeps.js +90 -0
- package/utils/pre-commit.sh +30 -0
- package/utils/removeHooks.js +20 -0
- package/utils/setup.js +33 -0
- package/utils/tbScript.js +184 -0
- package/utils/tbUtils.js +469 -0
- package/utils/testRunner.js +298 -0
- package/utils/troubleshootingAdapter.js +190 -0
- package/workflows/README.md +3 -0
|
@@ -0,0 +1,1207 @@
|
|
|
1
|
+
/* @copyright Itential, LLC 2019 (pre-modifications) */
|
|
2
|
+
|
|
3
|
+
// Set globals
|
|
4
|
+
/* global describe it log pronghornProps */
|
|
5
|
+
/* eslint global-require: warn */
|
|
6
|
+
/* eslint no-unused-vars: warn */
|
|
7
|
+
/* eslint import/no-dynamic-require:warn */
|
|
8
|
+
|
|
9
|
+
// include required items for testing & logging
|
|
10
|
+
const assert = require('assert');
|
|
11
|
+
const fs = require('fs-extra');
|
|
12
|
+
const mocha = require('mocha');
|
|
13
|
+
const path = require('path');
|
|
14
|
+
const util = require('util');
|
|
15
|
+
const winston = require('winston');
|
|
16
|
+
const execute = require('child_process').execSync;
|
|
17
|
+
const { expect } = require('chai');
|
|
18
|
+
const { use } = require('chai');
|
|
19
|
+
const td = require('testdouble');
|
|
20
|
+
|
|
21
|
+
const anything = td.matchers.anything();
|
|
22
|
+
let logLevel = 'none';
|
|
23
|
+
const isRapidFail = false;
|
|
24
|
+
const Ajv = require('ajv');
|
|
25
|
+
|
|
26
|
+
const ajv = new Ajv({ allErrors: true, unknownFormats: 'ignore' });
|
|
27
|
+
|
|
28
|
+
// read in the properties from the sampleProperties files
|
|
29
|
+
let adaptdir = __dirname;
|
|
30
|
+
if (adaptdir.endsWith('/test/integration')) {
|
|
31
|
+
adaptdir = adaptdir.substring(0, adaptdir.length - 17);
|
|
32
|
+
} else if (adaptdir.endsWith('/test/unit')) {
|
|
33
|
+
adaptdir = adaptdir.substring(0, adaptdir.length - 10);
|
|
34
|
+
}
|
|
35
|
+
const samProps = require(`${adaptdir}/sampleProperties.json`).properties;
|
|
36
|
+
|
|
37
|
+
// these variables can be changed to run in integrated mode so easier to set them here
|
|
38
|
+
// always check these in with bogus data!!!
|
|
39
|
+
samProps.stub = true;
|
|
40
|
+
samProps.host = 'replace.hostorip.here';
|
|
41
|
+
samProps.authentication.username = 'username';
|
|
42
|
+
samProps.authentication.password = 'password';
|
|
43
|
+
samProps.protocol = 'http';
|
|
44
|
+
samProps.port = 80;
|
|
45
|
+
samProps.ssl.enabled = false;
|
|
46
|
+
samProps.ssl.accept_invalid_cert = false;
|
|
47
|
+
samProps.request.attempt_timeout = 60000;
|
|
48
|
+
const attemptTimeout = samProps.request.attempt_timeout;
|
|
49
|
+
const { stub } = samProps;
|
|
50
|
+
samProps.authentication.tenantId = '';
|
|
51
|
+
|
|
52
|
+
// these are the adapter properties. You generally should not need to alter
|
|
53
|
+
// any of these after they are initially set up
|
|
54
|
+
global.pronghornProps = {
|
|
55
|
+
pathProps: {
|
|
56
|
+
encrypted: false
|
|
57
|
+
},
|
|
58
|
+
adapterProps: {
|
|
59
|
+
adapters: [{
|
|
60
|
+
id: 'Test-winston_syslog',
|
|
61
|
+
type: 'WinstonSyslog',
|
|
62
|
+
properties: samProps
|
|
63
|
+
}]
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
global.$HOME = `${__dirname}/../..`;
|
|
68
|
+
|
|
69
|
+
// set the log levels that Pronghorn uses, spam and trace are not defaulted in so without
|
|
70
|
+
// this you may error on log.trace calls.
|
|
71
|
+
const myCustomLevels = {
|
|
72
|
+
levels: {
|
|
73
|
+
spam: 6,
|
|
74
|
+
trace: 5,
|
|
75
|
+
debug: 4,
|
|
76
|
+
info: 3,
|
|
77
|
+
warn: 2,
|
|
78
|
+
error: 1,
|
|
79
|
+
none: 0
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// need to see if there is a log level passed in
|
|
84
|
+
process.argv.forEach((val) => {
|
|
85
|
+
// is there a log level defined to be passed in?
|
|
86
|
+
if (val.indexOf('--LOG') === 0) {
|
|
87
|
+
// get the desired log level
|
|
88
|
+
const inputVal = val.split('=')[1];
|
|
89
|
+
|
|
90
|
+
// validate the log level is supported, if so set it
|
|
91
|
+
if (Object.hasOwnProperty.call(myCustomLevels.levels, inputVal)) {
|
|
92
|
+
logLevel = inputVal;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// need to set global logging
|
|
98
|
+
global.log = winston.createLogger({
|
|
99
|
+
level: logLevel,
|
|
100
|
+
levels: myCustomLevels.levels,
|
|
101
|
+
transports: [
|
|
102
|
+
new winston.transports.Console()
|
|
103
|
+
]
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Runs the error asserts for the test
|
|
108
|
+
*/
|
|
109
|
+
function runErrorAsserts(data, error, code, origin, displayStr) {
|
|
110
|
+
assert.equal(null, data);
|
|
111
|
+
assert.notEqual(undefined, error);
|
|
112
|
+
assert.notEqual(null, error);
|
|
113
|
+
assert.notEqual(undefined, error.IAPerror);
|
|
114
|
+
assert.notEqual(null, error.IAPerror);
|
|
115
|
+
assert.notEqual(undefined, error.IAPerror.displayString);
|
|
116
|
+
assert.notEqual(null, error.IAPerror.displayString);
|
|
117
|
+
assert.equal(code, error.icode);
|
|
118
|
+
assert.equal(origin, error.IAPerror.origin);
|
|
119
|
+
assert.equal(displayStr, error.IAPerror.displayString);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// require the adapter that we are going to be using
|
|
123
|
+
const WinstonSyslog = require('../../adapter');
|
|
124
|
+
|
|
125
|
+
// delete the .DS_Store directory in entities -- otherwise this will cause errors
|
|
126
|
+
const dirPath = path.join(__dirname, '../../entities/.DS_Store');
|
|
127
|
+
if (fs.existsSync(dirPath)) {
|
|
128
|
+
try {
|
|
129
|
+
fs.removeSync(dirPath);
|
|
130
|
+
console.log('.DS_Store deleted');
|
|
131
|
+
} catch (e) {
|
|
132
|
+
console.log('Error when deleting .DS_Store:', e);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// begin the testing - these should be pretty well defined between the describe and the it!
|
|
137
|
+
describe('[unit] WinstonSyslog Adapter Test', () => {
|
|
138
|
+
describe('WinstonSyslog Class Tests', () => {
|
|
139
|
+
const a = new WinstonSyslog(
|
|
140
|
+
pronghornProps.adapterProps.adapters[0].id,
|
|
141
|
+
pronghornProps.adapterProps.adapters[0].properties
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
if (isRapidFail) {
|
|
145
|
+
const state = {};
|
|
146
|
+
state.passed = true;
|
|
147
|
+
|
|
148
|
+
mocha.afterEach(function x() {
|
|
149
|
+
state.passed = state.passed
|
|
150
|
+
&& (this.currentTest.state === 'passed');
|
|
151
|
+
});
|
|
152
|
+
mocha.beforeEach(function x() {
|
|
153
|
+
if (!state.passed) {
|
|
154
|
+
return this.currentTest.skip();
|
|
155
|
+
}
|
|
156
|
+
return true;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
describe('#class instance created', () => {
|
|
161
|
+
it('should be a class with properties', (done) => {
|
|
162
|
+
try {
|
|
163
|
+
assert.notEqual(null, a);
|
|
164
|
+
assert.notEqual(undefined, a);
|
|
165
|
+
const checkId = global.pronghornProps.adapterProps.adapters[0].id;
|
|
166
|
+
assert.equal(checkId, a.id);
|
|
167
|
+
assert.notEqual(null, a.allProps);
|
|
168
|
+
const check = global.pronghornProps.adapterProps.adapters[0].properties.healthcheck.type;
|
|
169
|
+
assert.equal(check, a.healthcheckType);
|
|
170
|
+
done();
|
|
171
|
+
} catch (error) {
|
|
172
|
+
log.error(`Test Failure: ${error}`);
|
|
173
|
+
done(error);
|
|
174
|
+
}
|
|
175
|
+
}).timeout(attemptTimeout);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
describe('adapterBase.js', () => {
|
|
179
|
+
it('should have an adapterBase.js', (done) => {
|
|
180
|
+
try {
|
|
181
|
+
fs.exists('adapterBase.js', (val) => {
|
|
182
|
+
assert.equal(true, val);
|
|
183
|
+
done();
|
|
184
|
+
});
|
|
185
|
+
} catch (error) {
|
|
186
|
+
log.error(`Test Failure: ${error}`);
|
|
187
|
+
done(error);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
let wffunctions = [];
|
|
193
|
+
describe('#iapGetAdapterWorkflowFunctions', () => {
|
|
194
|
+
it('should retrieve workflow functions', (done) => {
|
|
195
|
+
try {
|
|
196
|
+
wffunctions = a.iapGetAdapterWorkflowFunctions(['healthCheck']);
|
|
197
|
+
|
|
198
|
+
try {
|
|
199
|
+
assert.notEqual(0, wffunctions.length);
|
|
200
|
+
done();
|
|
201
|
+
} catch (err) {
|
|
202
|
+
log.error(`Test Failure: ${err}`);
|
|
203
|
+
done(err);
|
|
204
|
+
}
|
|
205
|
+
} catch (error) {
|
|
206
|
+
log.error(`Adapter Exception: ${error}`);
|
|
207
|
+
done(error);
|
|
208
|
+
}
|
|
209
|
+
}).timeout(attemptTimeout);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
describe('package.json', () => {
|
|
213
|
+
it('should have a package.json', (done) => {
|
|
214
|
+
try {
|
|
215
|
+
fs.exists('package.json', (val) => {
|
|
216
|
+
assert.equal(true, val);
|
|
217
|
+
done();
|
|
218
|
+
});
|
|
219
|
+
} catch (error) {
|
|
220
|
+
log.error(`Test Failure: ${error}`);
|
|
221
|
+
done(error);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
it('package.json should be validated', (done) => {
|
|
225
|
+
try {
|
|
226
|
+
const packageDotJson = require('../../package.json');
|
|
227
|
+
// Define the JSON schema for package.json
|
|
228
|
+
const packageJsonSchema = {
|
|
229
|
+
type: 'object',
|
|
230
|
+
properties: {
|
|
231
|
+
name: { type: 'string' },
|
|
232
|
+
version: { type: 'string' }
|
|
233
|
+
// May need to add more properties as needed
|
|
234
|
+
},
|
|
235
|
+
required: ['name', 'version']
|
|
236
|
+
};
|
|
237
|
+
const validate = ajv.compile(packageJsonSchema);
|
|
238
|
+
const isValid = validate(packageDotJson);
|
|
239
|
+
|
|
240
|
+
if (isValid === false) {
|
|
241
|
+
log.error('The package.json contains errors');
|
|
242
|
+
assert.equal(true, isValid);
|
|
243
|
+
} else {
|
|
244
|
+
assert.equal(true, isValid);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
done();
|
|
248
|
+
} catch (error) {
|
|
249
|
+
log.error(`Test Failure: ${error}`);
|
|
250
|
+
done(error);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
it('package.json standard fields should be customized', (done) => {
|
|
254
|
+
try {
|
|
255
|
+
const packageDotJson = require('../../package.json');
|
|
256
|
+
assert.notEqual(-1, packageDotJson.name.indexOf('winston_syslog'));
|
|
257
|
+
assert.notEqual(undefined, packageDotJson.version);
|
|
258
|
+
assert.notEqual(null, packageDotJson.version);
|
|
259
|
+
assert.notEqual('', packageDotJson.version);
|
|
260
|
+
assert.notEqual(undefined, packageDotJson.description);
|
|
261
|
+
assert.notEqual(null, packageDotJson.description);
|
|
262
|
+
assert.notEqual('', packageDotJson.description);
|
|
263
|
+
assert.equal('adapter.js', packageDotJson.main);
|
|
264
|
+
assert.notEqual(undefined, packageDotJson.wizardVersion);
|
|
265
|
+
assert.notEqual(null, packageDotJson.wizardVersion);
|
|
266
|
+
assert.notEqual('', packageDotJson.wizardVersion);
|
|
267
|
+
assert.notEqual(undefined, packageDotJson.engineVersion);
|
|
268
|
+
assert.notEqual(null, packageDotJson.engineVersion);
|
|
269
|
+
assert.notEqual('', packageDotJson.engineVersion);
|
|
270
|
+
assert.equal('udp', packageDotJson.adapterType);
|
|
271
|
+
done();
|
|
272
|
+
} catch (error) {
|
|
273
|
+
log.error(`Test Failure: ${error}`);
|
|
274
|
+
done(error);
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
it('package.json proper scripts should be provided', (done) => {
|
|
278
|
+
try {
|
|
279
|
+
const packageDotJson = require('../../package.json');
|
|
280
|
+
assert.notEqual(undefined, packageDotJson.scripts);
|
|
281
|
+
assert.notEqual(null, packageDotJson.scripts);
|
|
282
|
+
assert.notEqual('', packageDotJson.scripts);
|
|
283
|
+
assert.equal('node utils/setup.js && npm install --package-lock-only --ignore-scripts && npx npm-force-resolutions', packageDotJson.scripts.preinstall);
|
|
284
|
+
assert.equal('node --max_old_space_size=4096 ./node_modules/eslint/bin/eslint.js . --ext .json --ext .js', packageDotJson.scripts.lint);
|
|
285
|
+
assert.equal('node --max_old_space_size=4096 ./node_modules/eslint/bin/eslint.js . --ext .json --ext .js --quiet', packageDotJson.scripts['lint:errors']);
|
|
286
|
+
assert.equal('mocha test/unit/adapterBaseTestUnit.js --LOG=error', packageDotJson.scripts['test:baseunit']);
|
|
287
|
+
assert.equal('mocha test/unit/adapterTestUnit.js --LOG=error', packageDotJson.scripts['test:unit']);
|
|
288
|
+
assert.equal('mocha test/integration/adapterTestIntegration.js --LOG=error', packageDotJson.scripts['test:integration']);
|
|
289
|
+
assert.equal('nyc --reporter html --reporter text mocha --reporter dot test/*', packageDotJson.scripts['test:cover']);
|
|
290
|
+
assert.equal('npm run test:baseunit && npm run test:unit && npm run test:integration', packageDotJson.scripts.test);
|
|
291
|
+
assert.equal('npm publish --registry=https://registry.npmjs.org --access=public', packageDotJson.scripts.deploy);
|
|
292
|
+
assert.equal('npm run deploy', packageDotJson.scripts.build);
|
|
293
|
+
done();
|
|
294
|
+
} catch (error) {
|
|
295
|
+
log.error(`Test Failure: ${error}`);
|
|
296
|
+
done(error);
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
it('package.json proper directories should be provided', (done) => {
|
|
300
|
+
try {
|
|
301
|
+
const packageDotJson = require('../../package.json');
|
|
302
|
+
assert.notEqual(undefined, packageDotJson.repository);
|
|
303
|
+
assert.notEqual(null, packageDotJson.repository);
|
|
304
|
+
assert.notEqual('', packageDotJson.repository);
|
|
305
|
+
assert.equal('git', packageDotJson.repository.type);
|
|
306
|
+
assert.equal('git@gitlab.com:itentialopensource/adapters/', packageDotJson.repository.url.substring(0, 43));
|
|
307
|
+
assert.equal('https://gitlab.com/itentialopensource/adapters/', packageDotJson.homepage.substring(0, 47));
|
|
308
|
+
done();
|
|
309
|
+
} catch (error) {
|
|
310
|
+
log.error(`Test Failure: ${error}`);
|
|
311
|
+
done(error);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
it('package.json proper dependencies should be provided', (done) => {
|
|
315
|
+
try {
|
|
316
|
+
const packageDotJson = require('../../package.json');
|
|
317
|
+
assert.notEqual(undefined, packageDotJson.dependencies);
|
|
318
|
+
assert.notEqual(null, packageDotJson.dependencies);
|
|
319
|
+
assert.notEqual('', packageDotJson.dependencies);
|
|
320
|
+
assert.equal('^6.12.0', packageDotJson.dependencies.ajv);
|
|
321
|
+
assert.equal('^0.21.0', packageDotJson.dependencies.axios);
|
|
322
|
+
assert.equal('^2.20.0', packageDotJson.dependencies.commander);
|
|
323
|
+
assert.equal('^8.1.0', packageDotJson.dependencies['fs-extra']);
|
|
324
|
+
assert.equal('^9.0.1', packageDotJson.dependencies.mocha);
|
|
325
|
+
assert.equal('^2.0.1', packageDotJson.dependencies['mocha-param']);
|
|
326
|
+
assert.equal('^0.5.3', packageDotJson.dependencies['network-diagnostics']);
|
|
327
|
+
assert.equal('^15.1.0', packageDotJson.dependencies.nyc);
|
|
328
|
+
assert.equal('^1.4.10', packageDotJson.dependencies['readline-sync']);
|
|
329
|
+
assert.equal('^7.3.2', packageDotJson.dependencies.semver);
|
|
330
|
+
assert.equal('^3.8.2', packageDotJson.dependencies.winston);
|
|
331
|
+
done();
|
|
332
|
+
} catch (error) {
|
|
333
|
+
log.error(`Test Failure: ${error}`);
|
|
334
|
+
done(error);
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
it('package.json proper dev dependencies should be provided', (done) => {
|
|
338
|
+
try {
|
|
339
|
+
const packageDotJson = require('../../package.json');
|
|
340
|
+
assert.notEqual(undefined, packageDotJson.devDependencies);
|
|
341
|
+
assert.notEqual(null, packageDotJson.devDependencies);
|
|
342
|
+
assert.notEqual('', packageDotJson.devDependencies);
|
|
343
|
+
assert.equal('^4.3.4', packageDotJson.devDependencies.chai);
|
|
344
|
+
assert.equal('^7.29.0', packageDotJson.devDependencies.eslint);
|
|
345
|
+
assert.equal('^14.2.1', packageDotJson.devDependencies['eslint-config-airbnb-base']);
|
|
346
|
+
assert.equal('^2.23.4', packageDotJson.devDependencies['eslint-plugin-import']);
|
|
347
|
+
assert.equal('^3.0.0', packageDotJson.devDependencies['eslint-plugin-json']);
|
|
348
|
+
assert.equal('^3.16.1', packageDotJson.devDependencies.testdouble);
|
|
349
|
+
done();
|
|
350
|
+
} catch (error) {
|
|
351
|
+
log.error(`Test Failure: ${error}`);
|
|
352
|
+
done(error);
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
describe('pronghorn.json', () => {
|
|
358
|
+
it('should have a pronghorn.json', (done) => {
|
|
359
|
+
try {
|
|
360
|
+
fs.exists('pronghorn.json', (val) => {
|
|
361
|
+
assert.equal(true, val);
|
|
362
|
+
done();
|
|
363
|
+
});
|
|
364
|
+
} catch (error) {
|
|
365
|
+
log.error(`Test Failure: ${error}`);
|
|
366
|
+
done(error);
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
it('pronghorn.json should be customized', (done) => {
|
|
370
|
+
try {
|
|
371
|
+
const pronghornDotJson = require('../../pronghorn.json');
|
|
372
|
+
assert.notEqual(-1, pronghornDotJson.id.indexOf('winston_syslog'));
|
|
373
|
+
assert.equal('Adapter', pronghornDotJson.type);
|
|
374
|
+
assert.equal('WinstonSyslog', pronghornDotJson.export);
|
|
375
|
+
assert.equal('WinstonSyslog', pronghornDotJson.title);
|
|
376
|
+
assert.equal('adapter.js', pronghornDotJson.src);
|
|
377
|
+
done();
|
|
378
|
+
} catch (error) {
|
|
379
|
+
log.error(`Test Failure: ${error}`);
|
|
380
|
+
done(error);
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
it('pronghorn.json should only expose workflow functions', (done) => {
|
|
384
|
+
try {
|
|
385
|
+
const pronghornDotJson = require('../../pronghorn.json');
|
|
386
|
+
|
|
387
|
+
for (let m = 0; m < pronghornDotJson.methods.length; m += 1) {
|
|
388
|
+
let found = false;
|
|
389
|
+
let paramissue = false;
|
|
390
|
+
for (let w = 0; w < wffunctions.length; w += 1) {
|
|
391
|
+
if (pronghornDotJson.methods[m].name === wffunctions[w]) {
|
|
392
|
+
found = true;
|
|
393
|
+
const methLine = execute(`grep " ${wffunctions[w]}(" adapter.js | grep "callback) {"`).toString();
|
|
394
|
+
let wfparams = [];
|
|
395
|
+
|
|
396
|
+
if (methLine && methLine.indexOf('(') >= 0 && methLine.indexOf(')') >= 0) {
|
|
397
|
+
const temp = methLine.substring(methLine.indexOf('(') + 1, methLine.lastIndexOf(')'));
|
|
398
|
+
wfparams = temp.split(',');
|
|
399
|
+
|
|
400
|
+
for (let t = 0; t < wfparams.length; t += 1) {
|
|
401
|
+
// remove default value from the parameter name
|
|
402
|
+
wfparams[t] = wfparams[t].substring(0, wfparams[t].search(/=/) > 0 ? wfparams[t].search(/#|\?|=/) : wfparams[t].length);
|
|
403
|
+
// remove spaces
|
|
404
|
+
wfparams[t] = wfparams[t].trim();
|
|
405
|
+
|
|
406
|
+
if (wfparams[t] === 'callback') {
|
|
407
|
+
wfparams.splice(t, 1);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// if there are inputs defined but not on the method line
|
|
413
|
+
if (wfparams.length === 0 && (pronghornDotJson.methods[m].input
|
|
414
|
+
&& pronghornDotJson.methods[m].input.length > 0)) {
|
|
415
|
+
paramissue = true;
|
|
416
|
+
} else if (wfparams.length > 0 && (!pronghornDotJson.methods[m].input
|
|
417
|
+
|| pronghornDotJson.methods[m].input.length === 0)) {
|
|
418
|
+
// if there are no inputs defined but there are on the method line
|
|
419
|
+
paramissue = true;
|
|
420
|
+
} else {
|
|
421
|
+
for (let p = 0; p < pronghornDotJson.methods[m].input.length; p += 1) {
|
|
422
|
+
let pfound = false;
|
|
423
|
+
for (let wfp = 0; wfp < wfparams.length; wfp += 1) {
|
|
424
|
+
if (pronghornDotJson.methods[m].input[p].name.toUpperCase() === wfparams[wfp].toUpperCase()) {
|
|
425
|
+
pfound = true;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
if (!pfound) {
|
|
430
|
+
paramissue = true;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
for (let wfp = 0; wfp < wfparams.length; wfp += 1) {
|
|
434
|
+
let pfound = false;
|
|
435
|
+
for (let p = 0; p < pronghornDotJson.methods[m].input.length; p += 1) {
|
|
436
|
+
if (pronghornDotJson.methods[m].input[p].name.toUpperCase() === wfparams[wfp].toUpperCase()) {
|
|
437
|
+
pfound = true;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
if (!pfound) {
|
|
442
|
+
paramissue = true;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
break;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
if (!found) {
|
|
452
|
+
// this is the reason to go through both loops - log which ones are not found so
|
|
453
|
+
// they can be worked
|
|
454
|
+
log.error(`${pronghornDotJson.methods[m].name} not found in workflow functions`);
|
|
455
|
+
}
|
|
456
|
+
if (paramissue) {
|
|
457
|
+
// this is the reason to go through both loops - log which ones are not found so
|
|
458
|
+
// they can be worked
|
|
459
|
+
log.error(`${pronghornDotJson.methods[m].name} has a parameter mismatch`);
|
|
460
|
+
}
|
|
461
|
+
assert.equal(true, found);
|
|
462
|
+
assert.equal(false, paramissue);
|
|
463
|
+
}
|
|
464
|
+
done();
|
|
465
|
+
} catch (error) {
|
|
466
|
+
log.error(`Adapter Exception: ${error}`);
|
|
467
|
+
done(error);
|
|
468
|
+
}
|
|
469
|
+
}).timeout(attemptTimeout);
|
|
470
|
+
it('pronghorn.json should expose all workflow functions', (done) => {
|
|
471
|
+
try {
|
|
472
|
+
const pronghornDotJson = require('../../pronghorn.json');
|
|
473
|
+
for (let w = 0; w < wffunctions.length; w += 1) {
|
|
474
|
+
let found = false;
|
|
475
|
+
|
|
476
|
+
for (let m = 0; m < pronghornDotJson.methods.length; m += 1) {
|
|
477
|
+
if (pronghornDotJson.methods[m].name === wffunctions[w]) {
|
|
478
|
+
found = true;
|
|
479
|
+
break;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
if (!found) {
|
|
484
|
+
// this is the reason to go through both loops - log which ones are not found so
|
|
485
|
+
// they can be worked
|
|
486
|
+
log.error(`${wffunctions[w]} not found in pronghorn.json`);
|
|
487
|
+
}
|
|
488
|
+
assert.equal(true, found);
|
|
489
|
+
}
|
|
490
|
+
done();
|
|
491
|
+
} catch (error) {
|
|
492
|
+
log.error(`Adapter Exception: ${error}`);
|
|
493
|
+
done(error);
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
describe('propertiesSchema.json', () => {
|
|
499
|
+
it('should have a propertiesSchema.json', (done) => {
|
|
500
|
+
try {
|
|
501
|
+
fs.exists('propertiesSchema.json', (val) => {
|
|
502
|
+
assert.equal(true, val);
|
|
503
|
+
done();
|
|
504
|
+
});
|
|
505
|
+
} catch (error) {
|
|
506
|
+
log.error(`Test Failure: ${error}`);
|
|
507
|
+
done(error);
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
it('propertiesSchema.json should be customized', (done) => {
|
|
511
|
+
try {
|
|
512
|
+
const propertiesDotJson = require('../../propertiesSchema.json');
|
|
513
|
+
assert.equal('adapter-winston_syslog', propertiesDotJson.$id);
|
|
514
|
+
assert.equal('object', propertiesDotJson.type);
|
|
515
|
+
assert.equal('http://json-schema.org/draft-07/schema#', propertiesDotJson.$schema);
|
|
516
|
+
done();
|
|
517
|
+
} catch (error) {
|
|
518
|
+
log.error(`Test Failure: ${error}`);
|
|
519
|
+
done(error);
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
it('propertiesSchema.json should contain generic adapter properties', (done) => {
|
|
523
|
+
try {
|
|
524
|
+
const propertiesDotJson = require('../../propertiesSchema.json');
|
|
525
|
+
assert.notEqual(undefined, propertiesDotJson.properties);
|
|
526
|
+
assert.notEqual(null, propertiesDotJson.properties);
|
|
527
|
+
assert.notEqual('', propertiesDotJson.properties);
|
|
528
|
+
assert.equal('string', propertiesDotJson.properties.host.type);
|
|
529
|
+
assert.equal('integer', propertiesDotJson.properties.port.type);
|
|
530
|
+
assert.equal('boolean', propertiesDotJson.properties.stub.type);
|
|
531
|
+
assert.notEqual(undefined, propertiesDotJson.definitions.authentication);
|
|
532
|
+
assert.notEqual(null, propertiesDotJson.definitions.authentication);
|
|
533
|
+
assert.notEqual('', propertiesDotJson.definitions.authentication);
|
|
534
|
+
assert.equal('string', propertiesDotJson.definitions.authentication.properties.auth_method.type);
|
|
535
|
+
assert.equal('string', propertiesDotJson.definitions.authentication.properties.username.type);
|
|
536
|
+
assert.equal('string', propertiesDotJson.definitions.authentication.properties.password.type);
|
|
537
|
+
assert.equal('string', propertiesDotJson.definitions.authentication.properties.token.type);
|
|
538
|
+
assert.equal('integer', propertiesDotJson.definitions.authentication.properties.invalid_token_error.type);
|
|
539
|
+
assert.equal('integer', propertiesDotJson.definitions.authentication.properties.token_timeout.type);
|
|
540
|
+
assert.equal('string', propertiesDotJson.definitions.authentication.properties.token_cache.type);
|
|
541
|
+
assert.equal(true, Array.isArray(propertiesDotJson.definitions.authentication.properties.auth_field.type));
|
|
542
|
+
assert.equal(true, Array.isArray(propertiesDotJson.definitions.authentication.properties.auth_field_format.type));
|
|
543
|
+
assert.equal('boolean', propertiesDotJson.definitions.authentication.properties.auth_logging.type);
|
|
544
|
+
assert.equal('string', propertiesDotJson.definitions.authentication.properties.client_id.type);
|
|
545
|
+
assert.equal('string', propertiesDotJson.definitions.authentication.properties.client_secret.type);
|
|
546
|
+
assert.equal('string', propertiesDotJson.definitions.authentication.properties.grant_type.type);
|
|
547
|
+
assert.notEqual(undefined, propertiesDotJson.definitions.ssl);
|
|
548
|
+
assert.notEqual(null, propertiesDotJson.definitions.ssl);
|
|
549
|
+
assert.notEqual('', propertiesDotJson.definitions.ssl);
|
|
550
|
+
assert.equal('string', propertiesDotJson.definitions.ssl.properties.ecdhCurve.type);
|
|
551
|
+
assert.equal('boolean', propertiesDotJson.definitions.ssl.properties.enabled.type);
|
|
552
|
+
assert.equal('boolean', propertiesDotJson.definitions.ssl.properties.accept_invalid_cert.type);
|
|
553
|
+
assert.equal('string', propertiesDotJson.definitions.ssl.properties.ca_file.type);
|
|
554
|
+
assert.equal('string', propertiesDotJson.definitions.ssl.properties.key_file.type);
|
|
555
|
+
assert.equal('string', propertiesDotJson.definitions.ssl.properties.cert_file.type);
|
|
556
|
+
assert.equal('string', propertiesDotJson.definitions.ssl.properties.secure_protocol.type);
|
|
557
|
+
assert.equal('string', propertiesDotJson.definitions.ssl.properties.ciphers.type);
|
|
558
|
+
assert.equal('string', propertiesDotJson.properties.base_path.type);
|
|
559
|
+
assert.equal('string', propertiesDotJson.properties.version.type);
|
|
560
|
+
assert.equal('string', propertiesDotJson.properties.cache_location.type);
|
|
561
|
+
assert.equal('boolean', propertiesDotJson.properties.encode_pathvars.type);
|
|
562
|
+
assert.equal('boolean', propertiesDotJson.properties.encode_queryvars.type);
|
|
563
|
+
assert.equal(true, Array.isArray(propertiesDotJson.properties.save_metric.type));
|
|
564
|
+
assert.equal('string', propertiesDotJson.properties.protocol.type);
|
|
565
|
+
assert.notEqual(undefined, propertiesDotJson.definitions);
|
|
566
|
+
assert.notEqual(null, propertiesDotJson.definitions);
|
|
567
|
+
assert.notEqual('', propertiesDotJson.definitions);
|
|
568
|
+
assert.notEqual(undefined, propertiesDotJson.definitions.healthcheck);
|
|
569
|
+
assert.notEqual(null, propertiesDotJson.definitions.healthcheck);
|
|
570
|
+
assert.notEqual('', propertiesDotJson.definitions.healthcheck);
|
|
571
|
+
assert.equal('string', propertiesDotJson.definitions.healthcheck.properties.type.type);
|
|
572
|
+
assert.equal('integer', propertiesDotJson.definitions.healthcheck.properties.frequency.type);
|
|
573
|
+
assert.equal('object', propertiesDotJson.definitions.healthcheck.properties.query_object.type);
|
|
574
|
+
assert.notEqual(undefined, propertiesDotJson.definitions.throttle);
|
|
575
|
+
assert.notEqual(null, propertiesDotJson.definitions.throttle);
|
|
576
|
+
assert.notEqual('', propertiesDotJson.definitions.throttle);
|
|
577
|
+
assert.equal('boolean', propertiesDotJson.definitions.throttle.properties.throttle_enabled.type);
|
|
578
|
+
assert.equal('integer', propertiesDotJson.definitions.throttle.properties.number_pronghorns.type);
|
|
579
|
+
assert.equal('string', propertiesDotJson.definitions.throttle.properties.sync_async.type);
|
|
580
|
+
assert.equal('integer', propertiesDotJson.definitions.throttle.properties.max_in_queue.type);
|
|
581
|
+
assert.equal('integer', propertiesDotJson.definitions.throttle.properties.concurrent_max.type);
|
|
582
|
+
assert.equal('integer', propertiesDotJson.definitions.throttle.properties.expire_timeout.type);
|
|
583
|
+
assert.equal('integer', propertiesDotJson.definitions.throttle.properties.avg_runtime.type);
|
|
584
|
+
assert.equal('array', propertiesDotJson.definitions.throttle.properties.priorities.type);
|
|
585
|
+
assert.notEqual(undefined, propertiesDotJson.definitions.request);
|
|
586
|
+
assert.notEqual(null, propertiesDotJson.definitions.request);
|
|
587
|
+
assert.notEqual('', propertiesDotJson.definitions.request);
|
|
588
|
+
assert.equal('integer', propertiesDotJson.definitions.request.properties.number_redirects.type);
|
|
589
|
+
assert.equal('integer', propertiesDotJson.definitions.request.properties.number_retries.type);
|
|
590
|
+
assert.equal(true, Array.isArray(propertiesDotJson.definitions.request.properties.limit_retry_error.type));
|
|
591
|
+
assert.equal('array', propertiesDotJson.definitions.request.properties.failover_codes.type);
|
|
592
|
+
assert.equal('integer', propertiesDotJson.definitions.request.properties.attempt_timeout.type);
|
|
593
|
+
assert.equal('object', propertiesDotJson.definitions.request.properties.global_request.type);
|
|
594
|
+
assert.equal('object', propertiesDotJson.definitions.request.properties.global_request.properties.payload.type);
|
|
595
|
+
assert.equal('object', propertiesDotJson.definitions.request.properties.global_request.properties.uriOptions.type);
|
|
596
|
+
assert.equal('object', propertiesDotJson.definitions.request.properties.global_request.properties.addlHeaders.type);
|
|
597
|
+
assert.equal('object', propertiesDotJson.definitions.request.properties.global_request.properties.authData.type);
|
|
598
|
+
assert.equal('boolean', propertiesDotJson.definitions.request.properties.healthcheck_on_timeout.type);
|
|
599
|
+
assert.equal('boolean', propertiesDotJson.definitions.request.properties.return_raw.type);
|
|
600
|
+
assert.equal('boolean', propertiesDotJson.definitions.request.properties.archiving.type);
|
|
601
|
+
assert.equal('boolean', propertiesDotJson.definitions.request.properties.return_request.type);
|
|
602
|
+
assert.notEqual(undefined, propertiesDotJson.definitions.proxy);
|
|
603
|
+
assert.notEqual(null, propertiesDotJson.definitions.proxy);
|
|
604
|
+
assert.notEqual('', propertiesDotJson.definitions.proxy);
|
|
605
|
+
assert.equal('boolean', propertiesDotJson.definitions.proxy.properties.enabled.type);
|
|
606
|
+
assert.equal('string', propertiesDotJson.definitions.proxy.properties.host.type);
|
|
607
|
+
assert.equal('integer', propertiesDotJson.definitions.proxy.properties.port.type);
|
|
608
|
+
assert.equal('string', propertiesDotJson.definitions.proxy.properties.protocol.type);
|
|
609
|
+
assert.equal('string', propertiesDotJson.definitions.proxy.properties.username.type);
|
|
610
|
+
assert.equal('string', propertiesDotJson.definitions.proxy.properties.password.type);
|
|
611
|
+
assert.notEqual(undefined, propertiesDotJson.definitions.mongo);
|
|
612
|
+
assert.notEqual(null, propertiesDotJson.definitions.mongo);
|
|
613
|
+
assert.notEqual('', propertiesDotJson.definitions.mongo);
|
|
614
|
+
assert.equal('string', propertiesDotJson.definitions.mongo.properties.host.type);
|
|
615
|
+
assert.equal('integer', propertiesDotJson.definitions.mongo.properties.port.type);
|
|
616
|
+
assert.equal('string', propertiesDotJson.definitions.mongo.properties.database.type);
|
|
617
|
+
assert.equal('string', propertiesDotJson.definitions.mongo.properties.username.type);
|
|
618
|
+
assert.equal('string', propertiesDotJson.definitions.mongo.properties.password.type);
|
|
619
|
+
assert.equal('string', propertiesDotJson.definitions.mongo.properties.replSet.type);
|
|
620
|
+
assert.equal('object', propertiesDotJson.definitions.mongo.properties.db_ssl.type);
|
|
621
|
+
assert.equal('boolean', propertiesDotJson.definitions.mongo.properties.db_ssl.properties.enabled.type);
|
|
622
|
+
assert.equal('boolean', propertiesDotJson.definitions.mongo.properties.db_ssl.properties.accept_invalid_cert.type);
|
|
623
|
+
assert.equal('string', propertiesDotJson.definitions.mongo.properties.db_ssl.properties.ca_file.type);
|
|
624
|
+
assert.equal('string', propertiesDotJson.definitions.mongo.properties.db_ssl.properties.key_file.type);
|
|
625
|
+
assert.equal('string', propertiesDotJson.definitions.mongo.properties.db_ssl.properties.cert_file.type);
|
|
626
|
+
assert.notEqual('', propertiesDotJson.definitions.devicebroker);
|
|
627
|
+
assert.equal('array', propertiesDotJson.definitions.devicebroker.properties.getDevice.type);
|
|
628
|
+
assert.equal('array', propertiesDotJson.definitions.devicebroker.properties.getDevicesFiltered.type);
|
|
629
|
+
assert.equal('array', propertiesDotJson.definitions.devicebroker.properties.isAlive.type);
|
|
630
|
+
assert.equal('array', propertiesDotJson.definitions.devicebroker.properties.getConfig.type);
|
|
631
|
+
assert.equal('array', propertiesDotJson.definitions.devicebroker.properties.getCount.type);
|
|
632
|
+
done();
|
|
633
|
+
} catch (error) {
|
|
634
|
+
log.error(`Test Failure: ${error}`);
|
|
635
|
+
done(error);
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
describe('error.json', () => {
|
|
641
|
+
it('should have an error.json', (done) => {
|
|
642
|
+
try {
|
|
643
|
+
fs.exists('error.json', (val) => {
|
|
644
|
+
assert.equal(true, val);
|
|
645
|
+
done();
|
|
646
|
+
});
|
|
647
|
+
} catch (error) {
|
|
648
|
+
log.error(`Test Failure: ${error}`);
|
|
649
|
+
done(error);
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
it('error.json should have standard adapter errors', (done) => {
|
|
653
|
+
try {
|
|
654
|
+
const errorDotJson = require('../../error.json');
|
|
655
|
+
assert.notEqual(undefined, errorDotJson.errors);
|
|
656
|
+
assert.notEqual(null, errorDotJson.errors);
|
|
657
|
+
assert.notEqual('', errorDotJson.errors);
|
|
658
|
+
assert.equal(true, Array.isArray(errorDotJson.errors));
|
|
659
|
+
assert.notEqual(0, errorDotJson.errors.length);
|
|
660
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.100'));
|
|
661
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.101'));
|
|
662
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.102'));
|
|
663
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.110'));
|
|
664
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.111'));
|
|
665
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.112'));
|
|
666
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.113'));
|
|
667
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.114'));
|
|
668
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.115'));
|
|
669
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.116'));
|
|
670
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.300'));
|
|
671
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.301'));
|
|
672
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.302'));
|
|
673
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.303'));
|
|
674
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.304'));
|
|
675
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.305'));
|
|
676
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.310'));
|
|
677
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.311'));
|
|
678
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.312'));
|
|
679
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.320'));
|
|
680
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.321'));
|
|
681
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.400'));
|
|
682
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.401'));
|
|
683
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.402'));
|
|
684
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.500'));
|
|
685
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.501'));
|
|
686
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.502'));
|
|
687
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.503'));
|
|
688
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.600'));
|
|
689
|
+
assert.notEqual(undefined, errorDotJson.errors.find((e) => e.icode === 'AD.900'));
|
|
690
|
+
done();
|
|
691
|
+
} catch (error) {
|
|
692
|
+
log.error(`Test Failure: ${error}`);
|
|
693
|
+
done(error);
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
describe('sampleProperties.json', () => {
|
|
699
|
+
it('should have a sampleProperties.json', (done) => {
|
|
700
|
+
try {
|
|
701
|
+
fs.exists('sampleProperties.json', (val) => {
|
|
702
|
+
assert.equal(true, val);
|
|
703
|
+
done();
|
|
704
|
+
});
|
|
705
|
+
} catch (error) {
|
|
706
|
+
log.error(`Test Failure: ${error}`);
|
|
707
|
+
done(error);
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
});
|
|
711
|
+
|
|
712
|
+
describe('#checkProperties', () => {
|
|
713
|
+
it('should have a checkProperties function', (done) => {
|
|
714
|
+
try {
|
|
715
|
+
assert.equal(true, typeof a.checkProperties === 'function');
|
|
716
|
+
done();
|
|
717
|
+
} catch (error) {
|
|
718
|
+
log.error(`Test Failure: ${error}`);
|
|
719
|
+
done(error);
|
|
720
|
+
}
|
|
721
|
+
});
|
|
722
|
+
it('the sample properties should be good - if failure change the log level', (done) => {
|
|
723
|
+
try {
|
|
724
|
+
const samplePropsJson = require('../../sampleProperties.json');
|
|
725
|
+
const clean = a.checkProperties(samplePropsJson.properties);
|
|
726
|
+
|
|
727
|
+
try {
|
|
728
|
+
assert.notEqual(0, Object.keys(clean));
|
|
729
|
+
assert.equal(undefined, clean.exception);
|
|
730
|
+
assert.notEqual(undefined, clean.host);
|
|
731
|
+
assert.notEqual(null, clean.host);
|
|
732
|
+
assert.notEqual('', clean.host);
|
|
733
|
+
done();
|
|
734
|
+
} catch (err) {
|
|
735
|
+
log.error(`Test Failure: ${err}`);
|
|
736
|
+
done(err);
|
|
737
|
+
}
|
|
738
|
+
} catch (error) {
|
|
739
|
+
log.error(`Adapter Exception: ${error}`);
|
|
740
|
+
done(error);
|
|
741
|
+
}
|
|
742
|
+
}).timeout(attemptTimeout);
|
|
743
|
+
});
|
|
744
|
+
|
|
745
|
+
describe('README.md', () => {
|
|
746
|
+
it('should have a README', (done) => {
|
|
747
|
+
try {
|
|
748
|
+
fs.exists('README.md', (val) => {
|
|
749
|
+
assert.equal(true, val);
|
|
750
|
+
done();
|
|
751
|
+
});
|
|
752
|
+
} catch (error) {
|
|
753
|
+
log.error(`Test Failure: ${error}`);
|
|
754
|
+
done(error);
|
|
755
|
+
}
|
|
756
|
+
});
|
|
757
|
+
it('README.md should be customized', (done) => {
|
|
758
|
+
try {
|
|
759
|
+
fs.readFile('README.md', 'utf8', (err, data) => {
|
|
760
|
+
assert.equal(-1, data.indexOf('[System]'));
|
|
761
|
+
assert.equal(-1, data.indexOf('[system]'));
|
|
762
|
+
assert.equal(-1, data.indexOf('[version]'));
|
|
763
|
+
assert.equal(-1, data.indexOf('[namespace]'));
|
|
764
|
+
done();
|
|
765
|
+
});
|
|
766
|
+
} catch (error) {
|
|
767
|
+
log.error(`Test Failure: ${error}`);
|
|
768
|
+
done(error);
|
|
769
|
+
}
|
|
770
|
+
});
|
|
771
|
+
});
|
|
772
|
+
|
|
773
|
+
describe('#connect', () => {
|
|
774
|
+
it('should have a connect function', (done) => {
|
|
775
|
+
try {
|
|
776
|
+
assert.equal(true, typeof a.connect === 'function');
|
|
777
|
+
done();
|
|
778
|
+
} catch (error) {
|
|
779
|
+
log.error(`Test Failure: ${error}`);
|
|
780
|
+
done(error);
|
|
781
|
+
}
|
|
782
|
+
});
|
|
783
|
+
});
|
|
784
|
+
|
|
785
|
+
describe('#healthCheck', () => {
|
|
786
|
+
it('should have a healthCheck function', (done) => {
|
|
787
|
+
try {
|
|
788
|
+
assert.equal(true, typeof a.healthCheck === 'function');
|
|
789
|
+
done();
|
|
790
|
+
} catch (error) {
|
|
791
|
+
log.error(`Test Failure: ${error}`);
|
|
792
|
+
done(error);
|
|
793
|
+
}
|
|
794
|
+
});
|
|
795
|
+
});
|
|
796
|
+
|
|
797
|
+
describe('#iapUpdateAdapterConfiguration', () => {
|
|
798
|
+
it('should have a iapUpdateAdapterConfiguration function', (done) => {
|
|
799
|
+
try {
|
|
800
|
+
assert.equal(true, typeof a.iapUpdateAdapterConfiguration === 'function');
|
|
801
|
+
done();
|
|
802
|
+
} catch (error) {
|
|
803
|
+
log.error(`Test Failure: ${error}`);
|
|
804
|
+
done(error);
|
|
805
|
+
}
|
|
806
|
+
});
|
|
807
|
+
});
|
|
808
|
+
|
|
809
|
+
describe('#iapFindAdapterPath', () => {
|
|
810
|
+
it('should have a iapFindAdapterPath function', (done) => {
|
|
811
|
+
try {
|
|
812
|
+
assert.equal(true, typeof a.iapFindAdapterPath === 'function');
|
|
813
|
+
done();
|
|
814
|
+
} catch (error) {
|
|
815
|
+
log.error(`Test Failure: ${error}`);
|
|
816
|
+
done(error);
|
|
817
|
+
}
|
|
818
|
+
});
|
|
819
|
+
it('iapFindAdapterPath should find atleast one path that matches', (done) => {
|
|
820
|
+
try {
|
|
821
|
+
a.iapFindAdapterPath('{base_path}/{version}', (data, error) => {
|
|
822
|
+
try {
|
|
823
|
+
assert.equal(undefined, error);
|
|
824
|
+
assert.notEqual(undefined, data);
|
|
825
|
+
assert.notEqual(null, data);
|
|
826
|
+
assert.equal(true, data.found);
|
|
827
|
+
assert.notEqual(undefined, data.foundIn);
|
|
828
|
+
assert.notEqual(null, data.foundIn);
|
|
829
|
+
assert.notEqual(0, data.foundIn.length);
|
|
830
|
+
done();
|
|
831
|
+
} catch (err) {
|
|
832
|
+
log.error(`Test Failure: ${err}`);
|
|
833
|
+
done(err);
|
|
834
|
+
}
|
|
835
|
+
});
|
|
836
|
+
} catch (error) {
|
|
837
|
+
log.error(`Adapter Exception: ${error}`);
|
|
838
|
+
done(error);
|
|
839
|
+
}
|
|
840
|
+
}).timeout(attemptTimeout);
|
|
841
|
+
});
|
|
842
|
+
|
|
843
|
+
describe('#iapSuspendAdapter', () => {
|
|
844
|
+
it('should have a iapSuspendAdapter function', (done) => {
|
|
845
|
+
try {
|
|
846
|
+
assert.equal(true, typeof a.iapSuspendAdapter === 'function');
|
|
847
|
+
done();
|
|
848
|
+
} catch (error) {
|
|
849
|
+
log.error(`Test Failure: ${error}`);
|
|
850
|
+
done(error);
|
|
851
|
+
}
|
|
852
|
+
});
|
|
853
|
+
});
|
|
854
|
+
|
|
855
|
+
describe('#iapUnsuspendAdapter', () => {
|
|
856
|
+
it('should have a iapUnsuspendAdapter function', (done) => {
|
|
857
|
+
try {
|
|
858
|
+
assert.equal(true, typeof a.iapUnsuspendAdapter === 'function');
|
|
859
|
+
done();
|
|
860
|
+
} catch (error) {
|
|
861
|
+
log.error(`Test Failure: ${error}`);
|
|
862
|
+
done(error);
|
|
863
|
+
}
|
|
864
|
+
});
|
|
865
|
+
});
|
|
866
|
+
|
|
867
|
+
describe('#iapGetAdapterQueue', () => {
|
|
868
|
+
it('should have a iapGetAdapterQueue function', (done) => {
|
|
869
|
+
try {
|
|
870
|
+
assert.equal(true, typeof a.iapGetAdapterQueue === 'function');
|
|
871
|
+
done();
|
|
872
|
+
} catch (error) {
|
|
873
|
+
log.error(`Test Failure: ${error}`);
|
|
874
|
+
done(error);
|
|
875
|
+
}
|
|
876
|
+
});
|
|
877
|
+
});
|
|
878
|
+
|
|
879
|
+
describe('#iapTroubleshootAdapter', () => {
|
|
880
|
+
it('should have a iapTroubleshootAdapter function', (done) => {
|
|
881
|
+
try {
|
|
882
|
+
assert.equal(true, typeof a.iapTroubleshootAdapter === 'function');
|
|
883
|
+
done();
|
|
884
|
+
} catch (error) {
|
|
885
|
+
log.error(`Test Failure: ${error}`);
|
|
886
|
+
done(error);
|
|
887
|
+
}
|
|
888
|
+
});
|
|
889
|
+
});
|
|
890
|
+
|
|
891
|
+
describe('#iapRunAdapterHealthcheck', () => {
|
|
892
|
+
it('should have a iapRunAdapterHealthcheck function', (done) => {
|
|
893
|
+
try {
|
|
894
|
+
assert.equal(true, typeof a.iapRunAdapterHealthcheck === 'function');
|
|
895
|
+
done();
|
|
896
|
+
} catch (error) {
|
|
897
|
+
log.error(`Test Failure: ${error}`);
|
|
898
|
+
done(error);
|
|
899
|
+
}
|
|
900
|
+
});
|
|
901
|
+
});
|
|
902
|
+
|
|
903
|
+
describe('#iapRunAdapterConnectivity', () => {
|
|
904
|
+
it('should have a iapRunAdapterConnectivity function', (done) => {
|
|
905
|
+
try {
|
|
906
|
+
assert.equal(true, typeof a.iapRunAdapterConnectivity === 'function');
|
|
907
|
+
done();
|
|
908
|
+
} catch (error) {
|
|
909
|
+
log.error(`Test Failure: ${error}`);
|
|
910
|
+
done(error);
|
|
911
|
+
}
|
|
912
|
+
});
|
|
913
|
+
});
|
|
914
|
+
|
|
915
|
+
describe('#iapRunAdapterBasicGet', () => {
|
|
916
|
+
it('should have a iapRunAdapterBasicGet function', (done) => {
|
|
917
|
+
try {
|
|
918
|
+
assert.equal(true, typeof a.iapRunAdapterBasicGet === 'function');
|
|
919
|
+
done();
|
|
920
|
+
} catch (error) {
|
|
921
|
+
log.error(`Test Failure: ${error}`);
|
|
922
|
+
done(error);
|
|
923
|
+
}
|
|
924
|
+
});
|
|
925
|
+
});
|
|
926
|
+
|
|
927
|
+
describe('#iapMoveAdapterEntitiesToDB', () => {
|
|
928
|
+
it('should have a iapMoveAdapterEntitiesToDB function', (done) => {
|
|
929
|
+
try {
|
|
930
|
+
assert.equal(true, typeof a.iapMoveAdapterEntitiesToDB === 'function');
|
|
931
|
+
done();
|
|
932
|
+
} catch (error) {
|
|
933
|
+
log.error(`Test Failure: ${error}`);
|
|
934
|
+
done(error);
|
|
935
|
+
}
|
|
936
|
+
});
|
|
937
|
+
});
|
|
938
|
+
|
|
939
|
+
describe('#checkActionFiles', () => {
|
|
940
|
+
it('should have a checkActionFiles function', (done) => {
|
|
941
|
+
try {
|
|
942
|
+
assert.equal(true, typeof a.checkActionFiles === 'function');
|
|
943
|
+
done();
|
|
944
|
+
} catch (error) {
|
|
945
|
+
log.error(`Test Failure: ${error}`);
|
|
946
|
+
done(error);
|
|
947
|
+
}
|
|
948
|
+
});
|
|
949
|
+
it('the action files should be good - if failure change the log level as most issues are warnings', (done) => {
|
|
950
|
+
try {
|
|
951
|
+
const clean = a.checkActionFiles();
|
|
952
|
+
|
|
953
|
+
try {
|
|
954
|
+
for (let c = 0; c < clean.length; c += 1) {
|
|
955
|
+
log.error(clean[c]);
|
|
956
|
+
}
|
|
957
|
+
assert.equal(0, clean.length);
|
|
958
|
+
done();
|
|
959
|
+
} catch (err) {
|
|
960
|
+
log.error(`Test Failure: ${err}`);
|
|
961
|
+
done(err);
|
|
962
|
+
}
|
|
963
|
+
} catch (error) {
|
|
964
|
+
log.error(`Adapter Exception: ${error}`);
|
|
965
|
+
done(error);
|
|
966
|
+
}
|
|
967
|
+
}).timeout(attemptTimeout);
|
|
968
|
+
});
|
|
969
|
+
|
|
970
|
+
describe('#encryptProperty', () => {
|
|
971
|
+
it('should have a encryptProperty function', (done) => {
|
|
972
|
+
try {
|
|
973
|
+
assert.equal(true, typeof a.encryptProperty === 'function');
|
|
974
|
+
done();
|
|
975
|
+
} catch (error) {
|
|
976
|
+
log.error(`Test Failure: ${error}`);
|
|
977
|
+
done(error);
|
|
978
|
+
}
|
|
979
|
+
});
|
|
980
|
+
it('should get base64 encoded property', (done) => {
|
|
981
|
+
try {
|
|
982
|
+
a.encryptProperty('testing', 'base64', (data, error) => {
|
|
983
|
+
try {
|
|
984
|
+
assert.equal(undefined, error);
|
|
985
|
+
assert.notEqual(undefined, data);
|
|
986
|
+
assert.notEqual(null, data);
|
|
987
|
+
assert.notEqual(undefined, data.response);
|
|
988
|
+
assert.notEqual(null, data.response);
|
|
989
|
+
assert.equal(0, data.response.indexOf('{code}'));
|
|
990
|
+
done();
|
|
991
|
+
} catch (err) {
|
|
992
|
+
log.error(`Test Failure: ${err}`);
|
|
993
|
+
done(err);
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
} catch (error) {
|
|
997
|
+
log.error(`Adapter Exception: ${error}`);
|
|
998
|
+
done(error);
|
|
999
|
+
}
|
|
1000
|
+
}).timeout(attemptTimeout);
|
|
1001
|
+
it('should get encrypted property', (done) => {
|
|
1002
|
+
try {
|
|
1003
|
+
a.encryptProperty('testing', 'encrypt', (data, error) => {
|
|
1004
|
+
try {
|
|
1005
|
+
assert.equal(undefined, error);
|
|
1006
|
+
assert.notEqual(undefined, data);
|
|
1007
|
+
assert.notEqual(null, data);
|
|
1008
|
+
assert.notEqual(undefined, data.response);
|
|
1009
|
+
assert.notEqual(null, data.response);
|
|
1010
|
+
assert.equal(0, data.response.indexOf('{crypt}'));
|
|
1011
|
+
done();
|
|
1012
|
+
} catch (err) {
|
|
1013
|
+
log.error(`Test Failure: ${err}`);
|
|
1014
|
+
done(err);
|
|
1015
|
+
}
|
|
1016
|
+
});
|
|
1017
|
+
} catch (error) {
|
|
1018
|
+
log.error(`Adapter Exception: ${error}`);
|
|
1019
|
+
done(error);
|
|
1020
|
+
}
|
|
1021
|
+
}).timeout(attemptTimeout);
|
|
1022
|
+
});
|
|
1023
|
+
|
|
1024
|
+
// describe('#iapHasAdapterEntity', () => {
|
|
1025
|
+
// it('should have a iapHasAdapterEntity function', (done) => {
|
|
1026
|
+
// try {
|
|
1027
|
+
// assert.equal(true, typeof a.iapHasAdapterEntity === 'function');
|
|
1028
|
+
// done();
|
|
1029
|
+
// } catch (error) {
|
|
1030
|
+
// log.error(`Test Failure: ${error}`);
|
|
1031
|
+
// done(error);
|
|
1032
|
+
// }
|
|
1033
|
+
// });
|
|
1034
|
+
// it('should find entity', (done) => {
|
|
1035
|
+
// try {
|
|
1036
|
+
// a.iapHasAdapterEntity('template_entity', // 'a9e9c33dc61122760072455df62663d2', (data) => {
|
|
1037
|
+
// try {
|
|
1038
|
+
// assert.equal(true, data[0]);
|
|
1039
|
+
// done();
|
|
1040
|
+
// } catch (err) {
|
|
1041
|
+
// log.error(`Test Failure: ${err}`);
|
|
1042
|
+
// done(err);
|
|
1043
|
+
// }
|
|
1044
|
+
// });
|
|
1045
|
+
// } catch (error) {
|
|
1046
|
+
// log.error(`Adapter Exception: ${error}`);
|
|
1047
|
+
// done(error);
|
|
1048
|
+
// }
|
|
1049
|
+
// }).timeout(attemptTimeout);
|
|
1050
|
+
// it('should not find entity', (done) => {
|
|
1051
|
+
// try {
|
|
1052
|
+
// a.iapHasAdapterEntity('template_entity', 'blah', (data) => {
|
|
1053
|
+
// try {
|
|
1054
|
+
// assert.equal(false, data[0]);
|
|
1055
|
+
// done();
|
|
1056
|
+
// } catch (err) {
|
|
1057
|
+
// log.error(`Test Failure: ${err}`);
|
|
1058
|
+
// done(err);
|
|
1059
|
+
// }
|
|
1060
|
+
// });
|
|
1061
|
+
// } catch (error) {
|
|
1062
|
+
// log.error(`Adapter Exception: ${error}`);
|
|
1063
|
+
// done(error);
|
|
1064
|
+
// }
|
|
1065
|
+
// }).timeout(attemptTimeout);
|
|
1066
|
+
// });
|
|
1067
|
+
|
|
1068
|
+
describe('#hasEntities', () => {
|
|
1069
|
+
it('should have a hasEntities function', (done) => {
|
|
1070
|
+
try {
|
|
1071
|
+
assert.equal(true, typeof a.hasEntities === 'function');
|
|
1072
|
+
done();
|
|
1073
|
+
} catch (error) {
|
|
1074
|
+
log.error(`Test Failure: ${error}`);
|
|
1075
|
+
done(error);
|
|
1076
|
+
}
|
|
1077
|
+
});
|
|
1078
|
+
});
|
|
1079
|
+
|
|
1080
|
+
describe('#getDevice', () => {
|
|
1081
|
+
it('should have a getDevice function', (done) => {
|
|
1082
|
+
try {
|
|
1083
|
+
assert.equal(true, typeof a.getDevice === 'function');
|
|
1084
|
+
done();
|
|
1085
|
+
} catch (error) {
|
|
1086
|
+
log.error(`Test Failure: ${error}`);
|
|
1087
|
+
done(error);
|
|
1088
|
+
}
|
|
1089
|
+
});
|
|
1090
|
+
});
|
|
1091
|
+
|
|
1092
|
+
describe('#getDevicesFiltered', () => {
|
|
1093
|
+
it('should have a getDevicesFiltered function', (done) => {
|
|
1094
|
+
try {
|
|
1095
|
+
assert.equal(true, typeof a.getDevicesFiltered === 'function');
|
|
1096
|
+
done();
|
|
1097
|
+
} catch (error) {
|
|
1098
|
+
log.error(`Test Failure: ${error}`);
|
|
1099
|
+
done(error);
|
|
1100
|
+
}
|
|
1101
|
+
});
|
|
1102
|
+
});
|
|
1103
|
+
|
|
1104
|
+
describe('#isAlive', () => {
|
|
1105
|
+
it('should have a isAlive function', (done) => {
|
|
1106
|
+
try {
|
|
1107
|
+
assert.equal(true, typeof a.isAlive === 'function');
|
|
1108
|
+
done();
|
|
1109
|
+
} catch (error) {
|
|
1110
|
+
log.error(`Test Failure: ${error}`);
|
|
1111
|
+
done(error);
|
|
1112
|
+
}
|
|
1113
|
+
});
|
|
1114
|
+
});
|
|
1115
|
+
|
|
1116
|
+
describe('#getConfig', () => {
|
|
1117
|
+
it('should have a getConfig function', (done) => {
|
|
1118
|
+
try {
|
|
1119
|
+
assert.equal(true, typeof a.getConfig === 'function');
|
|
1120
|
+
done();
|
|
1121
|
+
} catch (error) {
|
|
1122
|
+
log.error(`Test Failure: ${error}`);
|
|
1123
|
+
done(error);
|
|
1124
|
+
}
|
|
1125
|
+
});
|
|
1126
|
+
});
|
|
1127
|
+
|
|
1128
|
+
describe('#iapGetDeviceCount', () => {
|
|
1129
|
+
it('should have a iapGetDeviceCount function', (done) => {
|
|
1130
|
+
try {
|
|
1131
|
+
assert.equal(true, typeof a.iapGetDeviceCount === 'function');
|
|
1132
|
+
done();
|
|
1133
|
+
} catch (error) {
|
|
1134
|
+
log.error(`Test Failure: ${error}`);
|
|
1135
|
+
done(error);
|
|
1136
|
+
}
|
|
1137
|
+
});
|
|
1138
|
+
});
|
|
1139
|
+
|
|
1140
|
+
/*
|
|
1141
|
+
-----------------------------------------------------------------------
|
|
1142
|
+
-----------------------------------------------------------------------
|
|
1143
|
+
*** All code above this comment will be replaced during a migration ***
|
|
1144
|
+
******************* DO NOT REMOVE THIS COMMENT BLOCK ******************
|
|
1145
|
+
-----------------------------------------------------------------------
|
|
1146
|
+
-----------------------------------------------------------------------
|
|
1147
|
+
*/
|
|
1148
|
+
|
|
1149
|
+
describe('#postLog - errors', () => {
|
|
1150
|
+
it('should have a postLog function', (done) => {
|
|
1151
|
+
assert.equal(true, typeof a.postLog === 'function');
|
|
1152
|
+
done();
|
|
1153
|
+
});
|
|
1154
|
+
it('should error on postLog - no severity', (done) => {
|
|
1155
|
+
try {
|
|
1156
|
+
a.postLog(null, null, null, (data, error) => {
|
|
1157
|
+
try {
|
|
1158
|
+
const displayE = 'severity is required';
|
|
1159
|
+
runErrorAsserts(data, error, 'AD.300', 'Test-winston_syslog-adapter-postLog', displayE);
|
|
1160
|
+
done();
|
|
1161
|
+
} catch (ex) {
|
|
1162
|
+
log.error(`Test Failure: ${ex}`);
|
|
1163
|
+
done(ex);
|
|
1164
|
+
}
|
|
1165
|
+
});
|
|
1166
|
+
} catch (exc) {
|
|
1167
|
+
log.error(`Adapter Exception: ${exc}`);
|
|
1168
|
+
done(exc);
|
|
1169
|
+
}
|
|
1170
|
+
}).timeout(attemptTimeout);
|
|
1171
|
+
it('should error on postLog - no facility', (done) => {
|
|
1172
|
+
try {
|
|
1173
|
+
a.postLog('info', null, null, (data, error) => {
|
|
1174
|
+
try {
|
|
1175
|
+
const displayE = 'facility is required';
|
|
1176
|
+
runErrorAsserts(data, error, 'AD.300', 'Test-winston_syslog-adapter-postLog', displayE);
|
|
1177
|
+
done();
|
|
1178
|
+
} catch (ex) {
|
|
1179
|
+
log.error(`Test Failure: ${ex}`);
|
|
1180
|
+
done(ex);
|
|
1181
|
+
}
|
|
1182
|
+
});
|
|
1183
|
+
} catch (exc) {
|
|
1184
|
+
log.error(`Adapter Exception: ${exc}`);
|
|
1185
|
+
done(exc);
|
|
1186
|
+
}
|
|
1187
|
+
}).timeout(attemptTimeout);
|
|
1188
|
+
it('should error on postLog - no message', (done) => {
|
|
1189
|
+
try {
|
|
1190
|
+
a.postLog('info', 'local0', null, (data, error) => {
|
|
1191
|
+
try {
|
|
1192
|
+
const displayE = 'message is required';
|
|
1193
|
+
runErrorAsserts(data, error, 'AD.300', 'Test-winston_syslog-adapter-postLog', displayE);
|
|
1194
|
+
done();
|
|
1195
|
+
} catch (ex) {
|
|
1196
|
+
log.error(`Test Failure: ${ex}`);
|
|
1197
|
+
done(ex);
|
|
1198
|
+
}
|
|
1199
|
+
});
|
|
1200
|
+
} catch (exc) {
|
|
1201
|
+
log.error(`Adapter Exception: ${exc}`);
|
|
1202
|
+
done(exc);
|
|
1203
|
+
}
|
|
1204
|
+
}).timeout(attemptTimeout);
|
|
1205
|
+
});
|
|
1206
|
+
});
|
|
1207
|
+
});
|