Skip to content

Commit

Permalink
test httpd mod integration
Browse files Browse the repository at this point in the history
  • Loading branch information
deadtrickster committed Mar 9, 2017
1 parent 5691768 commit 02c1aeb
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions test/ct/prometheus_httpd_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ groups() ->
{positive, [sequential], [
prometheus_httpd_standalone,
prometheus_httpd_negotiation,
prometheus_httpd_negotiation_fail
prometheus_httpd_negotiation_fail,

prometheus_httpd_mod
]}
].

Expand All @@ -46,6 +48,22 @@ init_per_suite(Config) ->
{ok, _} = application:ensure_all_started(inets),
{ok, _} = application:ensure_all_started(prometheus),
prometheus_httpd:start(),

inets:start(httpd, [
{modules, [
prometheus_httpd,
mod_get
]},
{port, 8082},
{server_name, "my test_server_name"},
{document_root, code:priv_dir(prometheus_httpd)},
{server_root, code:priv_dir(prometheus_httpd)},
{mime_types,[
{"html","text/html"},
{"css","text/css"},
{"js","application/x-javascript"}
]}
]),
Config.

%% ===================================================================
Expand All @@ -70,7 +88,6 @@ prometheus_httpd_standalone(_Config) ->
?assertMatch([{"content-length", ExpectedHTMLCL},
{"content-type", ExpectedHTMLCT}|_]
when ExpectedHTMLCL > 0, headers(HTMLResponse)),

Path = prometheus_httpd_config:path(),
?assertMatch({match, _}, re:run(body(HTMLResponse), ["href=\"", Path, "\""])).

Expand Down Expand Up @@ -127,6 +144,35 @@ prometheus_httpd_negotiation_fail(_Config) ->
{"content-type", "text/html"}|_],
headers(CTResponse)).

prometheus_httpd_mod(_Config) ->
{ok, MetricsResponse} = httpc:request("http://localhost:8082/metrics"),
?assertMatch(200, status(MetricsResponse)),
MetricsCT = prometheus_text_format:content_type(),
ExpecteMetricsCT = binary_to_list(MetricsCT),
?assertMatch([{"content-encoding", "gzip"},
{"content-length", ExpectedMetricsCL},
{"content-type", ExpecteMetricsCT}|_]
when ExpectedMetricsCL > 0, headers(MetricsResponse)),
MetricsBody = zlib:gunzip(body(MetricsResponse)),
?assertMatch(true, all_telemetry_metrics_present(MetricsBody)),

{ok, HTMLResponse} = httpc:request("http://localhost:8082/index.html"),
?assertMatch(200, status(HTMLResponse)),
ExpectedHTMLCT = "text/html",
?assertMatch([{"content-length", ExpectedHTMLCL},
{"content-type", ExpectedHTMLCT}|_]
when ExpectedHTMLCL > 0, headers(HTMLResponse)),
?assertMatch({match, _}, re:run(body(HTMLResponse), "M_E_T_R_I_C_S")),

{ok, CTResponse} =
httpc:request(get, {"http://localhost:8082/qwe",
[]}, [], []),
?assertMatch(404, status(CTResponse)),
?assertMatch([{"content-length", CL404},
{"content-type", "text/html"}|_]
when CL404 > 0,
headers(CTResponse)).

%% ===================================================================
%% Private parts
%% ===================================================================
Expand Down

0 comments on commit 02c1aeb

Please sign in to comment.