summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@chef.io>2015-06-19 13:14:13 -0700
committerdanielsdeleo <dan@chef.io>2015-06-19 13:29:42 -0700
commit4c389f615afdab97ab8f1718efa5b29c1f3d696c (patch)
treefdfe3573b20cd02c9b37bab161deb051e7c6d5fc
parenteccaff433d062a9d2ece196480032b7b96bf942a (diff)
downloadohai-4c389f615afdab97ab8f1718efa5b29c1f3d696c.tar.gz
Refactor stubbing of File.exists in linux platform tests
-rw-r--r--spec/unit/plugins/linux/platform_spec.rb247
1 files changed, 147 insertions, 100 deletions
diff --git a/spec/unit/plugins/linux/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb
index ce21f2f7..41d8261a 100644
--- a/spec/unit/plugins/linux/platform_spec.rb
+++ b/spec/unit/plugins/linux/platform_spec.rb
@@ -21,23 +21,38 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Linux plugin platform" do
+
+ let(:have_debian_version) { false }
+ let(:have_redhat_release) { false }
+ let(:have_gentoo_release) { false }
+ let(:have_exherbo_release) { false }
+ let(:have_suse_release) { false }
+ let(:have_arch_release) { false }
+ let(:have_system_release) { false }
+ let(:have_slackware_version) { false }
+ let(:have_enterprise_release) { false }
+ let(:have_oracle_release) { false }
+ let(:have_parallels_release) { false }
+ let(:have_raspi_config) { false }
+ let(:have_os_release) { false }
+
before(:each) do
@plugin = get_plugin("linux/platform")
allow(@plugin).to receive(:collect_os).and_return(:linux)
@plugin[:lsb] = Mash.new
- allow(File).to receive(:exists?).with("/etc/debian_version").and_return(false)
- allow(File).to receive(:exists?).with("/etc/redhat-release").and_return(false)
- allow(File).to receive(:exists?).with("/etc/gentoo-release").and_return(false)
- allow(File).to receive(:exists?).with("/etc/exherbo-release").and_return(false)
- allow(File).to receive(:exists?).with("/etc/SuSE-release").and_return(false)
- allow(File).to receive(:exists?).with("/etc/arch-release").and_return(false)
- allow(File).to receive(:exists?).with("/etc/system-release").and_return(false)
- allow(File).to receive(:exists?).with("/etc/slackware-version").and_return(false)
- allow(File).to receive(:exists?).with("/etc/enterprise-release").and_return(false)
- allow(File).to receive(:exists?).with("/etc/oracle-release").and_return(false)
- allow(File).to receive(:exists?).with("/etc/parallels-release").and_return(false)
- allow(File).to receive(:exists?).with("/usr/bin/raspi-config").and_return(false)
- allow(File).to receive(:exists?).with("/etc/os-release").and_return(false)
+ allow(File).to receive(:exists?).with("/etc/debian_version").and_return(have_debian_version)
+ allow(File).to receive(:exists?).with("/etc/redhat-release").and_return(have_redhat_release)
+ allow(File).to receive(:exists?).with("/etc/gentoo-release").and_return(have_gentoo_release)
+ allow(File).to receive(:exists?).with("/etc/exherbo-release").and_return(have_exherbo_release)
+ allow(File).to receive(:exists?).with("/etc/SuSE-release").and_return(have_suse_release)
+ allow(File).to receive(:exists?).with("/etc/arch-release").and_return(have_arch_release)
+ allow(File).to receive(:exists?).with("/etc/system-release").and_return(have_system_release)
+ allow(File).to receive(:exists?).with("/etc/slackware-version").and_return(have_slackware_version)
+ allow(File).to receive(:exists?).with("/etc/enterprise-release").and_return(have_enterprise_release)
+ allow(File).to receive(:exists?).with("/etc/oracle-release").and_return(have_oracle_release)
+ allow(File).to receive(:exists?).with("/etc/parallels-release").and_return(have_parallels_release)
+ allow(File).to receive(:exists?).with("/usr/bin/raspi-config").and_return(have_raspi_config)
+ allow(File).to receive(:exists?).with("/etc/os-release").and_return(have_os_release)
end
describe "on lsb compliant distributions" do
@@ -110,9 +125,11 @@ describe Ohai::System, "Linux plugin platform" do
end
describe "on debian" do
+
+ let(:have_debian_version) { true }
+
before(:each) do
@plugin.lsb = nil
- expect(File).to receive(:exists?).with("/etc/debian_version").and_return(true)
end
it "should read the version from /etc/debian_version" do
@@ -135,20 +152,26 @@ describe Ohai::System, "Linux plugin platform" do
expect(@plugin[:platform]).to eq("ubuntu")
end
- # Raspbian is a debian clone
- it "should detect Raspbian as itself with debian as the family" do
- expect(File).to receive(:exists?).with("/usr/bin/raspi-config").and_return(true)
- expect(File).to receive(:read).with("/etc/debian_version").and_return("wheezy/sid")
- @plugin.run
- expect(@plugin[:platform]).to eq("raspbian")
- expect(@plugin[:platform_family]).to eq("debian")
+ context "on raspbian" do
+
+ let(:have_raspi_config) { true }
+
+ # Raspbian is a debian clone
+ it "should detect Raspbian as itself with debian as the family" do
+ expect(File).to receive(:read).with("/etc/debian_version").and_return("wheezy/sid")
+ @plugin.run
+ expect(@plugin[:platform]).to eq("raspbian")
+ expect(@plugin[:platform_family]).to eq("debian")
+ end
end
end
describe "on slackware" do
+
+ let(:have_slackware_version) { true }
+
before(:each) do
@plugin.lsb = nil
- expect(File).to receive(:exists?).with("/etc/slackware-version").and_return(true)
end
it "should set platform and platform_family to slackware" do
@@ -160,9 +183,11 @@ describe Ohai::System, "Linux plugin platform" do
end
describe "on arch" do
+
+ let(:have_arch_release) { true }
+
before(:each) do
@plugin.lsb = nil
- expect(File).to receive(:exists?).with("/etc/arch-release").and_return(true)
end
it "should set platform to arch and platform_family to arch" do
@@ -179,9 +204,11 @@ describe Ohai::System, "Linux plugin platform" do
end
describe "on gentoo" do
+
+ let(:have_gentoo_release) { true }
+
before(:each) do
@plugin.lsb = nil
- expect(File).to receive(:exists?).with("/etc/gentoo-release").and_return(true)
end
it "should set platform and platform_family to gentoo" do
@@ -193,9 +220,11 @@ describe Ohai::System, "Linux plugin platform" do
end
describe "on exherbo" do
+
+ let(:have_exherbo_release) { true }
+
before(:each) do
@plugin.lsb = nil
- expect(File).to receive(:exists?).with("/etc/exherbo-release").and_return(true)
end
it "should set platform and platform_family to exherbo" do
@@ -264,9 +293,11 @@ describe Ohai::System, "Linux plugin platform" do
end
describe "without lsb_release results" do
+
+ let(:have_redhat_release) { true }
+
before(:each) do
@plugin.lsb = nil
- expect(File).to receive(:exists?).with("/etc/redhat-release").and_return(true)
end
it "should read the platform as centos and version as 5.3" do
@@ -334,13 +365,16 @@ describe Ohai::System, "Linux plugin platform" do
end
describe "on pcs linux" do
+
+ let(:have_redhat_release) { true }
+ let(:have_parallels_release) { true }
+
describe "with lsb_result" do
+
it "should read the platform as parallels and version as 6.0.5" do
@plugin[:lsb][:id] = "CloudLinuxServer"
@plugin[:lsb][:release] = "6.5"
- allow(File).to receive(:exists?).with("/etc/redhat-release").and_return(true)
allow(File).to receive(:read).with("/etc/redhat-release").and_return("CloudLinux Server release 6.5 (Pavel Popovich)")
- expect(File).to receive(:exists?).with("/etc/parallels-release").and_return(true)
expect(File).to receive(:read).with("/etc/parallels-release").and_return("Parallels Cloud Server 6.0.5 (20007)")
@plugin.run
expect(@plugin[:platform]).to eq("parallels")
@@ -350,14 +384,13 @@ describe Ohai::System, "Linux plugin platform" do
end
describe "without lsb_results" do
+
before(:each) do
@plugin.lsb = nil
end
it "should read the platform as parallels and version as 6.0.5" do
- allow(File).to receive(:exists?).with("/etc/redhat-release").and_return(true)
allow(File).to receive(:read).with("/etc/redhat-release").and_return("CloudLinux Server release 6.5 (Pavel Popovich)")
- expect(File).to receive(:exists?).with("/etc/parallels-release").and_return(true)
expect(File).to receive(:read).with("/etc/parallels-release").and_return("Parallels Cloud Server 6.0.5 (20007)")
@plugin.run
expect(@plugin[:platform]).to eq("parallels")
@@ -368,93 +401,104 @@ describe Ohai::System, "Linux plugin platform" do
end
describe "on oracle enterprise linux" do
- describe "with lsb_results" do
- it "should read the platform as oracle and version as 5.7" do
- @plugin[:lsb][:id] = "EnterpriseEnterpriseServer"
- @plugin[:lsb][:release] = "5.7"
- allow(File).to receive(:exists?).with("/etc/redhat-release").and_return(true)
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 5.7 (Tikanga)")
- expect(File).to receive(:exists?).with("/etc/enterprise-release").and_return(true)
- expect(File).to receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.7 (Carthage)")
- @plugin.run
- expect(@plugin[:platform]).to eq("oracle")
- expect(@plugin[:platform_version]).to eq("5.7")
+
+ let(:have_redhat_release) { true }
+
+ context "with lsb_results" do
+
+ context "on version 5.x" do
+
+ let(:have_enterprise_release) { true }
+
+ it "should read the platform as oracle and version as 5.7" do
+ @plugin[:lsb][:id] = "EnterpriseEnterpriseServer"
+ @plugin[:lsb][:release] = "5.7"
+ allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 5.7 (Tikanga)")
+ expect(File).to receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.7 (Carthage)")
+ @plugin.run
+ expect(@plugin[:platform]).to eq("oracle")
+ expect(@plugin[:platform_version]).to eq("5.7")
+ end
end
- it "should read the platform as oracle and version as 6.1" do
- @plugin[:lsb][:id] = "OracleServer"
- @plugin[:lsb][:release] = "6.1"
- allow(File).to receive(:exists?).with("/etc/redhat-release").and_return(true)
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.1 (Santiago)")
- expect(File).to receive(:exists?).with("/etc/oracle-release").and_return(true)
- expect(File).to receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.1")
- @plugin.run
- expect(@plugin[:platform]).to eq("oracle")
- expect(@plugin[:platform_version]).to eq("6.1")
+ context "on version 6.x" do
+
+ let(:have_oracle_release) { true }
+
+ it "should read the platform as oracle and version as 6.1" do
+ @plugin[:lsb][:id] = "OracleServer"
+ @plugin[:lsb][:release] = "6.1"
+ allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.1 (Santiago)")
+ expect(File).to receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.1")
+ @plugin.run
+ expect(@plugin[:platform]).to eq("oracle")
+ expect(@plugin[:platform_version]).to eq("6.1")
+ end
+
end
end
- describe "without lsb_results" do
+ context "without lsb_results" do
before(:each) do
@plugin.lsb = nil
end
- it "should read the platform as oracle and version as 5" do
- allow(File).to receive(:exists?).with("/etc/redhat-release").and_return(true)
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("Enterprise Linux Enterprise Linux Server release 5 (Carthage)")
- expect(File).to receive(:exists?).with("/etc/enterprise-release").and_return(true)
- expect(File).to receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5 (Carthage)")
- @plugin.run
- expect(@plugin[:platform]).to eq("oracle")
- expect(@plugin[:platform_version]).to eq("5")
- end
+ context "on version 5.x" do
- it "should read the platform as oracle and version as 5.1" do
- allow(File).to receive(:exists?).with("/etc/redhat-release").and_return(true)
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("Enterprise Linux Enterprise Linux Server release 5.1 (Carthage)")
- expect(File).to receive(:exists?).with("/etc/enterprise-release").and_return(true)
- expect(File).to receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.1 (Carthage)")
- @plugin.run
- expect(@plugin[:platform]).to eq("oracle")
- expect(@plugin[:platform_version]).to eq("5.1")
- end
+ let(:have_enterprise_release) { true }
- it "should read the platform as oracle and version as 5.7" do
- allow(File).to receive(:exists?).with("/etc/redhat-release").and_return(true)
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 5.7 (Tikanga)")
- expect(File).to receive(:exists?).with("/etc/enterprise-release").and_return(true)
- expect(File).to receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.7 (Carthage)")
- @plugin.run
- expect(@plugin[:platform]).to eq("oracle")
- expect(@plugin[:platform_version]).to eq("5.7")
- end
+ it "should read the platform as oracle and version as 5" do
+ allow(File).to receive(:read).with("/etc/redhat-release").and_return("Enterprise Linux Enterprise Linux Server release 5 (Carthage)")
+ expect(File).to receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5 (Carthage)")
+ @plugin.run
+ expect(@plugin[:platform]).to eq("oracle")
+ expect(@plugin[:platform_version]).to eq("5")
+ end
+
+ it "should read the platform as oracle and version as 5.1" do
+ allow(File).to receive(:read).with("/etc/redhat-release").and_return("Enterprise Linux Enterprise Linux Server release 5.1 (Carthage)")
+ expect(File).to receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.1 (Carthage)")
+ @plugin.run
+ expect(@plugin[:platform]).to eq("oracle")
+ expect(@plugin[:platform_version]).to eq("5.1")
+ end
+
+ it "should read the platform as oracle and version as 5.7" do
+ allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 5.7 (Tikanga)")
+ expect(File).to receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.7 (Carthage)")
+ @plugin.run
+ expect(@plugin[:platform]).to eq("oracle")
+ expect(@plugin[:platform_version]).to eq("5.7")
+ end
- it "should read the platform as oracle and version as 6.0" do
- allow(File).to receive(:exists?).with("/etc/redhat-release").and_return(true)
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.0 (Santiago)")
- expect(File).to receive(:exists?).with("/etc/oracle-release").and_return(true)
- expect(File).to receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.0")
- @plugin.run
- expect(@plugin[:platform]).to eq("oracle")
- expect(@plugin[:platform_version]).to eq("6.0")
end
- it "should read the platform as oracle and version as 6.1" do
- allow(File).to receive(:exists?).with("/etc/redhat-release").and_return(true)
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.1 (Santiago)")
- expect(File).to receive(:exists?).with("/etc/oracle-release").and_return(true)
- expect(File).to receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.1")
- @plugin.run
- expect(@plugin[:platform]).to eq("oracle")
- expect(@plugin[:platform_version]).to eq("6.1")
+ context "on version 6.x" do
+
+ let(:have_oracle_release) { true }
+
+ it "should read the platform as oracle and version as 6.0" do
+ allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.0 (Santiago)")
+ expect(File).to receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.0")
+ @plugin.run
+ expect(@plugin[:platform]).to eq("oracle")
+ expect(@plugin[:platform_version]).to eq("6.0")
+ end
+
+ it "should read the platform as oracle and version as 6.1" do
+ allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.1 (Santiago)")
+ expect(File).to receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.1")
+ @plugin.run
+ expect(@plugin[:platform]).to eq("oracle")
+ expect(@plugin[:platform_version]).to eq("6.1")
+ end
end
end
end
describe "on suse" do
- before(:each) do
- expect(File).to receive(:exists?).with("/etc/SuSE-release").and_return(true)
- end
+
+ let(:have_suse_release) { true }
describe "with lsb_release results" do
before(:each) do
@@ -532,10 +576,13 @@ describe Ohai::System, "Linux plugin platform" do
end
describe "on Wind River Linux for Cisco Nexus" do
+
+ let(:have_redhat_release) { true }
+
+ let(:have_os_release) { true }
+
it "should set platform to nexus and platform_family to wrlinux" do
@plugin.lsb = nil
- allow(File).to receive(:exists?).with("/etc/redhat-release").and_return(true)
- allow(File).to receive(:exists?).with("/etc/os-release").and_return(true)
expect(File).to receive(:read).with("/etc/os-release").and_return("ID_LIKE=wrlinux\nID=nexus\nCISCO_RELEASE_INFO=/etc/os-release")
@plugin.run
expect(@plugin[:platform]).to eq("nexus")