Fix test for @hostname case

This commit is contained in:
Luke Bakken 2018-11-30 12:27:58 -08:00
parent 35ffd53be1
commit ff6243bfd2
2 changed files with 11 additions and 4 deletions

View File

@ -30,9 +30,15 @@ defmodule RabbitMQ.CLI.Core.Helpers do
end
def normalise_node(name) do
case String.split(name, "@", parts: 2) do
[_,""] -> name <> "#{hostname()}" |> String.to_atom
[_,_] -> name |> String.to_atom
[_] -> name <> "@#{hostname()}" |> String.to_atom
[_,""] ->
name <> "#{hostname()}" |> String.to_atom
["",hostname] ->
default_name = to_string(Config.get_option(:node))
default_name <> "@#{hostname}" |> String.to_atom
[_,_] ->
name |> String.to_atom
[_] ->
name <> "@#{hostname()}" |> String.to_atom
end
end

View File

@ -92,7 +92,8 @@ defmodule HelpersTest do
end
test "if input is a hostname without a node name, default node name is added" do
want = String.to_atom("rabbit_test@#{hostname()}")
default_name = RabbitMQ.CLI.Core.Config.get_option(:node)
want = String.to_atom("#{default_name}@#{hostname()}")
got = @subject.normalise_node("@#{hostname()}")
assert want == got
end