diff options
author | dcorbacho <dparracorbacho@piotal.io> | 2020-11-18 14:27:41 +0000 |
---|---|---|
committer | dcorbacho <dparracorbacho@piotal.io> | 2020-11-18 14:27:41 +0000 |
commit | f23a51261d9502ec39df0f8db47ba6b22aa7659f (patch) | |
tree | 53dcdf46e7dc2c14e81ee960bce8793879b488d3 /deps/rabbitmq_cli/test/core/node_name_test.exs | |
parent | afa2c2bf6c7e0e9b63f4fb53dc931c70388e1c82 (diff) | |
parent | 9f6d64ec4a4b1eeac24d7846c5c64fd96798d892 (diff) | |
download | rabbitmq-server-git-f23a51261d9502ec39df0f8db47ba6b22aa7659f.tar.gz |
Merge remote-tracking branch 'origin/master' into stream-timestamp-offsetstream-timestamp-offset
Diffstat (limited to 'deps/rabbitmq_cli/test/core/node_name_test.exs')
-rw-r--r-- | deps/rabbitmq_cli/test/core/node_name_test.exs | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/deps/rabbitmq_cli/test/core/node_name_test.exs b/deps/rabbitmq_cli/test/core/node_name_test.exs new file mode 100644 index 0000000000..89bc1484bc --- /dev/null +++ b/deps/rabbitmq_cli/test/core/node_name_test.exs @@ -0,0 +1,73 @@ +## This Source Code Form is subject to the terms of the Mozilla Public +## License, v. 2.0. If a copy of the MPL was not distributed with this +## file, You can obtain one at https://mozilla.org/MPL/2.0/. +## +## Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved. + +defmodule NodeNameTest do + use ExUnit.Case, async: true + + @subject RabbitMQ.CLI.Core.NodeName + + test "shortnames: RabbitMQ nodename is properly formed from atom" do + want = String.to_atom("rabbit@#{:inet_db.gethostname()}") + {:ok, got} = @subject.create(:rabbit, :shortnames) + assert want == got + end + + test "shortnames: RabbitMQ nodename is properly formed from string" do + want = String.to_atom("rabbit@#{:inet_db.gethostname()}") + {:ok, got} = @subject.create("rabbit", :shortnames) + assert want == got + end + + test "shortnames: RabbitMQ nodename is properly formed with trailing @" do + want = String.to_atom("rabbit@#{:inet_db.gethostname()}") + {:ok, got} = @subject.create(:rabbit@, :shortnames) + assert want == got + end + + test "shortnames: RabbitMQ nodename is properly formed with host part" do + want = :rabbit@foofoo + {:ok, got} = @subject.create(want, :shortnames) + assert want == got + end + + test "shortnames: nodename head only supports alphanumerics, underscores and hyphens in name head" do + {:error, {:node_name, :invalid_node_name_head}} = @subject.create("кириллица", :shortnames) + end + + test "longnames: RabbitMQ nodename is properly formed from atom" do + {:ok, got} = @subject.create(:rabbit, :longnames) + assert Atom.to_string(got) =~ ~r/rabbit@[\w\-]+\.\w+/ + end + + test "longnames: RabbitMQ nodename is properly formed from string" do + {:ok, got} = @subject.create("rabbit", :longnames) + assert Atom.to_string(got) =~ ~r/rabbit@[\w\-]+\.\w+/ + end + + test "longnames: RabbitMQ nodename is properly formed from atom with domain" do + want = :"rabbit@localhost.localdomain" + {:ok, got} = @subject.create(want, :longnames) + assert want == got + end + + test "longnames: RabbitMQ nodename is properly formed from string with domain" do + name_str = "rabbit@localhost.localdomain" + want = String.to_atom(name_str) + {:ok, got} = @subject.create(name_str, :longnames) + assert want == got + end + + test "longnames: RabbitMQ nodename is properly formed from string with partial domain" do + name_str = "rabbit@localhost" + want = String.to_atom(name_str <> "." <> @subject.domain()) + {:ok, got} = @subject.create(name_str, :longnames) + assert want == got + end + + test "longnames: nodename head only supports alphanumerics, underscores and hyphens in name head" do + {:error, {:node_name, :invalid_node_name_head}} = @subject.create("кириллица", :longnames) + end +end |