Skip to content

Commit 6dbfe5e

Browse files
mdkentdanielsdeleo
authored andcommitted
CHEF-1100: Add some basic specs for yum arch support.
1 parent 7f83b2a commit 6dbfe5e

2 files changed

Lines changed: 51 additions & 40 deletions

File tree

‎chef/spec/unit/provider/package/yum_spec.rb‎

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,76 +25,54 @@
2525
@new_resource = Chef::Resource::Package.new('cups')
2626
@current_resource = Chef::Resource::Package.new('cups')
2727
@status = mock("Status", :exitstatus => 0)
28-
@yum_cache = mock(
29-
'Chef::Provider::Yum::YumCache',
30-
:refresh => true,
31-
:flush => true,
32-
:installed_version => "1.2.4-11.18.el5",
33-
:candidate_version => "1.2.4-11.18.el5_2.3"
34-
)
35-
Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
28+
@yum_cache = mock(
29+
'Chef::Provider::Yum::YumCache',
30+
:refresh => true,
31+
:flush => true,
32+
:installed_version => "1.2.4-11.18.el5",
33+
:candidate_version => "1.2.4-11.18.el5_2.3"
34+
)
35+
Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
3636
@provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
3737
Chef::Resource::Package.stub!(:new).and_return(@current_resource)
3838
@stderr = mock("STDERR", :null_object => true)
3939
@pid = mock("PID", :null_object => true)
4040
end
41-
41+
4242
describe "when loading the current system state" do
43-
43+
4444
it "should create a current resource with the name of the new_resource" do
4545
Chef::Resource::Package.should_receive(:new).and_return(@current_resource)
4646
@provider.load_current_resource
4747
end
48-
48+
4949
it "should set the current resources package name to the new resources package name" do
5050
@current_resource.should_receive(:package_name).with(@new_resource.package_name)
5151
@provider.load_current_resource
5252
end
53-
53+
5454
it "should set the installed version to nil on the current resource if no installed package" do
55-
@yum_cache.stub!(:installed_version).and_return(nil)
55+
@yum_cache.stub!(:installed_version).and_return(nil)
5656
@current_resource.should_receive(:version).with(nil).and_return(true)
5757
@provider.load_current_resource
5858
end
59-
59+
6060
it "should set the installed version if yum has one" do
6161
@current_resource.should_receive(:version).with("1.2.4-11.18.el5").and_return(true)
6262
@provider.load_current_resource
6363
end
64-
64+
6565
it "should set the candidate version if yum info has one" do
6666
@provider.load_current_resource
6767
@provider.candidate_version.should eql("1.2.4-11.18.el5_2.3")
6868
end
69-
69+
7070
it "should return the current resouce" do
7171
@provider.load_current_resource.should eql(@current_resource)
7272
end
7373
end
7474

7575
describe Chef::Provider::Package::Yum, "install_package" do
76-
77-
# before(:each) do
78-
# @node = Chef::Node.new
79-
# @new_resource = mock("Chef::Resource::Package",
80-
# :null_object => true,
81-
# :name => "emacs",
82-
# :version => nil,
83-
# :package_name => "emacs",
84-
# :updated => nil,
85-
# :source => nil
86-
# )
87-
# @yum_cache = mock(
88-
# 'Chef::Provider::Yum::YumCache',
89-
# :refresh => true,
90-
# :flush => true,
91-
# :installed_version => "1.2.4-11.18.el5",
92-
# :candidate_version => "1.2.4-11.18.el5_2.3"
93-
# )
94-
# Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
95-
# @provider = Chef::Provider::Package::Yum.new(@node, @new_resource)
96-
# end
97-
9876
it "should run yum install with the package name and version" do
9977
@provider.should_receive(:run_command_with_systems_locale).with({
10078
:command => "yum -d0 -e0 -y install emacs-1.0"
@@ -110,6 +88,14 @@
11088
@provider.install_package("emacs", "21.4-20.el5")
11189
end
11290

91+
it "should run yum install with the package name, version and arch" do
92+
@new_resource.stub!(:arch).and_return("i386")
93+
@provider.should_receive(:run_command_with_systems_locale).with({
94+
:command => "yum -d0 -e0 -y install emacs-21.4-20.el5.i386"
95+
})
96+
@provider.install_package("emacs", "21.4-20.el5")
97+
end
98+
11399
end
114100

115101
describe Chef::Provider::Package::Yum, "upgrade_package" do
@@ -119,15 +105,23 @@
119105
})
120106
@provider.upgrade_package(@new_resource.name, nil)
121107
end
122-
108+
109+
it "should run yum update with arch if the package is installed and no version is given" do
110+
@new_resource.stub!(:arch).and_return("i386")
111+
@provider.should_receive(:run_command_with_systems_locale).with({
112+
:command => "yum -d0 -e0 -y update cups.i386"
113+
})
114+
@provider.upgrade_package(@new_resource.name, nil)
115+
end
116+
123117
it "should run yum install if the package is installed and a version is given" do
124118
@provider.candidate_version = '11'
125119
@provider.should_receive(:run_command_with_systems_locale).with({
126120
:command => "yum -d0 -e0 -y install cups-11"
127121
})
128122
@provider.upgrade_package(@new_resource.name, @provider.candidate_version)
129123
end
130-
124+
131125
it "should run yum install if the package is not installed" do
132126
@provider.candidate_version = '11'
133127
@current_resource.stub!(:version).and_return(nil)
@@ -146,6 +140,14 @@
146140
})
147141
@provider.remove_package("emacs", "1.0")
148142
end
143+
144+
it "should run yum remove with the package name and arch" do
145+
@new_resource.stub!(:arch).and_return("x86_64")
146+
@provider.should_receive(:run_command_with_systems_locale).with({
147+
:command => "yum -d0 -e0 -y remove emacs-1.0.x86_64"
148+
})
149+
@provider.remove_package("emacs", "1.0")
150+
end
149151
end
150152

151153
describe Chef::Provider::Package::Yum, "purge_package" do

‎chef/spec/unit/resource/yum_package_spec.rb‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,13 @@
3737
end
3838
end
3939

40+
describe Chef::Resource::YumPackage, "arch" do
41+
before(:each) do
42+
@resource = Chef::Resource::YumPackage.new("foo")
43+
end
4044

45+
it "should set the arch variable to whatever is passed in" do
46+
@resource.arch("i386")
47+
@resource.arch.should eql("i386")
48+
end
49+
end

0 commit comments

Comments
 (0)