diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2018-03-15 00:33:22 +0000 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2018-03-15 18:03:30 -0700 |
commit | e48bda8af9be0d52333aa3d4a16339051bff937b (patch) | |
tree | 5d4559d744c281f4cbbbb1ca4fde0a1a60346084 /spec | |
parent | a1d6e9863914dd4d93ae3a319aa86a24e6edbcb8 (diff) | |
download | chef-e48bda8af9be0d52333aa3d4a16339051bff937b.tar.gz |
add a few lock/unlock tests and fix a bug
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/functional/resource/yum_package_spec.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/functional/resource/yum_package_spec.rb b/spec/functional/resource/yum_package_spec.rb index 732cffb1ad..f7cf54e020 100644 --- a/spec/functional/resource/yum_package_spec.rb +++ b/spec/functional/resource/yum_package_spec.rb @@ -24,6 +24,10 @@ exclude_test = !(%w{rhel fedora}.include?(ohai[:platform_family]) && !File.exist describe Chef::Resource::YumPackage, :requires_root, :external => exclude_test do include Chef::Mixin::ShellOut + # NOTE: every single test here either needs to explicitly call flush_cache or needs to explicitly + # call preinstall (which explicitly calls flush_cache). It is your responsibility to do one or the + # other in order to minimize calling flush_cache a half dozen times per test. + def flush_cache Chef::Resource::YumPackage.new("shouldnt-matter", run_context).run_action(:flush_cache) end @@ -881,4 +885,48 @@ gpgcheck=0 end end end + + describe ":lock and :unlock" do + before(:all) do + shell_out!("yum -y install yum-versionlock") + end + + before(:each) do + shell_out("yum versionlock delete '*'") # will exit with error when nothing is locked, we don't care + end + + it "locks an rpm" do + flush_cache + yum_package.package_name("chef_rpm") + yum_package.run_action(:lock) + expect(yum_package.updated_by_last_action?).to be true + expect(shell_out("yum versionlock list").stdout.chomp).to match("^0:chef_rpm-") + end + + it "does not lock if its already locked" do + flush_cache + shell_out!("yum versionlock add chef_rpm") + yum_package.package_name("chef_rpm") + yum_package.run_action(:lock) + expect(yum_package.updated_by_last_action?).to be false + expect(shell_out("yum versionlock list").stdout.chomp).to match("^0:chef_rpm-") + end + + it "unlocks an rpm" do + flush_cache + shell_out!("yum versionlock add chef_rpm") + yum_package.package_name("chef_rpm") + yum_package.run_action(:unlock) + expect(yum_package.updated_by_last_action?).to be true + expect(shell_out("yum versionlock list").stdout.chomp).not_to match("^0:chef_rpm-") + end + + it "does not unlock an already locked rpm" do + flush_cache + yum_package.package_name("chef_rpm") + yum_package.run_action(:unlock) + expect(yum_package.updated_by_last_action?).to be false + expect(shell_out("yum versionlock list").stdout.chomp).not_to match("^0:chef_rpm-") + end + end end |