From f998bbae4148b19eec182e3755b7e3021da0acca Mon Sep 17 00:00:00 2001 From: Tony Vu Date: Mon, 29 Feb 2016 17:48:20 -0800 Subject: [PATCH] (BKR-451) Fix broken logger warnings The `warning` methods in `deploy_package_repo` should have been simply `warn`. This PR changes them to warn and adds appropriate spec testing for the methods to ensure they `warn` correctly. --- lib/beaker/host/unix/pkg.rb | 4 +-- spec/beaker/host/unix/pkg_spec.rb | 55 ++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/lib/beaker/host/unix/pkg.rb b/lib/beaker/host/unix/pkg.rb index 6fa8bfebc8..ed2f7a137f 100644 --- a/lib/beaker/host/unix/pkg.rb +++ b/lib/beaker/host/unix/pkg.rb @@ -209,7 +209,7 @@ def deploy_apt_repo(path, name, version) codename = self['platform'].codename if codename.nil? - @logger.warning "Could not determine codename for debian platform #{self['platform']}. Skipping deployment of repo #{name}" + @logger.warn "Could not determine codename for debian platform #{self['platform']}. Skipping deployment of repo #{name}" return end @@ -248,7 +248,7 @@ def deploy_zyp_repo(path, name, version) # params def deploy_package_repo(path, name, version) if not File.exists? path - @logger.warning "Was asked to deploy package repository from #{path}, but it doesn't exist!" + @logger.warn "Was asked to deploy package repository from #{path}, but it doesn't exist!" return end diff --git a/spec/beaker/host/unix/pkg_spec.rb b/spec/beaker/host/unix/pkg_spec.rb index bd5f9f79f5..004cb55691 100644 --- a/spec/beaker/host/unix/pkg_spec.rb +++ b/spec/beaker/host/unix/pkg_spec.rb @@ -28,8 +28,61 @@ def exec let (:logger) { double( 'logger' ).as_null_object } let (:instance) { UnixPkgTest.new(opts, logger) } - context "check_for_package" do + context 'Package deployment tests' do + path = '/some/file/path' + name = 'package_name' + version = '1.0.0' + + describe '#deploy_package_repo' do + + it 'returns a warning if there is no file at the path specified' do + expect(logger).to receive(:warn) + allow(File).to receive(:exists?).with(path).and_return(false) + instance.deploy_package_repo(path,name,version) + end + + it 'calls #deploy_apt_repo for debian systems' do + @opts = {'platform' => 'ubuntu-is-me'} + expect(instance).to receive(:deploy_apt_repo) + allow(File).to receive(:exists?).with(path).and_return(true) + instance.deploy_package_repo(path,name,version) + end + + it 'calls #deploy_yum_repo for el systems' do + @opts = {'platform' => 'el-is-me'} + expect(instance).to receive(:deploy_yum_repo) + allow(File).to receive(:exists?).with(path).and_return(true) + instance.deploy_package_repo(path,name,version) + end + + it 'calls #deploy_zyp_repo for sles systems' do + @opts = {'platform' => 'sles-is-me'} + expect(instance).to receive(:deploy_zyp_repo) + allow(File).to receive(:exists?).with(path).and_return(true) + instance.deploy_package_repo(path,name,version) + end + it 'raises an error for unsupported systems' do + @opts = {'platform' => 'windows-is-me'} + allow(File).to receive(:exists?).with(path).and_return(true) + expect{instance.deploy_package_repo(path,name,version)}.to raise_error(RuntimeError) + end + end + + describe '#deploy_apt_repo' do + + it 'warns and exits when no codename exists for the debian platform' do + @opts = {'platform' => 'ubuntu-is-me'} + expect(logger).to receive(:warn) + allow(@opts['platform']).to receive(:codename).and_return(nil) + expect(instance).to receive(:deploy_apt_repo).and_return(instance.deploy_apt_repo(path,name,version)) + allow(File).to receive(:exists?).with(path).and_return(true) + instance.deploy_package_repo(path,name,version) + end + end + end + + context "check_for_package" do it "checks correctly on sles" do @opts = {'platform' => 'sles-is-me'} pkg = 'sles_package'