From e9e15d4d5be7bbf58907e8fee4a91a6c2fac01de Mon Sep 17 00:00:00 2001 From: vkatsuba Date: Wed, 28 Jul 2021 15:20:03 +0300 Subject: [PATCH] Remove ibrowse --- big_tests/rebar.config | 2 +- big_tests/rebar.lock | 5 +-- big_tests/src/ejabberd_tests.app.src | 3 +- big_tests/tests/mod_http_upload_SUITE.erl | 49 +++++++++++++++++++---- tools/setup_riak.escript | 3 +- 5 files changed, 47 insertions(+), 15 deletions(-) diff --git a/big_tests/rebar.config b/big_tests/rebar.config index 0a487b3fee..3bc944d49d 100644 --- a/big_tests/rebar.config +++ b/big_tests/rebar.config @@ -14,6 +14,7 @@ {erlsh, {git, "https://github.com/proger/erlsh.git", {ref, "4e8a107"}}}, {jiffy, "1.0.8"}, {proper, "1.4.0"}, + {gun, "1.3.2"}, {escalus, {git, "https://github.com/esl/escalus.git", {branch, "master"}}}, {gen_fsm_compat, "0.3.0"}, {cowboy, "2.9.0"}, @@ -21,7 +22,6 @@ {shotgun, "0.4.1"}, {amqp_client, "3.8.14"}, {esip, "1.0.33"}, - {ibrowse, "4.4.1"}, {jid, "1.0.0", {pkg, mongoose_jid}} ]}. diff --git a/big_tests/rebar.lock b/big_tests/rebar.lock index b6882dd75e..c8b7fe73e3 100644 --- a/big_tests/rebar.lock +++ b/big_tests/rebar.lock @@ -32,8 +32,7 @@ 1}, {<<"gen_fsm_compat">>,{pkg,<<"gen_fsm_compat">>,<<"0.3.0">>},0}, {<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.9">>},1}, - {<<"gun">>,{pkg,<<"gun">>,<<"1.3.2">>},1}, - {<<"ibrowse">>,{pkg,<<"ibrowse">>,<<"4.4.1">>},0}, + {<<"gun">>,{pkg,<<"gun">>,<<"1.3.2">>},0}, {<<"jid">>,{pkg,<<"mongoose_jid">>,<<"1.0.0">>},0}, {<<"jiffy">>,{pkg,<<"jiffy">>,<<"1.0.8">>},0}, {<<"jsx">>,{pkg,<<"jsx">>,<<"2.9.0">>},2}, @@ -64,7 +63,6 @@ {<<"gen_fsm_compat">>, <<"5903549F67D595F58A7101154CBE0FDD46955FBFBE40813F1E53C23A970FF5F4">>}, {<<"goldrush">>, <<"F06E5D5F1277DA5C413E84D5A2924174182FB108DABB39D5EC548B27424CD106">>}, {<<"gun">>, <<"542064CBB9F613650B8A8100B3A927505F364FBE198B7A5A112868FF43F3E477">>}, - {<<"ibrowse">>, <<"2B7D0637B0F8B9B4182DE4BD0F2E826A4DA2C9B04898B6E15659BA921A8D6EC2">>}, {<<"jid">>, <<"B6D8F9E3015CCB36868D5DB1E847C6176C4F7513360F11CA07B8B95DDC42421E">>}, {<<"jiffy">>, <<"60E36F00BE35E5AC6E6CF2D4CAF3BDF3103D4460AFF385F543A8D7DF2D6D9613">>}, {<<"jsx">>, <<"D2F6E5F069C00266CAD52FB15D87C428579EA4D7D73A33669E12679E203329DD">>}, @@ -94,7 +92,6 @@ {<<"gen_fsm_compat">>, <<"7153D11BAD328933D4B24E663D8CEC52874E14176C7FB392FA1FF768B17460D9">>}, {<<"goldrush">>, <<"99CB4128CFFCB3227581E5D4D803D5413FA643F4EB96523F77D9E6937D994CEB">>}, {<<"gun">>, <<"BA323F0A5FD8ABAC379A3E1FE6D8CE570C4A12C7FD1C68F4994B53447918E462">>}, - {<<"ibrowse">>, <<"1E86C591DBC6D270632625534986BECA30813AF7CE784E742E5FC38E342C29B3">>}, {<<"jid">>, <<"D96C1223660E54549305252A3492500980505652AEB80950E201A3C446C4C9D2">>}, {<<"jiffy">>, <<"F9AE986BA5A0854EB48CF6A76192D9367086DA86C20197DA430630BE7C087A4E">>}, {<<"jsx">>, <<"8EE1DB1CABAFDD578A2776A6AAAE87C2A8CE54B47B59E9EC7DAB5D7EB71CD8DC">>}, diff --git a/big_tests/src/ejabberd_tests.app.src b/big_tests/src/ejabberd_tests.app.src index 482a2e6779..9977d95a54 100644 --- a/big_tests/src/ejabberd_tests.app.src +++ b/big_tests/src/ejabberd_tests.app.src @@ -8,7 +8,8 @@ stdlib, cowboy, gen_fsm_compat, - jid + jid, + gun ]}, {env, []} ]}. diff --git a/big_tests/tests/mod_http_upload_SUITE.erl b/big_tests/tests/mod_http_upload_SUITE.erl index 244a63a39a..ab95666c24 100644 --- a/big_tests/tests/mod_http_upload_SUITE.erl +++ b/big_tests/tests/mod_http_upload_SUITE.erl @@ -98,11 +98,9 @@ suite() -> %%-------------------------------------------------------------------- init_per_suite(Config) -> - ibrowse:start(), escalus:init_per_suite(Config). end_per_suite(Config) -> - ibrowse:stop(), escalus:end_per_suite(Config). init_per_group(unset_size, Config) -> @@ -278,12 +276,49 @@ test_minio_upload(Config, ContentType) -> GetUrl = binary_to_list(extract_url(Result, <<"get">>)), PutUrl = binary_to_list(extract_url(Result, <<"put">>)), Header = generate_header(Config, ContentType), - PutRetValue = ibrowse:send_req(PutUrl, Header, put, ?MINIO_TEST_DATA), - ?assertMatch({ok, "200", _, []}, PutRetValue), - GetRetValue = ibrowse:send_req(GetUrl, [], get), - ?assertMatch({ok, "200", _, ?MINIO_TEST_DATA}, GetRetValue) + PutRetValue = request(put, PutUrl, Header, ?MINIO_TEST_DATA), + ?assertMatch({200, _}, PutRetValue), + GetRetValue = request(get, GetUrl, [], []), + ?assertMatch({200, ?MINIO_TEST_DATA}, GetRetValue) end). +request(Method, PutUrl, Header, Data) -> + PURL = #{host := Host, port := Port, path := Path} = uri_string:parse(PutUrl), + {ok, ConnPid} = gun:open(Host, Port), + {ok, _} = gun:await_up(ConnPid), + FullPath = + case PURL of + #{query := Query} -> + Path ++ "?" ++ Query; + _ -> + Path + end, + StreamRef = + case Method of + put -> + gun:put(ConnPid, FullPath, Header, Data); + get -> + gun:get(ConnPid, FullPath) + end, + RespOpts = #{pid => ConnPid, stream_ref => StreamRef, acc => <<>>}, + #{status := Status, acc := Acc} = get_reponse(RespOpts), + ok = gun:close(ConnPid), + {Status, binary_to_list(Acc)}. + +get_reponse(#{pid := Pid, stream_ref := StreamRef, acc := Acc} = Opts) -> + case gun:await(Pid, StreamRef) of + {response, fin, Status, _} -> + Opts#{status => Status, acc => Acc}; + {response, nofin, Status, _} -> + get_reponse(Opts#{status => Status}); + {data, nofin, Data} -> + get_reponse(Opts#{acc => <>}); + {data, fin, Data} -> + Opts#{acc => <>}; + Error -> + Error + end. + generate_header(Config, undefined) -> case proplists:get_value(with_acl, Config, false) of true -> @@ -292,7 +327,7 @@ generate_header(Config, undefined) -> [] end; generate_header(Config, ContentType) -> - [{<<"Content-Type">>, ContentType} | generate_header(Config, undefined)]. + [{<<"content-type">>, ContentType} | generate_header(Config, undefined)]. rejects_empty_filename(Config) -> escalus:story( diff --git a/tools/setup_riak.escript b/tools/setup_riak.escript index ebb7162b6e..3b8ac1baf8 100755 --- a/tools/setup_riak.escript +++ b/tools/setup_riak.escript @@ -4,6 +4,7 @@ -ifdef(OTP_RELEASE). -define(STACKTRACE(C, R, S), C:R:S ->). -else. +%% This script runs inside michalwski/docker-riak, which still uses OTP 20.3 -define(STACKTRACE(C, R, S), C:R -> S = erlang:get_stacktrace(),). -endif. @@ -23,8 +24,6 @@ main(_) -> io:format("Riak node ~p~n", [RiakNode]), try setup_riak_node(RiakNode) catch ?STACKTRACE(Class, Reason, Stacktrace) - %% This script runs inside michalwski/docker-riak, which still uses OTP 20.3 - %Stacktrace = erlang:get_stacktrace(), io:format("Failed ~p:~p~n~p~n", [Class, Reason, Stacktrace]), init:stop(1) end,