Skip to content

Fix unit tests for yum/dnf provider option change #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions spec/shared_examples/rhel_package_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

it "should call #{provider_name} install for :installed" do
allow(resource).to receive(:should).with(:ensure).and_return(:installed)
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-d', '0', '-e', error_level, '-y', :install, 'mypackage'])
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-y', :install, 'mypackage'])
provider.install
end

Expand All @@ -86,7 +86,7 @@

it "should catch #{provider_name} install failures when status code is wrong" do
allow(resource).to receive(:should).with(:ensure).and_return(:installed)
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-e', error_level, '-y', :install, name]).and_return(Puppet::Util::Execution::ProcessOutput.new("No package #{name} available.", 0))
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-y', :install, name]).and_return(Puppet::Util::Execution::ProcessOutput.new("No package #{name} available.", 0))
expect {
provider.install
}.to raise_error(Puppet::Error, "Could not find package #{name}")
Expand All @@ -102,14 +102,14 @@
it 'should be able to set version' do
version = '1.2'
resource[:ensure] = version
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-d', '0', '-e', error_level, '-y', :install, "#{name}-#{version}"])
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-y', :install, "#{name}-#{version}"])
allow(provider).to receive(:query).and_return(:ensure => version)
provider.install
end
it 'should handle partial versions specified' do
version = '1.3.4'
resource[:ensure] = version
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-d', '0', '-e', error_level, '-y', :install, 'mypackage-1.3.4'])
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-y', :install, 'mypackage-1.3.4'])
allow(provider).to receive(:query).and_return(:ensure => '1.3.4-1.el6')
provider.install
end
Expand All @@ -118,7 +118,7 @@
current_version = '1.2'
version = '1.0'
resource[:ensure] = '1.0'
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-d', '0', '-e', error_level, '-y', :downgrade, "#{name}-#{version}"])
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-y', :downgrade, "#{name}-#{version}"])
allow(provider).to receive(:query).and_return({:ensure => current_version}, {:ensure => version})
provider.install
end
Expand All @@ -127,7 +127,7 @@
current_version = '1.0'
version = '1.2'
resource[:ensure] = '1.2'
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-d', '0', '-e', error_level, '-y', upgrade_command, "#{name}-#{version}"])
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-y', upgrade_command, "#{name}-#{version}"])
allow(provider).to receive(:query).and_return({:ensure => current_version}, {:ensure => version})
provider.install
end
Expand All @@ -136,7 +136,7 @@
current_version = ''
version = '1.2'
resource[:ensure] = :latest
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-d', '0', '-e', error_level, '-y', :install, name])
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-y', :install, name])
allow(provider).to receive(:query).and_return({:ensure => current_version}, {:ensure => version})
provider.install
end
Expand All @@ -145,30 +145,30 @@
current_version = '1.0'
version = '1.2'
resource[:ensure] = :latest
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-d', '0', '-e', error_level, '-y', upgrade_command, name])
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-y', upgrade_command, name])
allow(provider).to receive(:query).and_return({:ensure => current_version}, {:ensure => version})
provider.install
end

it 'should accept install options' do
resource[:ensure] = :installed
resource[:install_options] = ['-t', {'-x' => 'expackage'}]
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-d', '0', '-e', error_level, '-y', ['-t', '-x=expackage'], :install, name])
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-y', ['-t', '-x=expackage'], :install, name])
provider.install
end

it 'allow virtual packages' do
resource[:ensure] = :installed
resource[:allow_virtual] = true
expect(Puppet::Util::Execution).not_to receive(:execute).with(["/usr/bin/#{provider_name}", '-d', '0', '-e', error_level, '-y', :list, name])
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-d', '0', '-e', error_level, '-y', :install, name])
expect(Puppet::Util::Execution).not_to receive(:execute).with(["/usr/bin/#{provider_name}", '-y', :list, name])
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-y', :install, name])
provider.install
end

it 'moves architecture to end of version' do
version = '1.2.3'
arch_resource[:ensure] = version
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-d', '0', '-e', error_level, '-y', :install, "#{name}-#{version}.#{arch}"])
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-y', :install, "#{name}-#{version}.#{arch}"])
allow(arch_provider).to receive(:query).and_return(:ensure => version)
arch_provider.install
end
Expand All @@ -180,7 +180,7 @@
:ensure => version,
:provider =>provider_name
)
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-d', '0', '-e', error_level, '-y', :install, "#{name}-noarch-#{version}"])
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-y', :install, "#{name}-noarch-#{version}"])
provider = provider_class.new
provider.resource = resource
allow(provider).to receive(:query).and_return(:ensure => version)
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/provider/package/dnfmodule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
it "does not try to disable if package is already disabled" do
allow(described_class).to receive(:command).with(:dnf).and_return(dnf_path)
allow(Puppet::Util::Execution).to receive(:execute)
.with("/usr/bin/dnf module list -y -d 0 -e 1")
.with("/usr/bin/dnf module list -y")
.and_return("baz 1.2 [d][x] common [d], complete Package Description")
resource[:ensure] = :disabled
expect(provider).to be_insync(:disabled)
Expand All @@ -254,7 +254,7 @@

it "returns an array of enabled modules" do
allow(Puppet::Util::Execution).to receive(:execute)
.with("/usr/bin/dnf module list -y -d 0 -e 1")
.with("/usr/bin/dnf module list -y")
.and_return(packages)

enabled_packages = described_class.instances.map { |package| package.properties }
Expand Down