Skip to content

Commit

Permalink
backup commit 2016.06.14 10:54
Browse files Browse the repository at this point in the history
  • Loading branch information
ptomulik committed Jun 14, 2016
1 parent e96288c commit c15aa92
Show file tree
Hide file tree
Showing 2 changed files with 242 additions and 6 deletions.
1 change: 0 additions & 1 deletion lib/puppet/util/repoutil.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ def self.package_versions_with_prefixes(prefixes, utils = suitablerepoutils)
def self.package_candidates_with_prefixes(prefixes, utils = suitablerepoutils)
collective_search_hash(:package_candidates_with_prefix, prefixes, utils)
end

end

def self.newrepoutil(name, options = {}, &block)
Expand Down
247 changes: 242 additions & 5 deletions spec/unit/puppet/util/repoutil_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,45 @@
require 'puppet/util/repoutil'

def ruby18?
(Gem::Version.new(RUBY_VERSION) < Gem::Version.new('1.9.0'))
RUBY_VERSION =~ /^1\.8\./
end

describe Puppet::Util do
describe 'newrepoutil' do
let(:block) { Proc.new {} }
it 'should just call Puppet::Util::Repoutils.newrepoutil' do
Puppet::Util::RepoUtils.expects(:newrepoutil).once.with(:foo,:bar).returns(:ok)
expect(described_class.newrepoutil(:foo,:bar,&block)).to equal(:ok)
end
end
describe 'repoutil' do
let(:block) { Proc.new {} }
it 'should just call Puppet::Util::Repoutils.repoutil' do
Puppet::Util::RepoUtils.expects(:repoutil).once.with(:foo).returns(:ok)
expect(described_class.repoutil(:foo)).to equal(:ok)
end
end
describe 'repoutils' do
let(:block) { Proc.new {} }
it 'should just call Puppet::Util::Repoutils.repoutils' do
Puppet::Util::RepoUtils.expects(:repoutils).once.with().returns(:ok)
expect(described_class.repoutils).to equal(:ok)
end
end
describe 'suitablerepoutils' do
let(:block) { Proc.new {} }
it 'should just call Puppet::Util::Repoutils.suitablerepoutils' do
Puppet::Util::RepoUtils.expects(:suitablerepoutils).once.with().returns(:ok)
expect(described_class.suitablerepoutils).to equal(:ok)
end
end
describe 'defaultrepoutil' do
let(:block) { Proc.new {} }
it 'should just call Puppet::Util::Repoutils.defaultrepoutil' do
Puppet::Util::RepoUtils.expects(:defaultrepoutil).once.with().returns(:ok)
expect(described_class.defaultrepoutil).to equal(:ok)
end
end
end

describe Puppet::Util::RepoUtils do
Expand Down Expand Up @@ -286,7 +324,7 @@ def self.name; :geez; end } }
expect(described_class.collective_query(:opname, :subject, [])).to eql({})
end
end
context 'with non-empty utils' do
context 'with custom utils' do
let(:util1) do
Class.new(Puppet::Util::RepoUtil) do
def self.name; :util1; end
Expand All @@ -309,16 +347,215 @@ def self.package_versions(package)
end
end
end
it 'bla bla' do
let(:util3) do
Class.new(Puppet::Util::RepoUtil) do
def self.name; :util3; end
def self.package_versions(package)
case package
when 'bash'; return [ '4.3-12' ]
end
end
end
end
before(:each) do
described_class.stubs(:repoutil).with(:util1).returns(util1)
described_class.stubs(:repoutil).with(:util2).returns(util2)
described_class.stubs(:repoutil).with(:util3).returns(util3)
end
it 'returns results collected from particular utils' do
packages = ['apache', 'bash', 'alsa-base', 'foo']
utils = [util1, util2]
utils = [util1, :util2, 'util3']
expect(described_class.collective_query(:package_versions, packages, utils)).to eql({
:util1 => { 'apache' => ['2.2', '2.4'], 'bash' => [ '4.3-11', '4.3-14' ] },
:util2 => { 'apache' => ['2.4', '2.6'], 'alsa-base' => ['1.0.27+1'] }
:util2 => { 'apache' => ['2.4', '2.6'], 'alsa-base' => ['1.0.27+1'] },
:util3 => { 'bash' => ['4.3-12'] }
})
end
end
end

describe 'collective_search_hash' do
context 'with utils=[]' do
it 'should return an empty hash' do
expect(described_class.collective_query(:opname, :subject, [])).to eql({})
end
end
context 'with custom utils' do
let(:util1) do
Class.new(Puppet::Util::RepoUtil) do
def self.name; :util1; end
def self.package_versions_with_prefix(package)
case package
when 'apache'; return { 'apache22' => ['2.2.14' ], 'apache24' => ['2.4.28'] }
when 'bash'; return { 'bash' => ['4.3-11', '4.3-14' ] }
else return {}
end
end
end
end
let(:util2) do
Class.new(Puppet::Util::RepoUtil) do
def self.name; :util2; end
def self.package_versions_with_prefix(package)
case package
when 'apache'; return { 'apache' => [ '2.4', '2.6' ] }
when 'alsa-base'; return { 'alsa-base' => [ '1.0.27+1' ] }
else return {}
end
end
end
end
let(:util3) do
Class.new(Puppet::Util::RepoUtil) do
def self.name; :util3; end
def self.package_versions_with_prefix(package)
case package
when 'bash'; return { 'bash' => [ '4.3-12' ] }
else return {}
end
end
end
end
before(:each) do
described_class.stubs(:repoutil).with(:util1).returns(util1)
described_class.stubs(:repoutil).with(:util2).returns(util2)
described_class.stubs(:repoutil).with(:util3).returns(util3)
end
it 'returns results collected from particular utils' do
packages = ['apache', 'bash', 'alsa-base', 'foo']
utils = [util1, :util2, 'util3']
expect(described_class.collective_search_hash(:package_versions_with_prefix, packages, utils)).to eql({
:util1 => { 'apache22' => ['2.2.14'], 'apache24' => ['2.4.28'], 'bash' => [ '4.3-11', '4.3-14' ] },
:util2 => { 'apache' => ['2.4', '2.6'], 'alsa-base' => ['1.0.27+1'] },
:util3 => { 'bash' => ['4.3-12'] }
})
end
end
end

describe 'collective_search_array' do
context 'with utils=[]' do
it 'should return an empty hash' do
expect(described_class.collective_query(:opname, :subject, [])).to eql({})
end
end
context 'with custom utils' do
let(:util1) do
Class.new(Puppet::Util::RepoUtil) do
def self.name; :util1; end
def self.packages_with_prefix(package)
case package
when 'apache'; return [ 'apache22', 'apache24' ]
when 'bash'; return [ 'bash' ]
else return []
end
end
end
end
let(:util2) do
Class.new(Puppet::Util::RepoUtil) do
def self.name; :util2; end
def self.packages_with_prefix(package)
case package
when 'apache'; return [ 'apache' ]
when 'alsa-base'; return [ 'alsa-base' ]
else return []
end
end
end
end
let(:util3) do
Class.new(Puppet::Util::RepoUtil) do
def self.name; :util3; end
def self.packages_with_prefix(package)
case package
when 'bash'; return [ 'bash' ]
else return []
end
end
end
end
before(:each) do
described_class.stubs(:repoutil).with(:util1).returns(util1)
described_class.stubs(:repoutil).with(:util2).returns(util2)
described_class.stubs(:repoutil).with(:util3).returns(util3)
end
it 'returns results collected from particular utils' do
packages = ['apache', 'bash', 'alsa-base', 'foo']
utils = [util1, :util2, 'util3']
expect(described_class.collective_search_array(:packages_with_prefix, packages, utils)).to eql({
:util1 => [ 'apache22', 'apache24', 'bash' ],
:util2 => [ 'apache', 'alsa-base' ],
:util3 => [ 'bash' ]
})
end
end
end

[ :package_records,
:package_versions,
:package_candidates ].each do |m|
describe "#{m}" do
context 'with default utils' do
let(:utils) { [ Class.new ] }
before(:each) { described_class.stubs(:suitablerepoutils).returns(utils) }
it "just invokes collective_query(#{m.inspect}, arg, suitableutils)" do
described_class.expects(:collective_query).once.with(m, :arg, utils).returns(:ok)
expect(described_class.method(m).call(:arg)).to equal(:ok)
end
end
context 'with non-default utils' do
it "just invokes collective_query(#{m.inspect}, arg, utils)" do
described_class.expects(:collective_query).once.with(m, :arg, :utils).returns(:ok)
expect(described_class.method(m).call(:arg, :utils)).to equal(:ok)
end
end
end
end

{
:packages_with_prefixes => :packages_with_prefix
}.each do |m,n|
describe "#{m}" do
context 'with default utils' do
let(:utils) { [ Class.new ] }
before(:each) { described_class.stubs(:suitablerepoutils).returns(utils) }
it "just invokes collective_query(#{m.inspect}, arg, suitableutils)" do
described_class.expects(:collective_search_array).once.with(n, :arg, utils).returns(:ok)
expect(described_class.method(m).call(:arg)).to equal(:ok)
end
end
context 'with non-default utils' do
it "just invokes collective_query(#{m.inspect}, arg, utils)" do
described_class.expects(:collective_search_array).once.with(n, :arg, :utils).returns(:ok)
expect(described_class.method(m).call(:arg, :utils)).to equal(:ok)
end
end
end
end

{
:package_records_with_prefixes => :package_records_with_prefix,
:package_versions_with_prefixes => :package_versions_with_prefix,
:package_candidates_with_prefixes => :package_candidates_with_prefix
}.each do |m,n|
describe "#{m}" do
context 'with default utils' do
let(:utils) { [ Class.new ] }
before(:each) { described_class.stubs(:suitablerepoutils).returns(utils) }
it "just invokes collective_query(#{m.inspect}, arg, suitableutils)" do
described_class.expects(:collective_search_hash).once.with(n, :arg, utils).returns(:ok)
expect(described_class.method(m).call(:arg)).to equal(:ok)
end
end
context 'with non-default utils' do
it "just invokes collective_query(#{m.inspect}, arg, utils)" do
described_class.expects(:collective_search_hash).once.with(n, :arg, :utils).returns(:ok)
expect(described_class.method(m).call(:arg, :utils)).to equal(:ok)
end
end
end
end
end

describe Puppet::Util::RepoUtil do
Expand Down

0 comments on commit c15aa92

Please sign in to comment.