summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2013-08-27 17:43:45 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2013-08-27 17:43:45 -0700
commit0531509d0c9f2a510d3885bc28abf6621164955d (patch)
tree8c417b20855da44a4273acc5ae1b4e72e65de518
parentcfe1bfc51893ca6f5c654ebe91794a7d6b61d944 (diff)
downloadohai-hostname-rage.tar.gz
fix specshostname-rage
-rw-r--r--spec/unit/plugins/linux/hostname_spec.rb75
1 files changed, 59 insertions, 16 deletions
diff --git a/spec/unit/plugins/linux/hostname_spec.rb b/spec/unit/plugins/linux/hostname_spec.rb
index b11b104b..9eab2a27 100644
--- a/spec/unit/plugins/linux/hostname_spec.rb
+++ b/spec/unit/plugins/linux/hostname_spec.rb
@@ -6,9 +6,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,29 +23,72 @@ describe Ohai::System, "Linux hostname plugin" do
before(:each) do
@plugin = get_plugin("linux/hostname")
@plugin[:os] = "linux"
- @plugin.stub(:from).with("hostname -s").and_return("katie")
- @plugin.stub(:from).with("hostname --fqdn").and_return("katie.bethell")
end
- it_should_check_from("linux::hostname", "hostname", "hostname -s", "katie")
-
- it_should_check_from("linux::hostname", "fqdn", "hostname --fqdn", "katie.bethell")
-
- describe "when domain name is unset" do
+ describe "when the hostname is an FQDN" do
before(:each) do
- @plugin.should_receive(:from).with("hostname --fqdn").and_raise("Ohai::Exception::Exec")
+ @plugin.stub(:from).with("hostname").and_return("katie.bethell")
+ @plugin.stub(:from).with("hostname -s").and_return("katie")
+ end
+
+ describe "when hostname -f resolves" do
+ before(:each) do
+ @plugin.stub(:from).with("hostname --fqdn").and_return("katie.bethell")
+ end
+ it "should not raise an error" do
+ lambda { @plugin.run }.should_not raise_error
+ end
+ it "should set fqdn to the result of hostname -f" do
+ @plugin.run
+ @plugin.fqdn.should == "katie.bethell"
+ end
+ it "should set fqdn to the long name" do
+ @plugin.run
+ @plugin.fqdn.should == "katie.bethell"
+ end
end
- it "should not raise an error" do
- lambda { @plugin.run }.should_not raise_error
+ describe "when hostname -f raises an error" do
+ before(:each) do
+ @plugin.stub(:from).with("hostname --fqdn").and_raise("Ohai::Exception::Exec")
+ end
+ it "should not raise an error" do
+ lambda { @plugin.run }.should_not raise_error
+ end
end
+ end
- it "should not set fqdn" do
- @plugin.run
- @plugin.fqdn.should == nil
+ describe "when the hostname is short" do
+ before(:each) do
+ @plugin.stub(:from).with("hostname").and_return("katie")
+ @plugin.stub(:from).with("hostname -s").and_return("katie")
+ end
+ describe "when hostname -f resolves" do
+ before(:each) do
+ @plugin.stub(:from).with("hostname --fqdn").and_return("katie.bethell")
+ end
+ it "should not raise an error" do
+ lambda { @plugin.run }.should_not raise_error
+ end
+ it "should set fqdn to the result of hostname -f" do
+ @plugin.run
+ @plugin.fqdn.should == "katie.bethell"
+ end
end
+ describe "when hostname -f raises an error" do
+ before(:each) do
+ @plugin.stub(:from).with("hostname --fqdn").and_raise("Ohai::Exception::Exec")
+ end
+ it "should not raise an error" do
+ lambda { @plugin.run }.should_not raise_error
+ end
+ it "should set fqdn to the short name" do
+ @plugin.run
+ @plugin.fqdn.should == "katie"
+ end
+ end
end
-
+
end