summaryrefslogtreecommitdiff
path: root/spec/unit/plugins/hostname_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/plugins/hostname_spec.rb')
-rw-r--r--spec/unit/plugins/hostname_spec.rb50
1 files changed, 24 insertions, 26 deletions
diff --git a/spec/unit/plugins/hostname_spec.rb b/spec/unit/plugins/hostname_spec.rb
index 9819c42f..9c975fe7 100644
--- a/spec/unit/plugins/hostname_spec.rb
+++ b/spec/unit/plugins/hostname_spec.rb
@@ -25,35 +25,37 @@ describe Ohai::System, "hostname plugin" do
allow(@plugin).to receive(:shell_out).with("hostname").and_return(mock_shell_out(0, "katie.local", ""))
end
- context "default behavior"
- before do
- allow(@plugin).to receive(:resolve_fqdn).and_return("katie.bethell")
- end
+ context "default behavior" do
+ before do
+ allow(@plugin).to receive(:canonicalize_hostname).with("katie.local").and_return("katie.bethell")
+ end
- it_should_check_from("linux::hostname", "machinename", "hostname", "katie.local")
+ it_should_check_from("linux::hostname", "machinename", "hostname", "katie.local")
- it "uses #resolve_fqdn to find the fqdn" do
- @plugin.run
- expect(@plugin[:fqdn]).to eq("katie.bethell")
- end
+ it "uses #resolve_fqdn to find the fqdn" do
+ @plugin.run
+ expect(@plugin[:fqdn]).to eq("katie.bethell")
+ end
- it "sets the domain to everything after the first dot of the fqdn" do
- @plugin.run
- expect(@plugin[:domain]).to eq("bethell")
- end
+ it "sets the domain to everything after the first dot of the fqdn" do
+ @plugin.run
+ expect(@plugin[:domain]).to eq("bethell")
+ end
- it "sets the [short] hostname to everything before the first dot of the fqdn" do
- @plugin.run
- expect(@plugin[:hostname]).to eq("katie")
+ it "sets the [short] hostname to everything before the first dot of the fqdn" do
+ @plugin.run
+ expect(@plugin[:hostname]).to eq("katie")
+ end
end
context "when a system has a bare hostname without a FQDN" do
before do
allow(@plugin).to receive(:collect_os).and_return(:default)
allow(@plugin).to receive(:shell_out).with("hostname").and_return(mock_shell_out(0, "katie", ""))
+ allow(@plugin).to receive(:canonicalize_hostname).with("katie").and_return("katie.bethell")
end
- it "correctlies set the [short] hostname" do
+ it "correctly sets the [short] hostname" do
@plugin.run
expect(@plugin[:hostname]).to eq("katie")
end
@@ -65,14 +67,12 @@ describe Ohai::System, "hostname plugin" do
allow(@plugin).to receive(:shell_out).with("hostname -s").and_return(
mock_shell_out(0, "katie", "")
)
- allow(@plugin).to receive(:shell_out).with("hostname --fqdn").and_return(
- mock_shell_out(0, "", ""), mock_shell_out(0, "katie.local", "")
- )
+ expect(@plugin).to receive(:canonicalize_hostname).with("katie.local").at_least(:once).and_raise(RuntimeError)
end
it "is called twice" do
@plugin.run
- expect(@plugin[:fqdn]).to eq("katie.local")
+ expect(@plugin[:fqdn]).to eq(nil)
end
end
@@ -82,9 +82,7 @@ describe Ohai::System, "hostname plugin" do
allow(@plugin).to receive(:shell_out).with("hostname -s").and_return(
mock_shell_out(0, "katie", "")
)
- allow(@plugin).to receive(:shell_out).with("hostname --fqdn").and_return(
- mock_shell_out(0, "katie.local", "")
- )
+ expect(@plugin).to receive(:canonicalize_hostname).with("katie.local").and_return("katie.local")
end
it "is not be called twice" do
@@ -144,7 +142,7 @@ describe Ohai::System, "hostname plugin for windows", :windows_only do
context "when hostname is not set for the machine" do
it "returns short machine name" do
- allow(Socket).to receive(:gethostbyaddr).with(anything).and_return(local_hostent)
+ expect(@plugin).to receive(:canonicalize_hostname).with(anything).and_return("local")
@plugin.run
expect(@plugin[:fqdn]).to eq("local")
end
@@ -152,7 +150,7 @@ describe Ohai::System, "hostname plugin for windows", :windows_only do
context "when hostname is set for the machine" do
it "returns the fqdn of the machine" do
- allow(Socket).to receive(:gethostbyaddr).with(anything).and_return(fqdn_hostent)
+ expect(@plugin).to receive(:canonicalize_hostname).with(anything).and_return("local.dx.internal.cloudapp.net")
@plugin.run
expect(@plugin[:fqdn]).to eq("local.dx.internal.cloudapp.net")
end