|
25 | 25 | @new_resource = Chef::Resource::Package.new('cups') |
26 | 26 | @current_resource = Chef::Resource::Package.new('cups') |
27 | 27 | @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) |
36 | 36 | @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) |
37 | 37 | Chef::Resource::Package.stub!(:new).and_return(@current_resource) |
38 | 38 | @stderr = mock("STDERR", :null_object => true) |
39 | 39 | @pid = mock("PID", :null_object => true) |
40 | 40 | end |
41 | | - |
| 41 | + |
42 | 42 | describe "when loading the current system state" do |
43 | | - |
| 43 | + |
44 | 44 | it "should create a current resource with the name of the new_resource" do |
45 | 45 | Chef::Resource::Package.should_receive(:new).and_return(@current_resource) |
46 | 46 | @provider.load_current_resource |
47 | 47 | end |
48 | | - |
| 48 | + |
49 | 49 | it "should set the current resources package name to the new resources package name" do |
50 | 50 | @current_resource.should_receive(:package_name).with(@new_resource.package_name) |
51 | 51 | @provider.load_current_resource |
52 | 52 | end |
53 | | - |
| 53 | + |
54 | 54 | 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) |
56 | 56 | @current_resource.should_receive(:version).with(nil).and_return(true) |
57 | 57 | @provider.load_current_resource |
58 | 58 | end |
59 | | - |
| 59 | + |
60 | 60 | it "should set the installed version if yum has one" do |
61 | 61 | @current_resource.should_receive(:version).with("1.2.4-11.18.el5").and_return(true) |
62 | 62 | @provider.load_current_resource |
63 | 63 | end |
64 | | - |
| 64 | + |
65 | 65 | it "should set the candidate version if yum info has one" do |
66 | 66 | @provider.load_current_resource |
67 | 67 | @provider.candidate_version.should eql("1.2.4-11.18.el5_2.3") |
68 | 68 | end |
69 | | - |
| 69 | + |
70 | 70 | it "should return the current resouce" do |
71 | 71 | @provider.load_current_resource.should eql(@current_resource) |
72 | 72 | end |
73 | 73 | end |
74 | 74 |
|
75 | 75 | 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 | | - |
98 | 76 | it "should run yum install with the package name and version" do |
99 | 77 | @provider.should_receive(:run_command_with_systems_locale).with({ |
100 | 78 | :command => "yum -d0 -e0 -y install emacs-1.0" |
|
110 | 88 | @provider.install_package("emacs", "21.4-20.el5") |
111 | 89 | end |
112 | 90 |
|
| 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 | + |
113 | 99 | end |
114 | 100 |
|
115 | 101 | describe Chef::Provider::Package::Yum, "upgrade_package" do |
|
119 | 105 | }) |
120 | 106 | @provider.upgrade_package(@new_resource.name, nil) |
121 | 107 | 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 | + |
123 | 117 | it "should run yum install if the package is installed and a version is given" do |
124 | 118 | @provider.candidate_version = '11' |
125 | 119 | @provider.should_receive(:run_command_with_systems_locale).with({ |
126 | 120 | :command => "yum -d0 -e0 -y install cups-11" |
127 | 121 | }) |
128 | 122 | @provider.upgrade_package(@new_resource.name, @provider.candidate_version) |
129 | 123 | end |
130 | | - |
| 124 | + |
131 | 125 | it "should run yum install if the package is not installed" do |
132 | 126 | @provider.candidate_version = '11' |
133 | 127 | @current_resource.stub!(:version).and_return(nil) |
|
146 | 140 | }) |
147 | 141 | @provider.remove_package("emacs", "1.0") |
148 | 142 | 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 |
149 | 151 | end |
150 | 152 |
|
151 | 153 | describe Chef::Provider::Package::Yum, "purge_package" do |
|
0 commit comments