summaryrefslogtreecommitdiff
path: root/spec/unit/provider/package/yum/yum_cache_spec.rb
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2018-01-29 16:56:11 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2018-01-29 17:04:46 -0800
commitef555061eb98597e40b1cfc632162a49827ed413 (patch)
tree9b5e9e96ccece1e46dff96bf7f10c34b84236fd3 /spec/unit/provider/package/yum/yum_cache_spec.rb
parentfc41b59349ff627141884fb13c5d3e963722106d (diff)
downloadchef-ef555061eb98597e40b1cfc632162a49827ed413.tar.gz
add specs for YumCache fascadelcg/chef-12-yum-backport
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'spec/unit/provider/package/yum/yum_cache_spec.rb')
-rw-r--r--spec/unit/provider/package/yum/yum_cache_spec.rb89
1 files changed, 89 insertions, 0 deletions
diff --git a/spec/unit/provider/package/yum/yum_cache_spec.rb b/spec/unit/provider/package/yum/yum_cache_spec.rb
new file mode 100644
index 0000000000..ba78987de7
--- /dev/null
+++ b/spec/unit/provider/package/yum/yum_cache_spec.rb
@@ -0,0 +1,89 @@
+#
+# Copyright:: Copyright 2018-2018, Chef Software 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 "spec_helper"
+
+describe Chef::Provider::Package::Yum::YumCache do
+ let(:yum_cache) { Chef::Provider::Package::Yum::YumCache.instance }
+
+ let(:python_helper) { instance_double(Chef::Provider::Package::Yum::PythonHelper) }
+
+ def yum_version(name, version, arch)
+ Chef::Provider::Package::Yum::Version.new(name, version, arch)
+ end
+
+ before(:each) do
+ allow( yum_cache ).to receive(:python_helper).and_return(python_helper)
+ end
+
+ it "package_available? returns false if the helper reports the available version is nil" do
+ expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo").and_return( yum_version("foo", nil, nil) )
+ expect( yum_cache.package_available?("foo") ).to be false
+ end
+
+ it "package_available? returns true if the helper returns an available version" do
+ expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo").and_return( yum_version("foo", "1.2.3-1", "x86_64") )
+ expect( yum_cache.package_available?("foo") ).to be true
+ end
+
+ it "version_available? returns false if the helper reports the available version is nil" do
+ expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", "1.2.3", nil).and_return( yum_version("foo", nil, nil) )
+ expect( yum_cache.version_available?("foo", "1.2.3") ).to be false
+ end
+
+ it "version_available? returns true if the helper returns an available version" do
+ expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", "1.2.3", nil).and_return( yum_version("foo", "1.2.3-1", "x86_64") )
+ expect( yum_cache.version_available?("foo", "1.2.3") ).to be true
+ end
+
+ it "version_available? with an arch returns false if the helper reports the available version is nil" do
+ expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", "1.2.3", "x86_64").and_return( yum_version("foo", nil, nil) )
+ expect( yum_cache.version_available?("foo", "1.2.3", "x86_64") ).to be false
+ end
+
+ it "version_available? with an arch returns true if the helper returns an available version" do
+ expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", "1.2.3", "x86_64").and_return( yum_version("foo", "1.2.3-1", "x86_64") )
+ expect( yum_cache.version_available?("foo", "1.2.3", "x86_64") ).to be true
+ end
+
+ [ :refresh, :reload, :reload_installed, :reload_provides, :reset, :reset_installed ].each do |method|
+ it "restarts the python helper when #{method} is called" do
+ expect( python_helper ).to receive(:restart)
+ yum_cache.send(method)
+ end
+ end
+
+ it "installed_version? returns nil if the helper reports the installed version is nil" do
+ expect( python_helper ).to receive(:package_query).with(:whatinstalled, "foo").and_return( yum_version("foo", nil, nil) )
+ expect( yum_cache.installed_version("foo") ).to be nil
+ end
+
+ it "installed_version? returns version string if the helper returns an installed version" do
+ expect( python_helper ).to receive(:package_query).with(:whatinstalled, "foo").and_return( yum_version("foo", "1.2.3-1", "x86_64") )
+ expect( yum_cache.installed_version("foo") ).to eql("1.2.3-1.x86_64")
+ end
+
+ it "available_version? returns nil if the helper reports the available version is nil" do
+ expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo").and_return( yum_version("foo", nil, nil) )
+ expect( yum_cache.available_version("foo") ).to be nil
+ end
+
+ it "available_version? returns version string if the helper returns an available version" do
+ expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo").and_return( yum_version("foo", "1.2.3-1", "x86_64") )
+ expect( yum_cache.available_version("foo") ).to eql("1.2.3-1.x86_64")
+ end
+end