Skip to content

Commit

Permalink
- [COOK-4275] - Enhancements to yum cookbook
Browse files Browse the repository at this point in the history
- Adding full spec coverage
  • Loading branch information
Sean OMeara committed Feb 13, 2014
1 parent b93e934 commit 69bd248
Show file tree
Hide file tree
Showing 22 changed files with 709 additions and 444 deletions.
14 changes: 13 additions & 1 deletion providers/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,20 @@ def whyrun_supported?
end

action :delete do
file "/etc/yum.repos.d/#{new_resource.repositoryid}.repo" do
template "/etc/yum.repos.d/#{new_resource.repositoryid}.repo" do
action :delete
notifies :run, "execute[yum clean #{new_resource.repositoryid}]", :immediately
notifies :create, "ruby_block[yum-cache-reload-#{new_resource.repositoryid}]", :immediately
end

execute "yum clean #{new_resource.repositoryid}"do
command "yum clean all --disablerepo=* --enablerepo=#{new_resource.repositoryid}"
action :nothing
end

ruby_block "yum-cache-reload-#{new_resource.repositoryid}" do
block { Chef::Provider::Package::Yum::YumCache.instance.reload }
action :nothing
end
end

Expand Down
39 changes: 39 additions & 0 deletions spec/unit/test_globalconfig_one_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require 'spec_helper'

describe 'yum_test::test_globalconfig_one' do
let(:test_global_config_one_run) do
ChefSpec::Runner.new(
:step_into => 'yum_globalconfig'
).converge(described_recipe)
end

let(:test_globalconfig_one_content) do
'# This file was generated by Chef
# Do NOT modify this file by hand.
[main]
cachedir=/var/cache/yum/$basearch/$releasever
debuglevel=2
exactarch=1
gpgcheck=1
installonly_limit=3
keepcache=0
logfile=/var/log/yum.log
obsoletes=1
plugins=1'
end

context 'creating a yum_globalconfig with minimal parameters' do
it 'creates yum_globalconfig[/tmp/yum.conf]' do
expect(test_global_config_one_run).to create_yum_globalconfig('/tmp/yum.conf')
end

it 'steps into yum_globalconfig and creates template[/tmp/yum.conf]' do
expect(test_global_config_one_run).to create_template('/tmp/yum.conf')
end

it 'steps into yum_globalconfig and renders file[/tmp/yum.conf]' do
expect(test_global_config_one_run).to render_file('/tmp/yum.conf').with_content(test_globalconfig_one_content)
end
end
end
105 changes: 105 additions & 0 deletions spec/unit/test_globalconfig_two_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
require 'spec_helper'

describe 'yum_test::test_globalconfig_two' do
let(:test_globalconfig_two_run) do
ChefSpec::Runner.new(
:step_into => 'yum_globalconfig'
).converge(described_recipe)
end

let(:test_globalconfig_two_content) do
'# This file was generated by Chef
# Do NOT modify this file by hand.
[main]
alwaysprompt=true
assumeyes=true
bandwidth=40
bugtracker_url=http://somewhere.eltz.biz
cachedir=/path/to/somewhere/good
clean_requirements_on_remove=true
color=always
color_list_available_downgrade=fg:green
color_list_available_install=fg:green
color_list_available_reinstall=fg:green
color_list_available_upgrade=fg:green
color_list_installed_extra=fg:green
color_list_installed_newer=fg:green
color_list_installed_older=fg:green
color_list_installed_reinstall=fg:green
color_search_match=bold
color_update_installed=fg:blue
color_update_local=fg:blue
color_update_remote=fg:blue
commands=--installroot=root=/over/there
debuglevel=5
diskspacecheck=true
distroverpkg=fedora-release
enable_group_conditionals=1
errorlevel=5
exactarch=1
exclude=kernel emacs-nox
gpgcheck=1
group_package_types=default mandatory
history_list_view=commands
history_record=true
history_record_packages=rpm
http_caching=true
installonly_limit=3
installonlypkgs=kernel, emacs-nox
installroot=/over/there
keepalive=true
keepcache=1
kernelpkgnames=dowhatnow
localpkg_gpgcheck=true
logfile=/your/logs/here
max_retries=10
mdpolicy=instant
metadata_expire=21600
mirrorlist_expire=21600
multilib_policy=best
obsoletes=1
overwrite_groups=true
password=ohai
persistdir=/somewhere/good
pluginconfpath=/etc/yum/pluginconf.d
pluginpath=/path/to /some/plugins
plugins=1
protected_multilib=true
protected_packages=yum glob:/etc/yum/protected.d/*.conf
proxy=https://datproxy.biz
proxy_password=evewashere
proxy_username=alice
recent=7
repo_gpgcheck=true
reset_nice=true
rpmverbosity=warn
showdupesfromrepos=true
ssl_check_cert_permissions=true
sslcacert=/path/to/cacert
sslclientcert=/path/to/clientcert
sslclientkey=/path/to/clientkey
sslverify=true
syslog_device=/dev/log
syslog_facility=LOG_USER
syslog_ident=chuck norris
throttle=100000M
timeout=30
tsflags=noscripts
username=baub'
end

context 'creating a yum_globalconfig with full parameters' do
it 'creates yum_globalconfig[/tmp/yum-full.conf]' do
expect(test_globalconfig_two_run).to create_yum_globalconfig('/tmp/yum-full.conf')
end

it 'steps into yum_globalconfig and create template[/tmp/yum-full.conf]' do
expect(test_globalconfig_two_run).to create_template('/tmp/yum-full.conf')
end

it 'steps into yum_globalconfig and render file[/tmp/yum-full.conf]' do
expect(test_globalconfig_two_run).to render_file('/tmp/yum-full.conf').with_content(test_globalconfig_two_content)
end
end
end
40 changes: 40 additions & 0 deletions spec/unit/test_repository_five_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require 'spec_helper'

describe 'yum_test::test_repository_four' do
let(:test_repository_four_run) do
ChefSpec::Runner.new(
:step_into => 'yum_repository'
).converge(described_recipe)
end

let(:test_repository_four_template) do
test_repository_four_run.template('/etc/yum.repos.d/test4.repo')
end

context 'creating a yum_repository with :remove alias' do
it 'removes yum_repository[test4]' do
expect(test_repository_four_run).to remove_yum_repository('test4')
end

it 'deletes file[/etc/yum.repos.d/test4.repo]' do
expect(test_repository_four_run).to delete_template('/etc/yum.repos.d/test4.repo')
end

it 'does not run execute[yum clean test4]' do
expect(test_repository_four_run).to_not run_execute('yum clean test4')
end

it 'does not run ruby_block[yum-cache-reload-test4]' do
expect(test_repository_four_run).to_not run_ruby_block('yum-cache-reload-test4')
end

it 'sends a :run to execute[yum clean test4]' do
expect(test_repository_four_template).to notify('execute[yum clean test4]')
end

it 'sends a :create to ruby_block[yum-cache-reload-test4]' do
expect(test_repository_four_template).to notify('ruby_block[yum-cache-reload-test4]')
end

end
end
40 changes: 40 additions & 0 deletions spec/unit/test_repository_four_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require 'spec_helper'

describe 'yum_test::test_repository_five' do
let(:test_repository_five_run) do
ChefSpec::Runner.new(
:step_into => 'yum_repository'
).converge(described_recipe)
end

let(:test_repository_five_template) do
test_repository_five_run.template('/etc/yum.repos.d/test5.repo')
end

context 'deletes a yum_repository' do
it 'delete yum_repository[test5]' do
expect(test_repository_five_run).to delete_yum_repository('test5')
end

it 'deletes file[/etc/yum.repos.d/test5.repo]' do
expect(test_repository_five_run).to delete_template('/etc/yum.repos.d/test5.repo')
end

it 'does not run execute[yum clean test5]' do
expect(test_repository_five_run).to_not run_execute('yum clean test5')
end

it 'does not run ruby_block[yum-cache-reload-test5]' do
expect(test_repository_five_run).to_not run_ruby_block('yum-cache-reload-test5')
end

it 'sends a :run to execute[yum clean test5]' do
expect(test_repository_five_template).to notify('execute[yum clean test5]')
end

it 'sends a :create to ruby_block[yum-cache-reload-test5]' do
expect(test_repository_five_template).to notify('ruby_block[yum-cache-reload-test5]')
end

end
end
57 changes: 57 additions & 0 deletions spec/unit/test_repository_one_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
require 'spec_helper'

describe 'yum_test::test_repository_one' do
let(:test_repository_one_run) do
ChefSpec::Runner.new(
:step_into => 'yum_repository'
).converge(described_recipe)
end

let(:test_repository_one_template) do
test_repository_one_run.template('/etc/yum.repos.d/test1.repo')
end

let(:test_repository_one_content) do
'# This file was generated by Chef
# Do NOT modify this file by hand.
[test1]
name=an test
baseurl=http://drop.the.baseurl.biz
enabled=1
gpgcheck=1
sslverify=1
'
end

context 'creating a yum_repository with minimal parameters' do
it 'creates yum_repository[test1]' do
expect(test_repository_one_run).to create_yum_repository('test1')
end

it 'steps into yum_repository and creates template[/etc/yum.repos.d/test1.repo]' do
expect(test_repository_one_run).to create_template('/etc/yum.repos.d/test1.repo')
end

it 'steps into yum_repository and renders file[/etc/yum.repos.d/test1.repo]' do
expect(test_repository_one_run).to render_file('/etc/yum.repos.d/test1.repo').with_content(test_repository_one_content)
end

it 'steps into yum_repository and runs execute[yum-makecache-test1]' do
expect(test_repository_one_run).to_not run_execute('yum-makecache-test1')
end

it 'steps into yum_repository and runs ruby_block[yum-cache-reload-test1]' do
expect(test_repository_one_run).to_not run_ruby_block('yum-cache-reload-test1')
end

it 'sends a :run to execute[yum-makecache-test1]' do
expect(test_repository_one_template).to notify('execute[yum-makecache-test1]')
end

it 'sends a :create to ruby_block[yum-cache-reload-test1]' do
expect(test_repository_one_template).to notify('ruby_block[yum-cache-reload-test1]')
end
end

end
58 changes: 58 additions & 0 deletions spec/unit/test_repository_seven_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require 'spec_helper'

describe 'yum_test::test_repository_seven' do
let(:test_repository_seven_run) do
ChefSpec::Runner.new(
:step_into => 'yum_repository'
).converge(described_recipe)
end

let(:test_repository_seven_template) do
test_repository_seven_run.template('/etc/yum.repos.d/test7.repo')
end

let(:test_repository_seven_content) do
'# This file was generated by Chef
# Do NOT modify this file by hand.
[test7]
name=an test
baseurl=http://drop.the.baseurl.biz
enabled=1
gpgcheck=1
gpgkey=http://example.com/RPM-GPG-KEY-FOOBAR-1
sslverify=1
'
end

context 'creating a yum_repository with minimal parameters' do
it 'creates yum_repository[test7]' do
expect(test_repository_seven_run).to create_yum_repository('test7')
end

it 'steps into yum_repository and creates template[/etc/yum.repos.d/test7.repo]' do
expect(test_repository_seven_run).to create_template('/etc/yum.repos.d/test7.repo')
end

it 'steps into yum_repository and renders file[/etc/yum.repos.d/test7.repo]' do
expect(test_repository_seven_run).to render_file('/etc/yum.repos.d/test7.repo').with_content(test_repository_seven_content)
end

it 'steps into yum_repository and runs execute[yum-makecache-test7]' do
expect(test_repository_seven_run).to_not run_execute('yum-makecache-test7')
end

it 'steps into yum_repository and runs ruby_block[yum-cache-reload-test7]' do
expect(test_repository_seven_run).to_not run_ruby_block('yum-cache-reload-test7')
end

it 'sends a :run to execute[yum-makecache-test7]' do
expect(test_repository_seven_template).to notify('execute[yum-makecache-test7]')
end

it 'sends a :create to ruby_block[yum-cache-reload-test7]' do
expect(test_repository_seven_template).to notify('ruby_block[yum-cache-reload-test7]')
end
end

end
Loading

0 comments on commit 69bd248

Please sign in to comment.