Skip to content

Commit

Permalink
Reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
cottinisimone committed Sep 27, 2024
1 parent c78db6b commit 3bb88f3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 7 additions & 3 deletions lib/amqp/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule Amqpx.Connection do
username: "guest",
password: "guest",
virtual_host: "/",
host: 'localhost',
host: ~c"localhost",
port: 5672,
channel_max: 0,
frame_max: 0,
Expand Down Expand Up @@ -210,7 +210,9 @@ defmodule Amqpx.Connection do
{:ok, pid} ->
IO.inspect("Connection opened to: #{ip}")

Check warning on line 211 in lib/amqp/connection.ex

View workflow job for this annotation

GitHub Actions / ci

There should be no calls to `IO.inspect/1`.
{:halt, {:ok, %Connection{pid: pid}}}
error -> {:cont, error}

error ->
{:cont, error}
end
end)
end
Expand All @@ -233,7 +235,9 @@ defmodule Amqpx.Connection do
case :inet.gethostbyname(host) do
{:ok, {:hostent, _, _, _, _, ips}} ->
ips |> Enum.map(&:inet.ntoa/1) |> Enum.dedup()
_ -> [host]

_ ->
[host]
end
end
end
14 changes: 7 additions & 7 deletions test/connection_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule ConnectionTest do
Connection.open(
username: "amqpx",
password: "amqpx",
host: 'rabbit',
host: ~c"rabbit",
obfuscate_password: @obfuscate_password
)

Expand All @@ -38,7 +38,7 @@ defmodule ConnectionTest do
test "open connection using both uri and options" do
assert {:ok, conn} =
Connection.open("amqp://amqpx:amqpx@nonexistent:5672",
host: 'rabbit',
host: ~c"rabbit",
obfuscate_password: @obfuscate_password
)

Expand All @@ -48,7 +48,7 @@ defmodule ConnectionTest do
test "open connection with uri, name, and options" do
assert {:ok, conn} =
Connection.open("amqp://amqpx:amqpx@nonexistent:5672", "my-connection",
host: 'rabbit',
host: ~c"rabbit",
obfuscate_password: @obfuscate_password
)

Expand All @@ -66,21 +66,21 @@ defmodule ConnectionTest do

assert params[:username] == "amqpx"
assert params[:password] == "amqpx"
assert params[:host] == 'rabbit'
assert params[:host] == ~c"rabbit"
end

describe "ip resolution" do
test "localhost is resolved as 127.0.0.1" do
assert ['127.0.0.1'] = Connection.resolve_ips('localhost')
assert [~c"127.0.0.1"] = Connection.resolve_ips(~c"localhost")
end

test "rabbit can be resolved into an ip" do
assert [ip] = Connection.resolve_ips('rabbit')
assert [ip] = Connection.resolve_ips(~c"rabbit")
assert {:ok, _} = :inet.parse_address(ip)
end

test "unknown host will not be resolved" do
assert ['nonexistent'] = Connection.resolve_ips('nonexistent')
assert [~c"nonexistent"] = Connection.resolve_ips(~c"nonexistent")
end
end
end

0 comments on commit 3bb88f3

Please sign in to comment.