diff options
author | Loïc Hoguin <[email protected]> | 2017-05-23 14:04:01 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2017-05-23 14:05:00 +0200 |
commit | 4048f16365047ac9b16a5dbf4c3aae0b665a613c (patch) | |
tree | 44ec0c446e74cc15089fdf27b50f244f10bba274 | |
parent | 8ed44cd9a9a1b80d8b4bb007753e557c41d5240b (diff) | |
download | cowboy-4048f16365047ac9b16a5dbf4c3aae0b665a613c.tar.gz cowboy-4048f16365047ac9b16a5dbf4c3aae0b665a613c.tar.bz2 cowboy-4048f16365047ac9b16a5dbf4c3aae0b665a613c.zip |
Add a test suite for h2spec
h2spec must be preinstalled on the machine and its location
pointed at by the H2SPEC environment variable.
-rw-r--r-- | test/h2spec_SUITE.erl | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/test/h2spec_SUITE.erl b/test/h2spec_SUITE.erl new file mode 100644 index 0000000..28e3fa8 --- /dev/null +++ b/test/h2spec_SUITE.erl @@ -0,0 +1,79 @@ +%% Copyright (c) 2017, Loïc Hoguin <[email protected]> +%% +%% Permission to use, copy, modify, and/or distribute this software for any +%% purpose with or without fee is hereby granted, provided that the above +%% copyright notice and this permission notice appear in all copies. +%% +%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +-module(h2spec_SUITE). +-compile(export_all). + +-import(ct_helper, [config/2]). +-import(ct_helper, [doc/1]). + +%% ct. + +all() -> + [h2spec]. + +init_per_suite(Config) -> + case os:getenv("H2SPEC") of + false -> + skip; + _ -> + cowboy_test:init_http2(h2spec, #{ + env => #{dispatch => init_dispatch()} + }, Config) + end. + +end_per_suite(_Config) -> + cowboy:stop_listener(h2spec). + +%% Dispatch configuration. + +init_dispatch() -> + cowboy_router:compile([ + {"localhost", [ + {"/", hello_h, []} + ]} + ]). + +%% Tests. + +h2spec(Config) -> + doc("h2spec test suite for the HTTP/2 protocol."), + Self = self(), + spawn_link(fun() -> start_port(Config, Self) end), + receive + {h2spec_exit, 0, Log} -> + ct:log("~ts", [Log]), + ok; + {h2spec_exit, Status, Log} -> + ct:log("~ts", [Log]), + error({exit_status, Status}) + end. + +start_port(Config, Pid) -> + H2spec = os:getenv("H2SPEC"), + ListenPort = config(port, Config), + Port = open_port( + {spawn, H2spec ++ " -S -t -k -p " + ++ integer_to_list(ListenPort)}, + [{line, 10000}, {cd, config(priv_dir, Config)}, binary, exit_status]), + receive_infinity(Port, Pid, []). + +receive_infinity(Port, Pid, Acc) -> + receive + {Port, {data, {eol, Line}}} -> + io:format(user, "~s~n", [Line]), + receive_infinity(Port, Pid, [Line|Acc]); + {Port, {exit_status, Status}} -> + Pid ! {h2spec_exit, Status, [[L, $\n] || L <- lists:reverse(Acc)]} + end. |