Skip to content

Commit

Permalink
refactor!: send/3 becomes command/3
Browse files Browse the repository at this point in the history
To reflect that it does both send and receive.
  • Loading branch information
sntran committed Mar 2, 2021
1 parent 8ad00ec commit 94b0820
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/gen_nntp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule GenNNTP do
@doc """
Sends a command and receives server's response.
"""
defdelegate send(socket, command, args \\ []), to: :gen_nntp
defdelegate command(socket, command, args \\ []), to: :gen_nntp

@callback init(any()) ::
{:ok, state} | {:ok, state, timeout | :hibernate} |
Expand Down
10 changes: 5 additions & 5 deletions src/gen_nntp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
connect/1,
connect/2,
connect/3,
send/2,
send/3
command/2,
command/3
]).

%% gen_server callbacks
Expand Down Expand Up @@ -136,10 +136,10 @@ connect(Address, Port, _Options) ->
%% The function will also wait for the response from server.
%% @end
%%-------------------------------------------------------------------
send(Socket, Commamd) ->
send(Socket, Commamd, []).
command(Socket, Commamd) ->
command(Socket, Commamd, []).

send(Socket, Command, _Args) when is_binary(Command) ->
command(Socket, Command, _Args) when is_binary(Command) ->
ok = gen_tcp:send(Socket, <<Command/binary, "\r\n">>),
gen_tcp:recv(Socket, 0, 1000).

Expand Down
8 changes: 4 additions & 4 deletions test/gen_nntp_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ defmodule GenNNTPTest do

end

describe "send/3" do
describe "command/3" do

setup do
GenNNTP.start(TestNNTPServer, [], [])
Expand All @@ -85,12 +85,12 @@ defmodule GenNNTPTest do
end

test "sends QUIT command", %{socket: socket} do
assert {:ok, response} = GenNNTP.send(socket, "QUIT", [])
assert {:ok, response} = GenNNTP.command(socket, "QUIT", [])
assert response =~ ~r/^205 /
end

test "send/2 default to empty arguments", %{socket: socket} do
assert {:ok, response} = GenNNTP.send(socket, "QUIT")
test "command/2 default to empty arguments", %{socket: socket} do
assert {:ok, response} = GenNNTP.command(socket, "QUIT")
assert response =~ ~r/^205 /
end

Expand Down

0 comments on commit 94b0820

Please sign in to comment.