Skip to content
This repository was archived by the owner on Dec 14, 2022. It is now read-only.

Commit a139dc4

Browse files
author
Chris Wiechmann
authored
Merge pull request #9 from Axway-API-Management-Plus/fix-time-range-test
Stabilized Custom-Timerange tests
2 parents a4ae432 + 477be0b commit a139dc4

File tree

4 files changed

+73
-22
lines changed

4 files changed

+73
-22
lines changed

elk-traffic-monitor-api/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
},
4545
"scripts": {
4646
"start": "node .",
47-
"test": "mocha --exit --colors ./test --recursive -R spec"
47+
"test": "mocha --exit --colors ./test --recursive -R spec",
48+
"test:debug": "mocha --inspect-brk ./test --recursive -R spec --timeout 10000"
4849
}
4950
}

elk-traffic-monitor-api/test/documents/basic/search_test_documents.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const getDate = require('../util');
1+
const getDate = require('../../util');
22

33
module.exports = [
44
{
@@ -419,7 +419,7 @@ module.exports = [
419419
"@version": "1",
420420
"transactionSummaryContext": null,
421421
"correlationId": "bb30715e5300e189d1da43fc",
422-
"timestampOriginal": "2020-03-17T20:19:07.812Z",
422+
"timestampOriginal": getDate('30000h'),
423423
"circuitPath": [
424424
{
425425
"execTime": 1,

elk-traffic-monitor-api/test/endpoints.js

Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const { expect } = require('chai');
22
const { startApiBuilder, stopApiBuilder, requestAsync, sendToElasticsearch, getRandomInt } = require('./_base');
33
const fs = require('fs');
4+
const getDate = require('./util');
45

56
describe('Endpoints', function () {
67
this.timeout(30000);
@@ -37,7 +38,6 @@ describe('Endpoints', function () {
3738
after(() => stopApiBuilder(server));
3839

3940
describe('Search', () => {
40-
debugger;
4141
it('[Search-0001] Execute a search without a limit including all requests from instance-1', () => {
4242
return requestAsync({
4343
method: 'GET',
@@ -151,19 +151,65 @@ describe('Endpoints', function () {
151151
user: server.apibuilder.config.apikey || 'test',
152152
password: ''
153153
};
154+
//
155+
/**
156+
* The dates given here must be aligned with dates in search_test_documents.js. Currently configured like so:
157+
* 8m --> "c8705e5ecc00adca32be7472"
158+
* 15m --> "c9705e5ecd000322778d2ec4" --> This is expected to be found
159+
* 120h --> "fc705e5ede00654de6d15daf"
160+
* 65m --> "4e645e5e4600bb590c881179" --> This is expected to be found
161+
* 30000h --> "bb30715e5300e189d1da43fc"
162+
*/
163+
const greaterThenThisDate = getDate('10h', true);
164+
const lowerThanThisDate = getDate('10m', true);
165+
console.log(`Query with greaterThenThisDate: ${greaterThenThisDate} and lowerThanThisDate: ${lowerThanThisDate}`);
154166
return requestAsync({
155167
method: 'GET',
156-
uri: `http://localhost:${server.apibuilder.port}/api/elk/v1/api/router/service/instance-1/ops/search?field=timestamp&op=gt&value=1577833200000&field=timestamp&op=lt&value=1585691940000`,
168+
uri: `http://localhost:${server.apibuilder.port}/api/elk/v1/api/router/service/instance-1/ops/search?field=timestamp&op=gt&value=${greaterThenThisDate}&field=timestamp&op=lt&value=${lowerThanThisDate}`,
157169
auth: auth,
158170
json: true
159171
}).then(({ response, body }) => {
160172
expect(response.statusCode).to.equal(200);
161173
expect(body).to.be.an('Object');
162174
expect(body).to.have.property('data');
163-
expect(body.data).to.have.lengthOf(4);
175+
expect(body.data).to.have.lengthOf(2);
176+
expect(body.data[0].correlationId).to.equal("c9705e5ecd000322778d2ec4");
177+
expect(body.data[1].correlationId).to.equal("4e645e5e4600bb590c881179");
164178
});
165179
});
166-
it('[Endpoint-0008] should return two entries with localport 8080', () => {
180+
it('[Endpoint-0008] should return 3 when using a wider custom time-range', () => {
181+
const auth = {
182+
user: server.apibuilder.config.apikey || 'test',
183+
password: ''
184+
};
185+
//
186+
/**
187+
* The dates given here must be aligned with dates in search_test_documents.js. Currently configured like so:
188+
* 8m --> "c8705e5ecc00adca32be7472" --> This is expected to be found
189+
* 15m --> "c9705e5ecd000322778d2ec4" --> This is expected to be found
190+
* 120h --> "fc705e5ede00654de6d15daf"
191+
* 65m --> "4e645e5e4600bb590c881179" --> This is expected to be found
192+
* 30000h --> "bb30715e5300e189d1da43fc"
193+
*/
194+
const greaterThenThisDate = getDate('110h', true);
195+
const lowerThanThisDate = getDate('5m', true);
196+
console.log(`Query with greaterThenThisDate: ${greaterThenThisDate} and lowerThanThisDate: ${lowerThanThisDate}`);
197+
return requestAsync({
198+
method: 'GET',
199+
uri: `http://localhost:${server.apibuilder.port}/api/elk/v1/api/router/service/instance-1/ops/search?field=timestamp&op=gt&value=${greaterThenThisDate}&field=timestamp&op=lt&value=${lowerThanThisDate}`,
200+
auth: auth,
201+
json: true
202+
}).then(({ response, body }) => {
203+
expect(response.statusCode).to.equal(200);
204+
expect(body).to.be.an('Object');
205+
expect(body).to.have.property('data');
206+
expect(body.data).to.have.lengthOf(3);
207+
expect(body.data[0].correlationId).to.equal("c8705e5ecc00adca32be7472");
208+
expect(body.data[1].correlationId).to.equal("c9705e5ecd000322778d2ec4");
209+
expect(body.data[2].correlationId).to.equal("4e645e5e4600bb590c881179");
210+
});
211+
});
212+
it('[Endpoint-0009] should return two entries with localport 8080', () => {
167213
const auth = {
168214
user: server.apibuilder.config.apikey || 'test',
169215
password: ''
@@ -182,7 +228,7 @@ describe('Endpoints', function () {
182228
});
183229
});
184230

185-
it('[Endpoint-0009] should return one entry with localport 8080 and given subject-id', () => {
231+
it('[Endpoint-0010] should return one entry with localport 8080 and given subject-id', () => {
186232
const auth = {
187233
user: server.apibuilder.config.apikey || 'test',
188234
password: ''
@@ -201,7 +247,7 @@ describe('Endpoints', function () {
201247
expect(body.data[0].subject).to.equals('Chris-Test');
202248
});
203249
});
204-
it('[Endpoint-0010] should return one entry with localport 8080 and given subject-id', () => {
250+
it('[Endpoint-0011] should return one entry with localport 8080 and given subject-id', () => {
205251
const auth = {
206252
user: server.apibuilder.config.apikey || 'test',
207253
password: ''
@@ -220,7 +266,7 @@ describe('Endpoints', function () {
220266
expect(body.data[0].uri).to.equals('/favicon.ico');
221267
});
222268
});
223-
it('[Endpoint-0011] should return one entry with localadr 1.1.1.1', () => {
269+
it('[Endpoint-0012] should return one entry with localadr 1.1.1.1', () => {
224270
const auth = {
225271
user: server.apibuilder.config.apikey || 'test',
226272
password: ''
@@ -239,7 +285,7 @@ describe('Endpoints', function () {
239285
expect(body.data[0].uri).to.equals('/healthcheck');
240286
});
241287
});
242-
it('[Endpoint-0012] should return one entry with remoteName (remoteHost) TestHost', () => {
288+
it('[Endpoint-0013] should return one entry with remoteName (remoteHost) TestHost', () => {
243289
const auth = {
244290
user: server.apibuilder.config.apikey || 'test',
245291
password: ''
@@ -258,7 +304,7 @@ describe('Endpoints', function () {
258304
expect(body.data[0].uri).to.equals('/healthcheck');
259305
});
260306
});
261-
it('[Endpoint-0013] should return one entry with remotePort 59641', () => {
307+
it('[Endpoint-0014] should return one entry with remotePort 59641', () => {
262308
const auth = {
263309
user: server.apibuilder.config.apikey || 'test',
264310
password: ''
@@ -277,7 +323,7 @@ describe('Endpoints', function () {
277323
expect(body.data[0].uri).to.equals('/favicon.ico');
278324
});
279325
});
280-
it('[Endpoint-0014] should return one entry with service name Petstore HTTP', () => {
326+
it('[Endpoint-0015] should return one entry with service name Petstore HTTP', () => {
281327
const auth = {
282328
user: server.apibuilder.config.apikey || 'test',
283329
password: ''
@@ -296,7 +342,7 @@ describe('Endpoints', function () {
296342
expect(body.data[0].uri).to.equals('/v2/pet/123');
297343
});
298344
});
299-
it('[Endpoint-0015] should return one entry with service name Petstore HTTP', () => {
345+
it('[Endpoint-0016] should return one entry with service name Petstore HTTP', () => {
300346
const auth = {
301347
user: server.apibuilder.config.apikey || 'test',
302348
password: ''
@@ -315,7 +361,7 @@ describe('Endpoints', function () {
315361
expect(body.data[0].uri).to.equals('/favicon.ico');
316362
});
317363
});
318-
it('[Endpoint-0016] should return one entry with the given correlation id', () => {
364+
it('[Endpoint-0017] should return one entry with the given correlation id', () => {
319365
const auth = {
320366
user: server.apibuilder.config.apikey || 'test',
321367
password: ''
@@ -334,7 +380,7 @@ describe('Endpoints', function () {
334380
expect(body.data[0].serviceName).to.equals('Petstore HTTP');
335381
});
336382
});
337-
it('[Endpoint-0017] should return one entry with final status Error', () => {
383+
it('[Endpoint-0018] should return one entry with final status Error', () => {
338384
const auth = {
339385
user: server.apibuilder.config.apikey || 'test',
340386
password: ''
@@ -352,7 +398,7 @@ describe('Endpoints', function () {
352398
expect(body.data[0].uri).to.equals('/healthcheck');
353399
});
354400
});
355-
it('[Endpoint-0018] should return results with a wirldcard path.', () => {
401+
it('[Endpoint-0019] should return results with a wirldcard path.', () => {
356402
const auth = {
357403
user: server.apibuilder.config.apikey || 'test',
358404
password: ''
@@ -370,7 +416,7 @@ describe('Endpoints', function () {
370416
expect(body.data[0].uri).to.equals('/v2/pet/123');
371417
});
372418
});
373-
it('[Endpoint-0019] Should return 1 entry in the last 10 minutes (ago=10m)', () => {
419+
it('[Endpoint-0020] Should return 1 entry in the last 10 minutes (ago=10m)', () => {
374420
const auth = {
375421
user: server.apibuilder.config.apikey || 'test',
376422
password: ''
@@ -388,7 +434,7 @@ describe('Endpoints', function () {
388434
expect(body.data[0].uri).to.equals('/v2/pet/123');
389435
});
390436
});
391-
it('[Endpoint-0020] Should return 2 entries in the last 30 minutes (ago=30m)', () => {
437+
it('[Endpoint-0021] Should return 2 entries in the last 30 minutes (ago=30m)', () => {
392438
const auth = {
393439
user: server.apibuilder.config.apikey || 'test',
394440
password: ''
@@ -406,7 +452,7 @@ describe('Endpoints', function () {
406452
expect(body.data[0].uri).to.equals('/v2/pet/123');
407453
});
408454
});
409-
it('[Endpoint-0020] Should only 2 entries in the last 2 hours (ago=120h)', () => {
455+
it('[Endpoint-0022] Should only 2 entries in the last 2 hours (ago=120h)', () => {
410456
const auth = {
411457
user: server.apibuilder.config.apikey || 'test',
412458
password: ''
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
function getDate(ago) {
1+
function getDate(ago, asEpoche) {
22
var now = new Date();
33
var diff = ago.substring(0, ago.length-1);
44
if(ago.endsWith('m')) {
55
now.setMinutes(now.getMinutes() - diff);
66
} else if(ago.endsWith('h')) {
77
now.setHours(now.getHours() - diff);
88
}
9-
return now.toISOString();
9+
if(asEpoche) {
10+
return now.getTime();
11+
} else {
12+
return now.toISOString();
13+
}
1014
}
1115

1216
module.exports = getDate;

0 commit comments

Comments
 (0)