typo correction
[KisSync.git] / test / prometheus-server.js
blobf7212921ea2262687f8e735563b6a4e37c01750d
1 const assert = require('assert');
2 const http = require('http');
3 const server = require('../lib/prometheus-server');
4 const PrometheusConfig = require('../lib/configuration/prometheusconfig').PrometheusConfig;
6 describe('prometheus-server', () => {
7 before(done => {
8 let inst = server.init(new PrometheusConfig({
9 prometheus: {
10 enabled: true,
11 port: 19820,
12 host: '127.0.0.1',
13 path: '/metrics'
15 }));
16 inst.once('listening', () => done());
17 });
19 function checkReq(options, done) {
20 const req = http.request({
21 method: options.method,
22 host: '127.0.0.1',
23 port: 19820,
24 path: options.path
25 }, res => {
26 assert.strictEqual(res.statusCode, options.expectedStatusCode);
27 assert.strictEqual(res.headers['content-type'], options.expectedContentType);
28 res.on('data', () => {});
29 res.on('end', () => done());
30 });
32 req.end();
35 it('rejects a non-GET request', done => {
36 checkReq({
37 method: 'POST',
38 path: '/metrics',
39 expectedStatusCode: 400,
40 expectedContentType: 'text/plain'
41 }, done);
42 });
44 it('rejects a request for the wrong path', done => {
45 checkReq({
46 method: 'GET',
47 path: '/qwerty',
48 expectedStatusCode: 400,
49 expectedContentType: 'text/plain'
50 }, done);
51 });
53 it('accepts a request for the configured path', done => {
54 checkReq({
55 method: 'GET',
56 path: '/metrics',
57 expectedStatusCode: 200,
58 expectedContentType: 'text/plain; version=0.0.4; charset=utf-8'
59 }, done);
60 });
62 after(() => {
63 server.shutdown();
64 });
65 });