12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- -module(h2spec_SUITE).
- -compile(export_all).
- -import(ct_helper, [config/2]).
- -import(ct_helper, [doc/1]).
- 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).
- init_dispatch() ->
- cowboy_router:compile([
- {"localhost", [
- {"/", hello_h, []}
- ]}
- ]).
- 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.
|