Move router to epp_router

This commit is contained in:
Maciej Szlosarczyk 2019-05-27 11:08:18 +03:00
parent eac669cbd3
commit 7e6273091b
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765
6 changed files with 67 additions and 66 deletions

View file

@ -1,4 +1,4 @@
-module(pool_supervisor).
-module(epp_pool_supervisor).
-behaviour(supervisor).

View file

@ -1,4 +1,4 @@
-module(router).
-module(epp_router).
-export([route_request/1, is_valid_epp_command/1]).

View file

@ -10,7 +10,7 @@
-record(state,{socket, length, session_id}).
init(Socket) ->
logger:info("Created a test process"),
logger:info("Created a worker process"),
{ok, #state{socket=Socket}}.
start_link(Socket) ->
@ -20,12 +20,13 @@ handle_cast(serve, State = #state{socket=Socket}) ->
{noreply, State#state{socket=Socket}};
handle_cast(greeting, State = #state{socket=Socket}) ->
SessionId = session_id(),
Cookie = hackney_cookie:setcookie("session", SessionId, []),
{Status, StatusCode, Headers, ClientRef} =
hackney:request(get, router:route_request("hello"), [], "",
[{cookie, [<<"session=">>, SessionId]}, insecure]),
{_Status, _StatusCode, _Headers, ClientRef} =
hackney:request(get, epp_router:route_request("hello"), [], "",
[{cookie, Cookie}, insecure]),
Body = <<"Some BODY">>,
{ok, Body} = hackney:body(ClientRef),
Length = byte_size(Body) + 4,
ByteSize = << Length:32/big >>,
@ -33,7 +34,7 @@ handle_cast(greeting, State = #state{socket=Socket}) ->
write_line(Socket, ByteSize),
write_line(Socket, Body),
gen_server:cast(self(), read_length),
{noreply, State#state{socket=Socket}};
{noreply, State#state{socket=Socket, session_id=SessionId}};
handle_cast(read_length, State = #state{socket=Socket}) ->
case read_length(Socket) of
{ok, Data} ->

View file

@ -1,4 +1,4 @@
-module(router_SUITE).
-module(epp_router_SUITE).
-include_lib("common_test/include/ct.hrl").
@ -9,4 +9,4 @@ all() -> [run_eunit].
%% Run Unit tests
run_eunit(_Config) ->
ok = eunit:test(router_tests).
ok = eunit:test(epp_router_tests).

View file

@ -0,0 +1,56 @@
-module(epp_router_tests).
-include_lib("eunit/include/eunit.hrl").
is_valid_epp_command_test() ->
Commands = ["hello", "login", "logout", "check", "info", "poll",
"create", "delete", "renew", "update", "transfer"],
lists:foreach(fun (N) ->
?assert(epp_router:is_valid_epp_command(N))
end,
Commands).
%% TODO: Make less verbose and repetitive
hello_url_test() ->
?assertEqual("https://registry.test/epp/session/hello", epp_router:route_request("hello")),
?assertEqual("https://registry.test/epp/session/hello", epp_router:route_request(<<"hello">>)).
login_url_test() ->
?assertEqual("https://registry.test/epp/session/login", epp_router:route_request("login")),
?assertEqual("https://registry.test/epp/session/login", epp_router:route_request(<<"login">>)).
logout_url_test() ->
?assertEqual("https://registry.test/epp/session/logout", epp_router:route_request("logout")),
?assertEqual("https://registry.test/epp/session/logout", epp_router:route_request(<<"logout">>)).
check_url_test() ->
?assertEqual("https://registry.test/epp/command/check", epp_router:route_request("check")),
?assertEqual("https://registry.test/epp/command/check", epp_router:route_request(<<"check">>)).
info_url_test() ->
?assertEqual("https://registry.test/epp/command/info", epp_router:route_request("info")),
?assertEqual("https://registry.test/epp/command/info", epp_router:route_request(<<"info">>)).
poll_url_test() ->
?assertEqual("https://registry.test/epp/command/poll", epp_router:route_request("poll")),
?assertEqual("https://registry.test/epp/command/poll", epp_router:route_request(<<"poll">>)).
create_url_test() ->
?assertEqual("https://registry.test/epp/command/create", epp_router:route_request("create")),
?assertEqual("https://registry.test/epp/command/create", epp_router:route_request(<<"create">>)).
delete_url_test() ->
?assertEqual("https://registry.test/epp/command/delete", epp_router:route_request("delete")),
?assertEqual("https://registry.test/epp/command/delete", epp_router:route_request(<<"delete">>)).
renew_url_test() ->
?assertEqual("https://registry.test/epp/command/renew", epp_router:route_request("renew")),
?assertEqual("https://registry.test/epp/command/renew", epp_router:route_request(<<"renew">>)).
update_url_test() ->
?assertEqual("https://registry.test/epp/command/update", epp_router:route_request("update")),
?assertEqual("https://registry.test/epp/command/update", epp_router:route_request(<<"update">>)).
transfer_url_test() ->
?assertEqual("https://registry.test/epp/command/transfer", epp_router:route_request("transfer")),
?assertEqual("https://registry.test/epp/command/transfer", epp_router:route_request(<<"transfer">>)).

View file

@ -1,56 +0,0 @@
-module(router_tests).
-include_lib("eunit/include/eunit.hrl").
is_valid_epp_command_test() ->
Commands = ["hello", "login", "logout", "check", "info", "poll",
"create", "delete", "renew", "update", "transfer"],
lists:foreach(fun (N) ->
?assert(router:is_valid_epp_command(N))
end,
Commands).
%% TODO: Make less verbose and repetitive
hello_url_test() ->
?assertEqual("https://registry.test/epp/session/hello", router:route_request("hello")),
?assertEqual("https://registry.test/epp/session/hello", router:route_request(<<"hello">>)).
login_url_test() ->
?assertEqual("https://registry.test/epp/session/login", router:route_request("login")),
?assertEqual("https://registry.test/epp/session/login", router:route_request(<<"login">>)).
logout_url_test() ->
?assertEqual("https://registry.test/epp/session/logout", router:route_request("logout")),
?assertEqual("https://registry.test/epp/session/logout", router:route_request(<<"logout">>)).
check_url_test() ->
?assertEqual("https://registry.test/epp/command/check", router:route_request("check")),
?assertEqual("https://registry.test/epp/command/check", router:route_request(<<"check">>)).
info_url_test() ->
?assertEqual("https://registry.test/epp/command/info", router:route_request("info")),
?assertEqual("https://registry.test/epp/command/info", router:route_request(<<"info">>)).
poll_url_test() ->
?assertEqual("https://registry.test/epp/command/poll", router:route_request("poll")),
?assertEqual("https://registry.test/epp/command/poll", router:route_request(<<"poll">>)).
create_url_test() ->
?assertEqual("https://registry.test/epp/command/create", router:route_request("create")),
?assertEqual("https://registry.test/epp/command/create", router:route_request(<<"create">>)).
delete_url_test() ->
?assertEqual("https://registry.test/epp/command/delete", router:route_request("delete")),
?assertEqual("https://registry.test/epp/command/delete", router:route_request(<<"delete">>)).
renew_url_test() ->
?assertEqual("https://registry.test/epp/command/renew", router:route_request("renew")),
?assertEqual("https://registry.test/epp/command/renew", router:route_request(<<"renew">>)).
update_url_test() ->
?assertEqual("https://registry.test/epp/command/update", router:route_request("update")),
?assertEqual("https://registry.test/epp/command/update", router:route_request(<<"update">>)).
transfer_url_test() ->
?assertEqual("https://registry.test/epp/command/transfer", router:route_request("transfer")),
?assertEqual("https://registry.test/epp/command/transfer", router:route_request(<<"transfer">>)).