mirror of
https://github.com/BreizhHardware/express-prom-bundle.git
synced 2026-03-18 21:30:38 +01:00
fix unittest for prom-client 15
This commit is contained in:
@@ -10,6 +10,16 @@ const supertestKoa = require('supertest-koa-agent');
|
|||||||
const promClient = require('prom-client');
|
const promClient = require('prom-client');
|
||||||
const cluster = require('cluster');
|
const cluster = require('cluster');
|
||||||
|
|
||||||
|
// for some reason in prom-client 15 the hashmap has a trailing comma
|
||||||
|
function extractBucket (instance, key) {
|
||||||
|
const hashmap = instance.metrics.http_request_duration_seconds.hashMap;
|
||||||
|
if (hashmap[key]) {
|
||||||
|
return hashmap[key];
|
||||||
|
} else {
|
||||||
|
return hashmap[key + ','];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
describe('index', () => {
|
describe('index', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
promClient.register.clear();
|
promClient.register.clear();
|
||||||
@@ -158,10 +168,9 @@ describe('index', () => {
|
|||||||
agent
|
agent
|
||||||
.get('/test')
|
.get('/test')
|
||||||
.end(() => {
|
.end(() => {
|
||||||
const metricHashMap = instance.metrics.http_request_duration_seconds.hashMap;
|
const bucket = extractBucket(instance, 'status_code:200');
|
||||||
expect(metricHashMap['status_code:200']).toBeDefined();
|
expect(bucket).toBeDefined();
|
||||||
const labeled = metricHashMap['status_code:200'];
|
expect(bucket.count).toBe(1);
|
||||||
expect(labeled.count).toBe(1);
|
|
||||||
|
|
||||||
agent
|
agent
|
||||||
.get('/metrics')
|
.get('/metrics')
|
||||||
@@ -223,11 +232,11 @@ describe('index', () => {
|
|||||||
agent
|
agent
|
||||||
.get('/good-word')
|
.get('/good-word')
|
||||||
.end(() => {
|
.end(() => {
|
||||||
const metricHashMap = instance.metrics.http_request_duration_seconds.hashMap;
|
const bucket = extractBucket(instance, 'status_code:200');
|
||||||
expect(metricHashMap['status_code:200']).toBeDefined();
|
expect(bucket).toBeDefined();
|
||||||
|
|
||||||
// only /good-word should be counted
|
// only /good-word should be counted
|
||||||
expect(metricHashMap['status_code:200'].count).toBe(1);
|
expect(bucket.count).toBe(1);
|
||||||
|
|
||||||
agent
|
agent
|
||||||
.get('/metrics')
|
.get('/metrics')
|
||||||
@@ -266,12 +275,10 @@ describe('index', () => {
|
|||||||
.expect(500);
|
.expect(500);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const metricHashMap = instance.metrics.http_request_duration_seconds.hashMap;
|
|
||||||
|
|
||||||
// only /200 and /500 should be counted
|
// only /200 and /500 should be counted
|
||||||
expect(metricHashMap['status_code:200'].count).toBe(1);
|
expect(extractBucket(instance, 'status_code:200').count).toBe(1);
|
||||||
expect(metricHashMap['status_code:404']).not.toBeDefined();
|
expect(extractBucket(instance, 'status_code:404')).not.toBeDefined();
|
||||||
expect(metricHashMap['status_code:500'].count).toBe(1);
|
expect(extractBucket(instance, 'status_code:500').count).toBe(1);
|
||||||
|
|
||||||
return agent
|
return agent
|
||||||
.get('/metrics')
|
.get('/metrics')
|
||||||
|
|||||||
Reference in New Issue
Block a user