From 99f6abcea721c04ca49c50d43251a9a29fced3fb Mon Sep 17 00:00:00 2001 From: Noah Kantrowitz Date: Tue, 17 Apr 2018 20:47:40 -0700 Subject: [PATCH] Update tests for Chef 14. --- test/spec/scl/mixin_spec.rb | 6 +++--- test/spec/system/mixin_spec.rb | 6 +++--- test/spec/system/resource_spec.rb | 27 +++++++++++++++++++-------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/test/spec/scl/mixin_spec.rb b/test/spec/scl/mixin_spec.rb index 4b9efc4..0d0f468 100644 --- a/test/spec/scl/mixin_spec.rb +++ b/test/spec/scl/mixin_spec.rb @@ -86,7 +86,7 @@ def action_run end # /describe #scl_package describe '#scl_folder' do - let(:test_provider) { provider(:poise_test).new(nil, nil) } + let(:test_provider) { provider(:poise_test).new(resource(:poise_test).new('test'), nil) } subject { test_provider.send(:scl_folder) } before do allow(test_provider).to receive(:scl_package).and_return({name: 'python34'}) @@ -96,7 +96,7 @@ def action_run end # /describe #scl_folder describe '#scl_environment' do - let(:test_provider) { provider(:poise_test).new(nil, nil) } + let(:test_provider) { provider(:poise_test).new(resource(:poise_test).new('test'), nil) } subject { test_provider.send(:scl_environment) } before do allow(test_provider).to receive(:scl_package).and_return({name: 'python34'}) @@ -114,7 +114,7 @@ def action_run allow(File).to receive(:exist?).with('/test/enable').and_return(true) allow(IO).to receive(:readlines).with('/test/enable').and_return(content.split(/\n/)) end - subject { provider(:poise_test).new(nil, nil).send(:parse_enable_file, '/test/enable') } + subject { provider(:poise_test).new(resource(:poise_test).new('test'), nil).send(:parse_enable_file, '/test/enable') } context 'with an empty file' do it { is_expected.to eq({}) } diff --git a/test/spec/system/mixin_spec.rb b/test/spec/system/mixin_spec.rb index 5e54604..24e3e66 100644 --- a/test/spec/system/mixin_spec.rb +++ b/test/spec/system/mixin_spec.rb @@ -114,14 +114,14 @@ def action_run end # /describe #uninstall_system_packages describe '#system_package_candidates' do - subject { provider(:poise_test).new(nil, nil).send(:system_package_candidates, '') } + subject { provider(:poise_test).new(resource(:poise_test).new('test'), nil).send(:system_package_candidates, '') } it { expect { subject }.to raise_error NotImplementedError } end # /describe #system_package_candidates describe '#system_package_name' do let(:chefspec_options) { {platform: 'debian', version: '7.11'} } let(:version) { '' } - let(:test_provider) { provider(:poise_test).new(nil, chef_run.run_context) } + let(:test_provider) { provider(:poise_test).new(resource(:poise_test).new('test'), chef_run.run_context) } provider(:poise_test) do include described_class packages('python', { @@ -184,7 +184,7 @@ def system_package_candidates(version) end # /describe #system_package_name describe '#system_dev_package_overrides' do - subject { provider(:poise_test).new(nil, nil).send(:system_dev_package_overrides) } + subject { provider(:poise_test).new(resource(:poise_test).new('test'), nil).send(:system_dev_package_overrides) } it { is_expected.to eq({}) } end # /describe #system_dev_package_overrides diff --git a/test/spec/system/resource_spec.rb b/test/spec/system/resource_spec.rb index 021a471..22e3232 100644 --- a/test/spec/system/resource_spec.rb +++ b/test/spec/system/resource_spec.rb @@ -158,14 +158,25 @@ context 'on CentOS' do let(:chefspec_options) { {platform: 'centos', version: '7.3.1611'} } before do - yum_cache = double('YumCache') - allow(yum_cache).to receive(:yum_binary=) - allow(yum_cache).to receive(:disable_extra_repo_control) - allow(yum_cache).to receive(:package_available?).and_return(false) - allow(yum_cache).to receive(:package_available?).with(/^mylang(-devel)?$/).and_return(true) - allow(yum_cache).to receive(:installed_version).with(/^mylang(-devel)?$/, nil).and_return(nil) - allow(yum_cache).to receive(:candidate_version).with(/^mylang(-devel)?$/, nil).and_return('1.2.3') - allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(yum_cache) + if defined?(Chef::Provider::Package::Yum::PythonHelper.instance) + # New-fangled PythonHelper (Chef 14+). + python_helper = double('PythonHelper') + allow(Chef::Provider::Package::Yum::PythonHelper).to receive(:instance).and_return(python_helper) + allow(python_helper).to receive(:package_query).with(:whatinstalled, 'mylang', version: nil, arch: nil).and_return(Chef::Provider::Package::Yum::Version.new('mylang', nil, nil)) + allow(python_helper).to receive(:package_query).with(:whatinstalled, 'mylang-devel', version: nil, arch: nil).and_return(Chef::Provider::Package::Yum::Version.new('mylang-devel', nil, nil)) + allow(python_helper).to receive(:package_query).with(:whatavailable, 'mylang', version: nil, arch: nil, options: nil).and_return(Chef::Provider::Package::Yum::Version.new('mylang', '0:1.2.3.el7', 'i386')) + allow(python_helper).to receive(:package_query).with(:whatavailable, 'mylang-devel', version: nil, arch: nil, options: nil).and_return(Chef::Provider::Package::Yum::Version.new('mylang-devel', '0:1.2.3.el7', 'i386')) + else + # Old-school yum cache. + yum_cache = double('YumCache') + allow(yum_cache).to receive(:yum_binary=) + allow(yum_cache).to receive(:disable_extra_repo_control) + allow(yum_cache).to receive(:package_available?).and_return(false) + allow(yum_cache).to receive(:package_available?).with(/^mylang(-devel)?$/).and_return(true) + allow(yum_cache).to receive(:installed_version).with(/^mylang(-devel)?$/, nil).and_return(nil) + allow(yum_cache).to receive(:candidate_version).with(/^mylang(-devel)?$/, nil).and_return('1.2.3') + allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(yum_cache) + end end context 'action :install' do