Skip to content

Commit 8d5af3a

Browse files
committed
Add tests
1 parent 3b20a63 commit 8d5af3a

File tree

3 files changed

+7
-24
lines changed

3 files changed

+7
-24
lines changed

bin/configurable-http-proxy

+1-6
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,7 @@ log.info(
342342
listen.apiPort
343343
);
344344
if (listen.metricsPort) {
345-
log.info(
346-
"Serve metrics at %s://%s:%s/metrics",
347-
"http",
348-
listen.metricsIp,
349-
listen.metricsPort
350-
);
345+
log.info("Serve metrics at %s://%s:%s/metrics", "http", listen.metricsIp, listen.metricsPort);
351346
}
352347

353348
if (args.pidFile) {

lib/testutil.js

+6
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,18 @@ exports.setupProxy = function (port, options, paths) {
128128

129129
servers.push(proxy.apiServer);
130130
servers.push(proxy.proxyServer);
131+
if (options.enableMetrics) {
132+
servers.push(proxy.metricsServer);
133+
}
131134
proxy.apiServer.on("listening", onlisten);
132135
proxy.proxyServer.on("listening", onlisten);
133136

134137
addTargets(proxy, paths || ["/"], port + 2).then(function () {
135138
proxy.proxyServer.listen(port, ip);
136139
proxy.apiServer.listen(port + 1, ip);
140+
if (options.enableMetrics) {
141+
proxy.metricsServer.listen(port + 3, ip);
142+
}
137143
});
138144
return p;
139145
};

test/api_spec.js

-18
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ describe("API Tests", function () {
1313
var apiPort = port + 1;
1414
var proxy;
1515
var apiUrl = "http://127.0.0.1:" + apiPort + "/api/routes";
16-
var metricsUrl = "http://127.0.0.1:" + apiPort + "/metrics";
1716

1817
var r;
1918

@@ -261,21 +260,4 @@ describe("API Tests", function () {
261260
.then(() => doReq(0))
262261
.then();
263262
});
264-
265-
it("GET /metrics", function (done) {
266-
r(metricsUrl).then((body) => {
267-
expect(body).toContain("process_cpu_user_seconds_total");
268-
done();
269-
});
270-
});
271-
272-
it("GET /metrics (disabled)", function (done) {
273-
proxy.options.disableMetrics = true;
274-
r(metricsUrl)
275-
.then((body) => done.fail("Expected 404"))
276-
.catch((error) => {
277-
expect(error.statusCode).toEqual(404);
278-
})
279-
.then(done);
280-
});
281263
});

0 commit comments

Comments
 (0)