diff options
author | Adam Jacob <adam@hjksolutions.com> | 2009-01-06 16:00:11 -0800 |
---|---|---|
committer | Adam Jacob <adam@hjksolutions.com> | 2009-01-06 16:00:11 -0800 |
commit | fef7342c034a680c3c8ee90d388bf6a345d1d4e7 (patch) | |
tree | 4c897a8e09041268fff3ed1be3396e6180a46930 | |
parent | 353d44156869a4f6eace20317a11bc4d5a82d4c1 (diff) | |
download | ohai-fef7342c034a680c3c8ee90d388bf6a345d1d4e7.tar.gz |
Updating specs for ohai to reflect streamlined plugin architecture, added rcov support
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | lib/ohai/plugins/linux/kernel.rb | 4 | ||||
-rw-r--r-- | spec/ohai/plugins/cpu_spec.rb | 138 | ||||
-rw-r--r-- | spec/ohai/plugins/darwin/hostname_spec.rb | 34 | ||||
-rw-r--r-- | spec/ohai/plugins/darwin/kernel_spec.rb | 34 | ||||
-rw-r--r-- | spec/ohai/plugins/darwin/platform_spec.rb | 67 | ||||
-rw-r--r-- | spec/ohai/plugins/hostname_spec.rb | 39 | ||||
-rw-r--r-- | spec/ohai/plugins/kernel_spec.rb | 16 | ||||
-rw-r--r-- | spec/ohai/plugins/linux/cpu_spec.rb | 128 | ||||
-rw-r--r-- | spec/ohai/plugins/linux/hostname_spec.rb | 34 | ||||
-rw-r--r-- | spec/ohai/plugins/linux/kernel_spec.rb | 30 | ||||
-rw-r--r-- | spec/ohai/plugins/linux/lsb_spec.rb (renamed from spec/ohai/plugins/lsb_spec.rb) | 12 | ||||
-rw-r--r-- | spec/ohai/plugins/linux/platform_spec.rb | 50 | ||||
-rw-r--r-- | spec/ohai/plugins/linux/uptime_spec.rb | 61 | ||||
-rw-r--r-- | spec/ohai/plugins/memory_spec.rb | 62 | ||||
-rw-r--r-- | spec/ohai/plugins/platform_spec.rb | 102 | ||||
-rw-r--r-- | spec/ohai/plugins/uptime_spec.rb | 70 | ||||
-rw-r--r-- | spec/rcov.opts | 2 | ||||
-rw-r--r-- | tasks/rspec.rake | 21 |
19 files changed, 492 insertions, 413 deletions
@@ -1,2 +1,3 @@ pkg/ tmp/ +coverage/ diff --git a/lib/ohai/plugins/linux/kernel.rb b/lib/ohai/plugins/linux/kernel.rb index adfd3556..fa901f91 100644 --- a/lib/ohai/plugins/linux/kernel.rb +++ b/lib/ohai/plugins/linux/kernel.rb @@ -16,8 +16,4 @@ # limitations under the License. # -kernel_name from("uname -s") -kernel_release from("uname -r") -kernel_version from("uname -v") -kernel_machine from("uname -m") kernel_os from("uname -o") diff --git a/spec/ohai/plugins/cpu_spec.rb b/spec/ohai/plugins/cpu_spec.rb deleted file mode 100644 index 4bf56391..00000000 --- a/spec/ohai/plugins/cpu_spec.rb +++ /dev/null @@ -1,138 +0,0 @@ -# -# Author:: Adam Jacob (<adam@opscode.com>) -# Copyright:: Copyright (c) 2008 OpsCode, Inc. -# License:: Apache License, Version 2.0 -# -# 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. -# See the License for the specific language governing permissions and -# limitations under the License. -# - - -require File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb') - -describe Ohai::System, "plugin cpu" do - before(:each) do - @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) - end - - it "should require the os plugin" do - @ohai.should_receive(:require_plugin).with("os").and_return(true) - @ohai._require_plugin("uptime") - end - - describe "on linux" do - before(:each) do - @ohai[:os] = "linux" - @mock_file = mock("/proc/cpuinfo") - @mock_file.stub!(:each). - and_yield("processor : 0"). - and_yield("vendor_id : GenuineIntel"). - and_yield("cpu family : 6"). - and_yield("model : 23"). - and_yield("model name : Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz"). - and_yield("stepping : 6"). - and_yield("cpu MHz : 1968.770"). - and_yield("cache size : 64 KB"). - and_yield("fdiv_bug : no"). - and_yield("hlt_bug : no"). - and_yield("f00f_bug : no"). - and_yield("coma_bug : no"). - and_yield("fpu : yes"). - and_yield("fpu_exception : yes"). - and_yield("cpuid level : 10"). - and_yield("wp : yes"). - and_yield("flags : fpu pse tsc msr mce cx8 sep mtrr pge cmov"). - and_yield("bogomips : 2575.86"). - and_yield("clflush size : 32") - File.stub!(:open).with("/proc/cpuinfo").and_return(@mock_file) - end - - it "should set cpu_total to 1" do - @ohai._require_plugin("cpu") - @ohai[:cpu_total].should == 1 - end - - it "should set cpu_real to 0" do - @ohai._require_plugin("cpu") - @ohai[:cpu_real].should == 0 - end - - it "should have a cpu 0" do - @ohai._require_plugin("cpu") - @ohai[:cpu].should have_key("0") - end - - it "should have a vendor_id for cpu 0" do - @ohai._require_plugin("cpu") - @ohai[:cpu]["0"].should have_key("vendor_id") - @ohai[:cpu]["0"]["vendor_id"].should eql("GenuineIntel") - end - - it "should have a family for cpu 0" do - @ohai._require_plugin("cpu") - @ohai[:cpu]["0"].should have_key("family") - @ohai[:cpu]["0"]["family"].should eql("6") - end - - it "should have a model for cpu 0" do - @ohai._require_plugin("cpu") - @ohai[:cpu]["0"].should have_key("model") - @ohai[:cpu]["0"]["model"].should eql("23") - end - - it "should have a stepping for cpu 0" do - @ohai._require_plugin("cpu") - @ohai[:cpu]["0"].should have_key("stepping") - @ohai[:cpu]["0"]["stepping"].should eql("6") - end - - it "should not have a phyiscal_id for cpu 0" do - @ohai._require_plugin("cpu") - @ohai[:cpu]["0"].should_not have_key("physical_id") - end - - it "should not have a core_id for cpu 0" do - @ohai._require_plugin("cpu") - @ohai[:cpu]["0"].should_not have_key("core_id") - end - - it "should not have a cores for cpu 0" do - @ohai._require_plugin("cpu") - @ohai[:cpu]["0"].should_not have_key("cores") - end - - it "should have a model name for cpu 0" do - @ohai._require_plugin("cpu") - @ohai[:cpu]["0"].should have_key("model_name") - @ohai[:cpu]["0"]["model_name"].should eql("Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz") - end - - it "should have a mhz for cpu 0" do - @ohai._require_plugin("cpu") - @ohai[:cpu]["0"].should have_key("mhz") - @ohai[:cpu]["0"]["mhz"].should eql("1968.770") - end - - it "should have a cache_size for cpu 0" do - @ohai._require_plugin("cpu") - @ohai[:cpu]["0"].should have_key("cache_size") - @ohai[:cpu]["0"]["cache_size"].should eql("64 KB") - end - - it "should have flags for cpu 0" do - @ohai._require_plugin("cpu") - @ohai[:cpu]["0"].should have_key("flags") - @ohai[:cpu]["0"]["flags"].should == %w{fpu pse tsc msr mce cx8 sep mtrr pge cmov} - end - end -end
\ No newline at end of file diff --git a/spec/ohai/plugins/darwin/hostname_spec.rb b/spec/ohai/plugins/darwin/hostname_spec.rb new file mode 100644 index 00000000..743cb744 --- /dev/null +++ b/spec/ohai/plugins/darwin/hostname_spec.rb @@ -0,0 +1,34 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 OpsCode, Inc. +# License:: Apache License, Version 2.0 +# +# 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. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +require File.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb') + +describe Ohai::System, "Darwin hostname plugin" do + before(:each) do + @ohai = Ohai::System.new + @ohai.stub!(:require_plugin).and_return(true) + @ohai[:os] = "darwin" + @ohai.stub!(:from).with("hostname -s").and_return("katie") + @ohai.stub!(:from).with("hostname").and_return("katie.bethell") + end + + it_should_check_from("darwin::hostname", "hostname", "hostname -s", "katie") + + it_should_check_from("darwin::hostname", "fqdn", "hostname", "katie.bethell") +end
\ No newline at end of file diff --git a/spec/ohai/plugins/darwin/kernel_spec.rb b/spec/ohai/plugins/darwin/kernel_spec.rb new file mode 100644 index 00000000..b8d15985 --- /dev/null +++ b/spec/ohai/plugins/darwin/kernel_spec.rb @@ -0,0 +1,34 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 OpsCode, Inc. +# License:: Apache License, Version 2.0 +# +# 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. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +require File.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb') + +describe Ohai::System, "Darwin kernel plugin" do + before(:each) do + @ohai = Ohai::System.new + @ohai.stub!(:require_plugin).and_return(true) + @ohai[:kernel_name] = "darwin" + end + + it "should set the kernel_os to the kernel_name value" do + @ohai._require_plugin("darwin::kernel") + @ohai[:kernel_os].should == @ohai[:kernel_name] + end + +end
\ No newline at end of file diff --git a/spec/ohai/plugins/darwin/platform_spec.rb b/spec/ohai/plugins/darwin/platform_spec.rb new file mode 100644 index 00000000..ffb9e95a --- /dev/null +++ b/spec/ohai/plugins/darwin/platform_spec.rb @@ -0,0 +1,67 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 OpsCode, Inc. +# License:: Apache License, Version 2.0 +# +# 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. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +require File.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb') + +describe Ohai::System, "Darwin plugin platform" do + before(:each) do + @ohai = Ohai::System.new + @ohai.stub!(:require_plugin).and_return(true) + @ohai[:os] = "darwin" + @pid = 10 + @stdin = mock("STDIN", { :close => true }) + @stdout = mock("STDOUT") + @stdout.stub!(:each). + and_yield("ProductName: Mac OS X"). + and_yield("ProductVersion: 10.5.5"). + and_yield("BuildVersion: 9F33") + @stderr = mock("STDERR") + @ohai.stub!(:popen4).with("sw_vers").and_yield(@pid, @stdin, @stdout, @stderr) + end + + it "should run sw_vers" do + @ohai.should_receive(:popen4).with("sw_vers").and_return(true) + @ohai._require_plugin("darwin::platform") + end + + it "should close sw_vers stdin" do + @stdin.should_receive(:close) + @ohai._require_plugin("darwin::platform") + end + + it "should iterate over each line of sw_vers stdout" do + @stdout.should_receive(:each).and_return(true) + @ohai._require_plugin("darwin::platform") + end + + it "should set platform to ProductName, downcased with _ for \\s" do + @ohai._require_plugin("darwin::platform") + @ohai[:platform].should == "mac_os_x" + end + + it "should set platform_version to ProductVersion" do + @ohai._require_plugin("darwin::platform") + @ohai[:platform_version].should == "10.5.5" + end + + it "should set platform_build to BuildVersion" do + @ohai._require_plugin("darwin::platform") + @ohai[:platform_build].should == "9F33" + end +end
\ No newline at end of file diff --git a/spec/ohai/plugins/hostname_spec.rb b/spec/ohai/plugins/hostname_spec.rb index 1bb03689..0b4aa0a7 100644 --- a/spec/ohai/plugins/hostname_spec.rb +++ b/spec/ohai/plugins/hostname_spec.rb @@ -19,44 +19,15 @@ require File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb') -describe Ohai::System, "plugin hostname" do +describe Ohai::System, "hostname plugin" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) + @ohai[:fqdn] = "katie.bethell" end - - it "should require the os plugin" do - @ohai.should_receive(:require_plugin).with("os").and_return(true) + + it "should set the domain to everything after the first dot of the fqdn" do @ohai._require_plugin("hostname") - end - - describe "on linux" do - before(:each) do - @ohai[:os] = "linux" - @ohai.stub!(:from).with("hostname").and_return("katie") - @ohai.stub!(:from).with("hostname --fqdn").and_return("katie.bethell") - end - - it_should_check_from("hostname", "hostname", "hostname", "katie") - - it_should_check_from("hostname", "fqdn", "hostname --fqdn", "katie.bethell") - - it "should set the domain to everything after the first dot of the fqdn" do - @ohai._require_plugin("hostname") - @ohai.domain.should == "bethell" - end - - end - - describe "on darwin" do - before(:each) do - @ohai[:os] = "darwin" - @ohai.stub!(:from).with("hostname -s").and_return("katie") - @ohai.stub!(:from).with("hostname").and_return("katie.bethell") - end - - it_should_check_from("hostname", "hostname", "hostname -s", "katie") - - it_should_check_from("hostname", "fqdn", "hostname", "katie.bethell") + @ohai.domain.should == "bethell" end end
\ No newline at end of file diff --git a/spec/ohai/plugins/kernel_spec.rb b/spec/ohai/plugins/kernel_spec.rb index 7095224c..af77ad5f 100644 --- a/spec/ohai/plugins/kernel_spec.rb +++ b/spec/ohai/plugins/kernel_spec.rb @@ -37,19 +37,5 @@ describe Ohai::System, "plugin kernel" do it_should_check_from("kernel", "kernel_version", "uname -v", "Darwin Kernel Version 9.5.0: Wed Sep 3 11:29:43 PDT 2008; root:xnu-1228.7.58~1\/RELEASE_I386") it_should_check_from("kernel", "kernel_machine", "uname -m", "i386") - - describe "on linux" do - before(:each) do - @ohai.stub!(:from).with("uname -s").and_return("Linux") - end - - it_should_check_from("kernel", "kernel_os", "uname -o", "Linux") - end - - describe "on darwin" do - it "should set the kernel_os to the kernel_name value" do - @ohai._require_plugin("kernel") - @ohai[:kernel_os].should == @ohai[:kernel_name] - end - end + end
\ No newline at end of file diff --git a/spec/ohai/plugins/linux/cpu_spec.rb b/spec/ohai/plugins/linux/cpu_spec.rb new file mode 100644 index 00000000..ef29ed4d --- /dev/null +++ b/spec/ohai/plugins/linux/cpu_spec.rb @@ -0,0 +1,128 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 OpsCode, Inc. +# License:: Apache License, Version 2.0 +# +# 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. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +require File.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb') + +describe Ohai::System, "Linux cpu plugin" do + before(:each) do + @ohai = Ohai::System.new + @ohai.stub!(:require_plugin).and_return(true) + @ohai[:os] = "linux" + @mock_file = mock("/proc/cpuinfo") + @mock_file.stub!(:each). + and_yield("processor : 0"). + and_yield("vendor_id : GenuineIntel"). + and_yield("cpu family : 6"). + and_yield("model : 23"). + and_yield("model name : Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz"). + and_yield("stepping : 6"). + and_yield("cpu MHz : 1968.770"). + and_yield("cache size : 64 KB"). + and_yield("fdiv_bug : no"). + and_yield("hlt_bug : no"). + and_yield("f00f_bug : no"). + and_yield("coma_bug : no"). + and_yield("fpu : yes"). + and_yield("fpu_exception : yes"). + and_yield("cpuid level : 10"). + and_yield("wp : yes"). + and_yield("flags : fpu pse tsc msr mce cx8 sep mtrr pge cmov"). + and_yield("bogomips : 2575.86"). + and_yield("clflush size : 32") + File.stub!(:open).with("/proc/cpuinfo").and_return(@mock_file) + end + + it "should set cpu_total to 1" do + @ohai._require_plugin("linux::cpu") + @ohai[:cpu_total].should == 1 + end + + it "should set cpu_real to 0" do + @ohai._require_plugin("linux::cpu") + @ohai[:cpu_real].should == 0 + end + + it "should have a cpu 0" do + @ohai._require_plugin("linux::cpu") + @ohai[:cpu].should have_key("0") + end + + it "should have a vendor_id for cpu 0" do + @ohai._require_plugin("linux::cpu") + @ohai[:cpu]["0"].should have_key("vendor_id") + @ohai[:cpu]["0"]["vendor_id"].should eql("GenuineIntel") + end + + it "should have a family for cpu 0" do + @ohai._require_plugin("linux::cpu") + @ohai[:cpu]["0"].should have_key("family") + @ohai[:cpu]["0"]["family"].should eql("6") + end + + it "should have a model for cpu 0" do + @ohai._require_plugin("linux::cpu") + @ohai[:cpu]["0"].should have_key("model") + @ohai[:cpu]["0"]["model"].should eql("23") + end + + it "should have a stepping for cpu 0" do + @ohai._require_plugin("linux::cpu") + @ohai[:cpu]["0"].should have_key("stepping") + @ohai[:cpu]["0"]["stepping"].should eql("6") + end + + it "should not have a phyiscal_id for cpu 0" do + @ohai._require_plugin("linux::cpu") + @ohai[:cpu]["0"].should_not have_key("physical_id") + end + + it "should not have a core_id for cpu 0" do + @ohai._require_plugin("linux::cpu") + @ohai[:cpu]["0"].should_not have_key("core_id") + end + + it "should not have a cores for cpu 0" do + @ohai._require_plugin("linux::cpu") + @ohai[:cpu]["0"].should_not have_key("cores") + end + + it "should have a model name for cpu 0" do + @ohai._require_plugin("linux::cpu") + @ohai[:cpu]["0"].should have_key("model_name") + @ohai[:cpu]["0"]["model_name"].should eql("Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz") + end + + it "should have a mhz for cpu 0" do + @ohai._require_plugin("linux::cpu") + @ohai[:cpu]["0"].should have_key("mhz") + @ohai[:cpu]["0"]["mhz"].should eql("1968.770") + end + + it "should have a cache_size for cpu 0" do + @ohai._require_plugin("linux::cpu") + @ohai[:cpu]["0"].should have_key("cache_size") + @ohai[:cpu]["0"]["cache_size"].should eql("64 KB") + end + + it "should have flags for cpu 0" do + @ohai._require_plugin("linux::cpu") + @ohai[:cpu]["0"].should have_key("flags") + @ohai[:cpu]["0"]["flags"].should == %w{fpu pse tsc msr mce cx8 sep mtrr pge cmov} + end +end
\ No newline at end of file diff --git a/spec/ohai/plugins/linux/hostname_spec.rb b/spec/ohai/plugins/linux/hostname_spec.rb new file mode 100644 index 00000000..fe441606 --- /dev/null +++ b/spec/ohai/plugins/linux/hostname_spec.rb @@ -0,0 +1,34 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 OpsCode, Inc. +# License:: Apache License, Version 2.0 +# +# 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. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +require File.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb') + +describe Ohai::System, "Linux hostname plugin" do + before(:each) do + @ohai = Ohai::System.new + @ohai.stub!(:require_plugin).and_return(true) + @ohai[:os] = "linux" + @ohai.stub!(:from).with("hostname").and_return("katie") + @ohai.stub!(:from).with("hostname --fqdn").and_return("katie.bethell") + end + + it_should_check_from("linux::hostname", "hostname", "hostname", "katie") + + it_should_check_from("linux::hostname", "fqdn", "hostname --fqdn", "katie.bethell") +end
\ No newline at end of file diff --git a/spec/ohai/plugins/linux/kernel_spec.rb b/spec/ohai/plugins/linux/kernel_spec.rb new file mode 100644 index 00000000..e6d44f04 --- /dev/null +++ b/spec/ohai/plugins/linux/kernel_spec.rb @@ -0,0 +1,30 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 OpsCode, Inc. +# License:: Apache License, Version 2.0 +# +# 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. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +require File.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb') + +describe Ohai::System, "Linux kernel plugin" do + before(:each) do + @ohai = Ohai::System.new + @ohai.stub!(:require_plugin).and_return(true) + @ohai.stub!(:from).with("uname -o").and_return("Linux") + end + + it_should_check_from("linux::kernel", "kernel_os", "uname -o", "Linux") +end
\ No newline at end of file diff --git a/spec/ohai/plugins/lsb_spec.rb b/spec/ohai/plugins/linux/lsb_spec.rb index 3da27b72..080b6889 100644 --- a/spec/ohai/plugins/lsb_spec.rb +++ b/spec/ohai/plugins/linux/lsb_spec.rb @@ -17,9 +17,9 @@ # -require File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb') +require File.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb') -describe Ohai::System, "plugin lsb" do +describe Ohai::System, "Linux lsb plugin" do before(:each) do @ohai = Ohai::System.new @ohai[:os] = "linux" @@ -33,22 +33,22 @@ describe Ohai::System, "plugin lsb" do end it "should set lsb_dist_id" do - @ohai._require_plugin("lsb") + @ohai._require_plugin("linux::lsb") @ohai[:lsb_dist_id] == "Ubuntu" end it "should set lsb_dist_release" do - @ohai._require_plugin("lsb") + @ohai._require_plugin("linux::lsb") @ohai[:lsb_dist_release] == "8.04" end it "should set lsb_dist_codename" do - @ohai._require_plugin("lsb") + @ohai._require_plugin("linux::lsb") @ohai[:lsb_dist_codename] == "hardy" end it "should set lsb dist description" do - @ohai._require_plugin("lsb") + @ohai._require_plugin("linux::lsb") @ohai[:lsb_dist_description] == "Ubuntu 8.04" end diff --git a/spec/ohai/plugins/linux/platform_spec.rb b/spec/ohai/plugins/linux/platform_spec.rb new file mode 100644 index 00000000..c822c80e --- /dev/null +++ b/spec/ohai/plugins/linux/platform_spec.rb @@ -0,0 +1,50 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 OpsCode, Inc. +# License:: Apache License, Version 2.0 +# +# 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. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +require File.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb') + +describe Ohai::System, "Linux plugin platform" do + before(:each) do + @ohai = Ohai::System.new + @ohai.stub!(:require_plugin).and_return(true) + @ohai[:os] = "linux" + end + + it "should require the lsb plugin" do + @ohai.should_receive(:require_plugin).with("linux::lsb").and_return(true) + @ohai._require_plugin("linux::platform") + end + + describe "on lsb compliant distributions" do + before(:each) do + @ohai[:lsb_dist_id] = "Ubuntu" + @ohai[:lsb_dist_release] = "8.04" + end + + it "should set platform to lowercased lsb_dist_id" do + @ohai._require_plugin("linux::platform") + @ohai[:platform].should == "ubuntu" + end + + it "should set platform_version to lsb_dist_release" do + @ohai._require_plugin("linux::platform") + @ohai[:platform_version].should == "8.04" + end + end +end diff --git a/spec/ohai/plugins/linux/uptime_spec.rb b/spec/ohai/plugins/linux/uptime_spec.rb new file mode 100644 index 00000000..21d3ed51 --- /dev/null +++ b/spec/ohai/plugins/linux/uptime_spec.rb @@ -0,0 +1,61 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 OpsCode, Inc. +# License:: Apache License, Version 2.0 +# +# 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. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +require File.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb') + +describe Ohai::System, "Linux plugin uptime" do + before(:each) do + @ohai = Ohai::System.new + @ohai.stub!(:require_plugin).and_return(true) + @ohai[:os] = "linux" + @ohai._require_plugin("uptime") + @mock_file = mock("/proc/uptime", { :gets => "18423 989" }) + File.stub!(:open).with("/proc/uptime").and_return(@mock_file) + end + + it "should check /proc/uptime for the uptime and idletime" do + File.should_receive(:open).with("/proc/uptime").and_return(@mock_file) + @ohai._require_plugin("linux::uptime") + end + + it "should split the value of /proc uptime" do + @mock_file.gets.should_receive(:split).with(" ").and_return(["18423", "989"]) + @ohai._require_plugin("linux::uptime") + end + + it "should set uptime_seconds to uptime" do + @ohai._require_plugin("linux::uptime") + @ohai[:uptime_seconds].should == 18423 + end + + it "should set uptime to a human readable date" do + @ohai._require_plugin("linux::uptime") + @ohai[:uptime].should == "5 hours 07 minutes 03 seconds" + end + + it "should set idletime_seconds to uptime" do + @ohai._require_plugin("linux::uptime") + @ohai[:idletime_seconds].should == 989 + end + + it "should set idletime to a human readable date" do + @ohai._require_plugin("linux::uptime") + @ohai[:idletime].should == "16 minutes 29 seconds" + end +end
\ No newline at end of file diff --git a/spec/ohai/plugins/memory_spec.rb b/spec/ohai/plugins/memory_spec.rb deleted file mode 100644 index 3da27b72..00000000 --- a/spec/ohai/plugins/memory_spec.rb +++ /dev/null @@ -1,62 +0,0 @@ -# -# Author:: Adam Jacob (<adam@opscode.com>) -# Copyright:: Copyright (c) 2008 OpsCode, Inc. -# License:: Apache License, Version 2.0 -# -# 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. -# See the License for the specific language governing permissions and -# limitations under the License. -# - - -require File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb') - -describe Ohai::System, "plugin lsb" do - before(:each) do - @ohai = Ohai::System.new - @ohai[:os] = "linux" - @ohai.stub!(:require_plugin).and_return(true) - @mock_file = mock("/etc/lsb-release") - @mock_file.stub!(:each). - and_yield("DISTRIB_ID=Ubuntu"). - and_yield("DISTRIB_RELEASE=8.04"). - and_yield("DISTRIB_CODENAME=hardy"). - and_yield('DISTRIB_DESCRIPTION="Ubuntu 8.04"') - end - - it "should set lsb_dist_id" do - @ohai._require_plugin("lsb") - @ohai[:lsb_dist_id] == "Ubuntu" - end - - it "should set lsb_dist_release" do - @ohai._require_plugin("lsb") - @ohai[:lsb_dist_release] == "8.04" - end - - it "should set lsb_dist_codename" do - @ohai._require_plugin("lsb") - @ohai[:lsb_dist_codename] == "hardy" - end - - it "should set lsb dist description" do - @ohai._require_plugin("lsb") - @ohai[:lsb_dist_description] == "Ubuntu 8.04" - end - - it "should not set any lsb values if /etc/lsb-release cannot be read" do - File.stub!(:open).with("/etc/lsb-release").and_raise(IOError) - @ohai.attribute?(:lsb_dist_id).should be(false) - @ohai.attribute?(:lsb_dist_release).should be(false) - @ohai.attribute?(:lsb_dist_codename).should be(false) - @ohai.attribute?(:lsb_dist_description).should be(false) - end -end
\ No newline at end of file diff --git a/spec/ohai/plugins/platform_spec.rb b/spec/ohai/plugins/platform_spec.rb index c588d56f..1be2dc15 100644 --- a/spec/ohai/plugins/platform_spec.rb +++ b/spec/ohai/plugins/platform_spec.rb @@ -23,98 +23,34 @@ describe Ohai::System, "plugin platform" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) + @ohai[:os] = 'monkey' + @ohai[:os_version] = 'poop' end - it "should require the os plugin" do - @ohai.should_receive(:require_plugin).with("os").and_return(true) + it "should require the os platform plugin" do + @ohai.should_receive(:require_plugin).with("monkey::platform") @ohai._require_plugin("platform") end - it "should require the lsb plugin" do - @ohai.should_receive(:require_plugin).with("lsb").and_return(true) + it "should set the platform to the os if it was not set earlier" do @ohai._require_plugin("platform") + @ohai[:platform].should eql("monkey") end - describe "on linux" do - before(:each) do - @ohai[:os] = "linux" - #File.stub!(:exists?).with("/etc/debian_version").and_return(false) - #File.stub!(:exists?).with("/etc/redhat-release").and_return(false) - end - - describe "on lsb compliant distributions" do - before(:each) do - @ohai[:lsb_dist_id] = "Ubuntu" - @ohai[:lsb_dist_release] = "8.04" - end - - it "should set platform to lowercased lsb_dist_id" do - @ohai._require_plugin("platform") - @ohai[:platform].should == "ubuntu" - end - - it "should set platform_version to lsb_dist_release" do - @ohai._require_plugin("platform") - @ohai[:platform_version].should == "8.04" - end - end - - # describe "on debian" do - # before(:each) do - # File.stub!(:exists?).and_return(true) - # end - # - # it "should set the platform to debian" do - # @ohai._require_plugin("platform") - # @ohai[:platform].should == "debian" - # end - # - # it_should_check_from("platform", "platform_version", "cat /etc/debian_version", "lenny/sid") - # end + it "should not set the platform to the os if it was set earlier" do + @ohai[:platform] = 'lars' + @ohai._require_plugin("platform") + @ohai[:platform].should eql("lars") end - describe "on darwin" do - before(:each) do - @ohai[:os] = "darwin" - @pid = 10 - @stdin = mock("STDIN", { :close => true }) - @stdout = mock("STDOUT") - @stdout.stub!(:each). - and_yield("ProductName: Mac OS X"). - and_yield("ProductVersion: 10.5.5"). - and_yield("BuildVersion: 9F33") - @stderr = mock("STDERR") - @ohai.stub!(:popen4).with("sw_vers").and_yield(@pid, @stdin, @stdout, @stderr) - end - - it "should run sw_vers" do - @ohai.should_receive(:popen4).with("sw_vers").and_return(true) - @ohai._require_plugin("platform") - end - - it "should close sw_vers stdin" do - @stdin.should_receive(:close) - @ohai._require_plugin("platform") - end - - it "should iterate over each line of sw_vers stdout" do - @stdout.should_receive(:each).and_return(true) - @ohai._require_plugin("platform") - end - - it "should set platform to ProductName, downcased with _ for \\s" do - @ohai._require_plugin("platform") - @ohai[:platform].should == "mac_os_x" - end - - it "should set platform_version to ProductVersion" do - @ohai._require_plugin("platform") - @ohai[:platform_version].should == "10.5.5" - end - - it "should set platform_build to BuildVersion" do - @ohai._require_plugin("platform") - @ohai[:platform_build].should == "9F33" - end + it "should set the platform_version to the os_version if it was not set earlier" do + @ohai._require_plugin("platform") + @ohai[:os_version].should eql("poop") + end + + it "should not set the platform to the os if it was set earlier" do + @ohai[:platform_version] = 'ulrich' + @ohai._require_plugin("platform") + @ohai[:platform_version].should eql("ulrich") end end
\ No newline at end of file diff --git a/spec/ohai/plugins/uptime_spec.rb b/spec/ohai/plugins/uptime_spec.rb deleted file mode 100644 index e236f407..00000000 --- a/spec/ohai/plugins/uptime_spec.rb +++ /dev/null @@ -1,70 +0,0 @@ -# -# Author:: Adam Jacob (<adam@opscode.com>) -# Copyright:: Copyright (c) 2008 OpsCode, Inc. -# License:: Apache License, Version 2.0 -# -# 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. -# See the License for the specific language governing permissions and -# limitations under the License. -# - - -require File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb') - -describe Ohai::System, "plugin uptime" do - before(:each) do - @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) - end - - it "should require the os plugin" do - @ohai.should_receive(:require_plugin).with("os").and_return(true) - @ohai._require_plugin("uptime") - end - - describe "on linux" do - before(:each) do - @ohai[:os] = "linux" - @mock_file = mock("/proc/uptime", { :gets => "18423 989" }) - File.stub!(:open).with("/proc/uptime").and_return(@mock_file) - end - - it "should check /proc/uptime for the uptime and idletime" do - File.should_receive(:open).with("/proc/uptime").and_return(@mock_file) - @ohai._require_plugin("uptime") - end - - it "should split the value of /proc uptime" do - @mock_file.gets.should_receive(:split).with(" ").and_return(["18423", "989"]) - @ohai._require_plugin("uptime") - end - - it "should set uptime_seconds to uptime" do - @ohai._require_plugin("uptime") - @ohai[:uptime_seconds].should == 18423 - end - - it "should set uptime to a human readable date" do - @ohai._require_plugin("uptime") - @ohai[:uptime].should == "5 hours 07 minutes 03 seconds" - end - - it "should set idletime_seconds to uptime" do - @ohai._require_plugin("uptime") - @ohai[:idletime_seconds].should == 989 - end - - it "should set idletime to a human readable date" do - @ohai._require_plugin("uptime") - @ohai[:idletime].should == "16 minutes 29 seconds" - end - end -end
\ No newline at end of file diff --git a/spec/rcov.opts b/spec/rcov.opts new file mode 100644 index 00000000..484626ea --- /dev/null +++ b/spec/rcov.opts @@ -0,0 +1,2 @@ +--exclude +spec,bin,/Library/Ruby diff --git a/tasks/rspec.rake b/tasks/rspec.rake index 2415fa49..61dc9d85 100644 --- a/tasks/rspec.rake +++ b/tasks/rspec.rake @@ -14,8 +14,27 @@ EOS exit(0) end -desc "Run the specs under spec/models" +desc "Run the specs under spec" Spec::Rake::SpecTask.new do |t| t.spec_opts = ['--options', "spec/spec.opts"] t.spec_files = FileList['spec/**/*_spec.rb'] end + +namespace :spec do + desc "Run all specs in spec directory with RCov" + Spec::Rake::SpecTask.new(:rcov) do |t| + t.spec_opts = ['--options', "spec/spec.opts"] + t.spec_files = FileList['spec/**/*_spec.rb'] + t.rcov = true + t.rcov_opts = lambda do + IO.readlines("spec/rcov.opts").map {|l| l.chomp.split " "}.flatten + end + end + + desc "Print Specdoc for all specs" + Spec::Rake::SpecTask.new(:doc) do |t| + t.spec_opts = ["--format", "specdoc", "--dry-run"] + t.spec_files = FileList['spec/**/*_spec.rb'] + end +end + |