2
# Author:: Adam Jacob (<adam@opscode.com>)
3
# Copyright:: Copyright (c) 2008 Opscode, Inc.
4
# License:: Apache License, Version 2.0
6
# Licensed under the Apache License, Version 2.0 (the "License");
7
# you may not use this file except in compliance with the License.
8
# You may obtain a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS,
14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
# See the License for the specific language governing permissions and
16
# limitations under the License.
19
require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "spec_helper"))
21
describe Chef::Provider::Package::Yum, "load_current_resource" do
23
@node = mock("Chef::Node", :null_object => true)
24
@new_resource = mock("Chef::Resource::Package",
28
:package_name => "cups",
31
@current_resource = mock("Chef::Resource::Package",
38
@status = mock("Status", :exitstatus => 0)
40
'Chef::Provider::Yum::YumCache',
43
:installed_version => "1.2.4-11.18.el5",
44
:candidate_version => "1.2.4-11.18.el5_2.3"
46
Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
47
@provider = Chef::Provider::Package::Yum.new(@node, @new_resource)
48
Chef::Resource::Package.stub!(:new).and_return(@current_resource)
49
@stderr = mock("STDERR", :null_object => true)
50
@pid = mock("PID", :null_object => true)
53
it "should create a current resource with the name of the new_resource" do
54
Chef::Resource::Package.should_receive(:new).and_return(@current_resource)
55
@provider.load_current_resource
58
it "should set the current resources package name to the new resources package name" do
59
@current_resource.should_receive(:package_name).with(@new_resource.package_name)
60
@provider.load_current_resource
63
it "should set the installed version to nil on the current resource if no installed package" do
64
@yum_cache.stub!(:installed_version).and_return(nil)
65
@current_resource.should_receive(:version).with(nil).and_return(true)
66
@provider.load_current_resource
69
it "should set the installed version if yum has one" do
70
@current_resource.should_receive(:version).with("1.2.4-11.18.el5").and_return(true)
71
@provider.load_current_resource
74
it "should set the candidate version if yum info has one" do
75
@provider.load_current_resource
76
@provider.candidate_version.should eql("1.2.4-11.18.el5_2.3")
79
it "should return the current resouce" do
80
@provider.load_current_resource.should eql(@current_resource)
84
describe Chef::Provider::Package::Yum, "install_package" do
87
@node = mock("Chef::Node", :null_object => true)
88
@new_resource = mock("Chef::Resource::Package",
92
:package_name => "emacs",
96
'Chef::Provider::Yum::YumCache',
99
:installed_version => "1.2.4-11.18.el5",
100
:candidate_version => "1.2.4-11.18.el5_2.3"
102
Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
103
@provider = Chef::Provider::Package::Yum.new(@node, @new_resource)
106
it "should run yum install with the package name and version" do
107
@provider.should_receive(:run_command).with({
108
:command => "yum -q -y install emacs-1.0"
110
@provider.install_package("emacs", "1.0")
114
describe Chef::Provider::Package::Yum, "upgrade_package" do
117
@node = mock("Chef::Node", :null_object => true)
118
@new_resource = mock("Chef::Resource::Package",
119
:null_object => true,
122
:package_name => "emacs",
126
'Chef::Provider::Yum::YumCache',
129
:installed_version => "1.2.4-11.18.el5",
130
:candidate_version => "1.2.4-11.18.el5_2.3"
132
Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
133
@current_resource = mock("Chef::Resource::Package",
134
:null_object => true,
137
:package_name => "emacs",
140
@provider = Chef::Provider::Package::Yum.new(@node, @new_resource)
141
@provider.candidate_version = "11"
142
@provider.current_resource = @current_resource
145
it "should run yum update if the package is installed" do
146
@provider.should_receive(:run_command).with({
147
:command => "yum -q -y update emacs-11"
149
@provider.upgrade_package(@new_resource.name, @provider.candidate_version)
152
it "should run yum install if the package is not installed" do
153
@current_resource.stub!(:version).and_return(nil)
154
@provider.should_receive(:run_command).with({
155
:command => "yum -q -y install emacs-11"
157
@provider.upgrade_package(@new_resource.name, @provider.candidate_version)
161
describe Chef::Provider::Package::Yum, "remove_package" do
163
@node = mock("Chef::Node", :null_object => true)
164
@new_resource = mock("Chef::Resource::Package",
165
:null_object => true,
168
:package_name => "emacs",
172
'Chef::Provider::Yum::YumCache',
175
:installed_version => "1.2.4-11.18.el5",
176
:candidate_version => "1.2.4-11.18.el5_2.3"
178
Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
179
@provider = Chef::Provider::Package::Yum.new(@node, @new_resource)
182
it "should run yum remove with the package name" do
183
@provider.should_receive(:run_command).with({
184
:command => "yum -q -y remove emacs-1.0"
186
@provider.remove_package("emacs", "1.0")
190
describe Chef::Provider::Package::Yum, "purge_package" do
192
@node = mock("Chef::Node", :null_object => true)
193
@new_resource = mock("Chef::Resource::Package",
194
:null_object => true,
197
:package_name => "emacs",
201
'Chef::Provider::Yum::YumCache',
204
:installed_version => "1.2.4-11.18.el5",
205
:candidate_version => "1.2.4-11.18.el5_2.3"
207
Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
208
@provider = Chef::Provider::Package::Yum.new(@node, @new_resource)
211
it "should run yum remove with the package name" do
212
@provider.should_receive(:run_command).with({
213
:command => "yum -q -y remove emacs-1.0"
215
@provider.purge_package("emacs", "1.0")