1: -module(test_stream_SUITE).
2:
3: -include_lib("common_test/include/ct.hrl").
4: -include_lib("kernel/include/logger.hrl").
5:
6: %% common_test callbacks
7: -export([suite/0, all/0, init_per_suite/1, end_per_suite/1]).
8:
9: %% tests
10: -export([test_stream/1]).
11:
12: -define(TIMEOUT, 1000).
13: -define(BASE_URL, "http://localhost").
14: -define(HTTPC_PROFILE, ?MODULE).
15:
16: %%
17: %% common_test callbacks
18: %%
19:
20: suite() -> [{timetrap, ?TIMEOUT}].
21:
22: all() -> [test_stream].
23:
24: init_per_suite(_Config) ->
25: {ok, _ApplicationPid} = eradio_app:start(),
26: {ok, {local, ListenPath}} = eradio_app:listen_ip(),
27:
28: {ok, _HttpcProfilePid} = inets:start(httpc, [{profile, ?HTTPC_PROFILE}]),
29: ok = httpc:set_options([{ipfamily, local}, {unix_socket, ListenPath}], ?HTTPC_PROFILE),
30: [].
31:
32: end_per_suite(_Config) ->
33: ok = inets:stop(httpc, ?HTTPC_PROFILE),
34: ok = eradio_app:stop(),
35: ok.
36:
37: %%
38: %% tests
39: %%
40:
41: test_stream(_Config) ->
42: Opts = [{sync, false}, {stream, self}],
43: {ok, RequestId} = request(get, {"/stream.mp3?listener_id=1", []}, [], Opts),
44: receive
45: {http, {RequestId, stream_start, _Headers}} -> ok;
46: {http, {RequestId, Result}} -> ct:fail(Result)
47: end.
48:
49: %%
50: %% private
51: %%
52:
53: request(Method, {Path, Headers}, HTTPOpts, Opts) ->
54: httpc:request(Method, {?BASE_URL ++ Path, Headers}, [{timeout, ?TIMEOUT} | HTTPOpts], Opts, ?HTTPC_PROFILE).