From 0531509d0c9f2a510d3885bc28abf6621164955d Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Tue, 27 Aug 2013 17:43:45 -0700 Subject: fix specs --- spec/unit/plugins/linux/hostname_spec.rb | 75 +++++++++++++++++++++++++------- 1 file 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 -- cgit v1.2.1