diff --git a/lib/puppet/provider/package/openbsd.rb b/lib/puppet/provider/package/openbsd.rb index c230fe41099..5cadfc4daa5 100644 --- a/lib/puppet/provider/package/openbsd.rb +++ b/lib/puppet/provider/package/openbsd.rb @@ -6,22 +6,24 @@ Puppet::Type.type(:package).provide :openbsd, :parent => Puppet::Provider::Package do desc "OpenBSD's form of `pkg_add` support. + OpenBSD has the concept of package branches, providing multiple versions of the + same package, i.e. `stable` vs. `snapshot`. To select a specific branch, + suffix the package name with % sign follwed by the branch name, i.e. `gimp%stable`. + This provider supports the `install_options` and `uninstall_options` attributes, which allow command-line flags to be passed to pkg_add and pkg_delete. These options should be specified as an array where each element is either a string or a hash." - commands :pkginfo => "pkg_info", - :pkgadd => "pkg_add", + commands :pkgadd => "pkg_add", + :pkginfo => "pkg_info", :pkgdelete => "pkg_delete" defaultfor 'os.name' => :openbsd confine 'os.name' => :openbsd - has_feature :versionable has_feature :install_options has_feature :uninstall_options - has_feature :upgradeable has_feature :supports_flavors def self.instances @@ -30,20 +32,21 @@ def self.instances begin execpipe(listcmd) do |process| # our regex for matching pkg_info output - regex = /^(.*)-(\d[^-]*)-?([\w-]*)(.*)$/ - fields = [:name, :ensure, :flavor] + regex = /^(.*)--([\w-]+)?(%[^w]+)?$/ + fields = [:name, :flavor, :branch] hash = {} # now turn each returned line into a package object process.each_line { |line| - match = regex.match(line.split[0]) + match = regex.match(line.split("\n")[0]) if match fields.zip(match.captures) { |field, value| hash[field] = value } - hash[:provider] = name + hash[:name] = "#{hash[:name]}#{hash[:branch]}" if hash[:branch] + hash[:provider] = name packages << new(hash) hash = {} else @@ -63,175 +66,55 @@ def self.instances end def self.listcmd - [command(:pkginfo), "-a"] - end - - def latest - parse_pkgconf - - if @resource[:source][-1, 1] == ::File::SEPARATOR - e_vars = { 'PKG_PATH' => @resource[:source] } - else - e_vars = {} - end - - if @resource[:flavor] - query = "#{@resource[:name]}--#{@resource[:flavor]}" - else - query = @resource[:name] - end - - output = Puppet::Util.withenv(e_vars) { pkginfo "-Q", query } - version = properties[:ensure] - - if output.nil? or output.size == 0 or output =~ /Error from / - debug "Failed to query for #{resource[:name]}" - return version - else - # Remove all fuzzy matches first. - output = output.split.select { |p| p =~ /^#{resource[:name]}-(\d[^-]*)-?(\w*)/ }.join - debug "pkg_info -Q for #{resource[:name]}: #{output}" - end - - if output =~ /^#{resource[:name]}-(\d[^-]*)-?(\w*) \(installed\)$/ - debug "Package is already the latest available" - version - else - match = /^(.*)-(\d[^-]*)-?(\w*)$/.match(output) - debug "Latest available for #{resource[:name]}: #{match[2]}" - - if version.to_sym == :absent || version.to_sym == :purged - return match[2] - end - - vcmp = version.split('.').map(&:to_i) <=> match[2].split('.').map(&:to_i) - if vcmp > 0 - # The locally installed package may actually be newer than what a mirror - # has. Log it at debug, but ignore it otherwise. - debug "Package #{resource[:name]} #{version} newer then available #{match[2]}" - version - else - match[2] - end - end + [command(:pkginfo), "-a", "-z"] end - def update - install(true) - end - - def parse_pkgconf - unless @resource[:source] - if Puppet::FileSystem.exist?("/etc/pkg.conf") - File.open("/etc/pkg.conf", "rb").readlines.each do |line| - matchdata = line.match(/^installpath\s*=\s*(.+)\s*$/i) - if matchdata - @resource[:source] = matchdata[1] - else - matchdata = line.match(/^installpath\s*\+=\s*(.+)\s*$/i) - if matchdata - if @resource[:source].nil? - @resource[:source] = matchdata[1] - else - @resource[:source] += ":" + matchdata[1] - end - end - end - end - - unless @resource[:source] - raise Puppet::Error, - _("No valid installpath found in /etc/pkg.conf and no source was set") - end - else - raise Puppet::Error, - _("You must specify a package source or configure an installpath in /etc/pkg.conf") - end - end - end - - def install(latest = false) + def install cmd = [] - parse_pkgconf - - if @resource[:source][-1, 1] == ::File::SEPARATOR - e_vars = { 'PKG_PATH' => @resource[:source] } - full_name = get_full_name(latest) - else - e_vars = {} - full_name = @resource[:source] - end + full_name = get_full_name + cmd << '-r' cmd << install_options cmd << full_name - if latest - cmd.unshift('-rz') + # pkg_add(1) doesn't set the return value upon failure so we have to peek + # at it's output to see if something went wrong. + output = Puppet::Util.withenv({}) { pkgadd cmd.flatten.compact } + if output =~ /Can't find / + self.fail "pkg_add returned: #{output.chomp}" end - - Puppet::Util.withenv(e_vars) { pkgadd cmd.flatten.compact } end - def get_full_name(latest = false) + def get_full_name # In case of a real update (i.e., the package already exists) then # pkg_add(8) can handle the flavors. However, if we're actually # installing with 'latest', we do need to handle the flavors. This is # done so we can feed pkg_add(8) the full package name to install to # prevent ambiguity. - if latest && resource[:flavor] - "#{resource[:name]}--#{resource[:flavor]}" - elsif latest - # Don't depend on get_version for updates. - @resource[:name] - else - # If :ensure contains a version, use that instead of looking it up. - # This allows for installing packages with the same stem, but multiple - # version such as openldap-server. - if @resource[:ensure].to_s =~ /(\d[^-]*)$/ - use_version = @resource[:ensure] - else - use_version = get_version - end - [@resource[:name], use_version, @resource[:flavor]].join('-').gsub(/-+$/, '') + name_branch_regex = /^(\S*)(%\w*)$/ + match = name_branch_regex.match(@resource[:name]) + if match + use_name = match.captures[0] + use_branch = match.captures[1] + else + use_name = @resource[:name] + use_branch = '' end - end - - def get_version - execpipe([command(:pkginfo), "-I", @resource[:name]]) do |process| - # our regex for matching pkg_info output - regex = /^(.*)-(\d[^-]*)-?(\w*)(.*)$/ - master_version = 0 - version = -1 - - process.each_line do |line| - match = regex.match(line.split[0]) - next unless match - - # now we return the first version, unless ensure is latest - version = match.captures[1] - return version unless @resource[:ensure] == "latest" - - master_version = version unless master_version > version - end - - return master_version unless master_version == 0 - return '' if version == -1 - raise Puppet::Error, _("%{version} is not available for this package") % { version: version } + if @resource[:flavor] + "#{use_name}--#{@resource[:flavor]}#{use_branch}" + else + "#{use_name}--#{use_branch}" end - rescue Puppet::ExecutionFailure - nil end def query - # Search for the version info - if pkginfo(@resource[:name]) =~ /Information for (inst:)?#{@resource[:name]}-(\S+)/ - { :ensure => Regexp.last_match(2) } - else - nil + pkg = self.class.instances.find do |package| + @resource[:name] == package.name end + pkg ? pkg.properties : nil end def install_options @@ -239,15 +122,15 @@ def install_options end def uninstall_options - join_options(resource[:uninstall_options]) + join_options(resource[:uninstall_options]) || [] end def uninstall - pkgdelete uninstall_options.flatten.compact, @resource[:name] + pkgdelete uninstall_options.flatten.compact, get_full_name end def purge - pkgdelete "-c", "-q", @resource[:name] + pkgdelete "-c", "-qq", uninstall_options.flatten.compact, get_full_name end def flavor @@ -256,7 +139,6 @@ def flavor def flavor=(value) if flavor != @resource.should(:flavor) - uninstall install end end diff --git a/spec/fixtures/unit/provider/package/openbsd/pkginfo.detail b/spec/fixtures/unit/provider/package/openbsd/pkginfo.detail deleted file mode 100644 index 5879a2abe61..00000000000 --- a/spec/fixtures/unit/provider/package/openbsd/pkginfo.detail +++ /dev/null @@ -1,19 +0,0 @@ -Information for bash-3.1.17 - -Comment: -GNU Bourne Again Shell - -Description: -Bash is the GNU Project's Bourne Again SHell, an sh-compatible -command language interpreter that executes commands read from the -standard input or from a file. Bash also incorporates useful -features from the Korn and C shells (ksh and csh). - -Bash is intended to be a conformant implementation of the IEEE POSIX -Shell and Tools specification (IEEE Working Group 1003.2). - -Maintainer: Christian Weisgerber - -WWW: http://cnswww.cns.cwru.edu/~chet/bash/bashtop.html - - diff --git a/spec/fixtures/unit/provider/package/openbsd/pkginfo.list b/spec/fixtures/unit/provider/package/openbsd/pkginfo.list index 5f4866aa133..936cffc38e2 100644 --- a/spec/fixtures/unit/provider/package/openbsd/pkginfo.list +++ b/spec/fixtures/unit/provider/package/openbsd/pkginfo.list @@ -1,10 +1,6 @@ -bash-3.1.17 GNU Bourne Again Shell -bzip2-1.0.3 block-sorting file compressor, unencumbered -expat-2.0.0 XML 1.0 parser written in C -gettext-0.14.5p1 GNU gettext -libiconv-1.9.2p3 character set conversion library -lzo-1.08p1 portable speedy lossless data compression library -openvpn-2.0.6 easy-to-use, robust, and highly configurable VPN -python-2.4.3p0 interpreted object-oriented programming language -vim-7.0.42-no_x11 vi clone, many additional features -wget-1.10.2p0 retrieve files from the web via HTTP, HTTPS and FTP +autoconf--%2.13 +autoconf--%2.56 +bash-- +postfix--ldap%stable +puppet--%8 +zstd-- diff --git a/spec/fixtures/unit/provider/package/openbsd/pkginfo.query b/spec/fixtures/unit/provider/package/openbsd/pkginfo.query deleted file mode 100644 index d79aecfa309..00000000000 --- a/spec/fixtures/unit/provider/package/openbsd/pkginfo.query +++ /dev/null @@ -1 +0,0 @@ -bash-3.1.17 GNU Bourne Again Shell diff --git a/spec/fixtures/unit/provider/package/openbsd/pkginfo_flavors.list b/spec/fixtures/unit/provider/package/openbsd/pkginfo_flavors.list deleted file mode 100644 index 1ed49a5ebed..00000000000 --- a/spec/fixtures/unit/provider/package/openbsd/pkginfo_flavors.list +++ /dev/null @@ -1,2 +0,0 @@ -bash-3.1.17-static GNU Bourne Again Shell -vim-7.0.42-no_x11 vi clone, many additional features diff --git a/spec/unit/provider/package/openbsd_spec.rb b/spec/unit/provider/package/openbsd_spec.rb index 8717da3c36b..3248c1683f0 100644 --- a/spec/unit/provider/package/openbsd_spec.rb +++ b/spec/unit/provider/package/openbsd_spec.rb @@ -2,42 +2,16 @@ require 'stringio' describe Puppet::Type.type(:package).provider(:openbsd) do + include PuppetSpec::Fixtures + let(:package) { Puppet::Type.type(:package).new(:name => 'bash', :provider => 'openbsd') } let(:provider) { described_class.new(package) } - def expect_read_from_pkgconf(lines) - pkgconf = double(:readlines => lines) - expect(Puppet::FileSystem).to receive(:exist?).with('/etc/pkg.conf').and_return(true) - expect(File).to receive(:open).with('/etc/pkg.conf', 'rb').and_return(pkgconf) - end - - def expect_pkgadd_with_source(source) - expect(provider).to receive(:pkgadd).with([source]) do - expect(ENV).not_to have_key('PKG_PATH') - end - end - - def expect_pkgadd_with_env_and_name(source, &block) - expect(ENV).not_to have_key('PKG_PATH') - - expect(provider).to receive(:pkgadd).with([provider.resource[:name]]) do - expect(ENV).to have_key('PKG_PATH') - expect(ENV['PKG_PATH']).to eq(source) - end - expect(provider).to receive(:execpipe).with(['/bin/pkg_info', '-I', provider.resource[:name]]).and_yield('') - - yield - - expect(ENV).not_to be_key('PKG_PATH') - end - context 'provider features' do it { is_expected.to be_installable } it { is_expected.to be_install_options } it { is_expected.to be_uninstallable } it { is_expected.to be_uninstall_options } - it { is_expected.to be_upgradeable } - it { is_expected.to be_versionable } end before :each do @@ -46,295 +20,91 @@ def expect_pkgadd_with_env_and_name(source, &block) allow(described_class).to receive(:command).with(:pkginfo).and_return('/bin/pkg_info') allow(described_class).to receive(:command).with(:pkgadd).and_return('/bin/pkg_add') allow(described_class).to receive(:command).with(:pkgdelete).and_return('/bin/pkg_delete') - - allow(Puppet::FileSystem).to receive(:exist?) end context "#instances" do it "should return nil if execution failed" do - expect(described_class).to receive(:execpipe).and_raise(Puppet::ExecutionFailure, 'wawawa') + #expect(provider).to receive(:pkginfo).and_raise(Puppet::ExecutionFailure, 'wawawa') + #expect(provider).to receive(:pkginfo).with(['-a', '-z']) expect(described_class.instances).to be_nil end it "should return the empty set if no packages are listed" do - expect(described_class).to receive(:execpipe).with(%w{/bin/pkg_info -a}).and_yield(StringIO.new('')) + expect(described_class).to receive(:execpipe).with(%w{/bin/pkg_info -a -z}).and_yield(StringIO.new('')) expect(described_class.instances).to be_empty end it "should return all packages when invoked" do fixture = File.read(my_fixture('pkginfo.list')) - expect(described_class).to receive(:execpipe).with(%w{/bin/pkg_info -a}).and_yield(fixture) + expect(described_class).to receive(:execpipe).with(%w{/bin/pkg_info -a -z}).and_yield(fixture) expect(described_class.instances.map(&:name).sort).to eq( - %w{bash bzip2 expat gettext libiconv lzo openvpn python vim wget}.sort + %w{autoconf%2.13 autoconf%2.56 bash postfix%stable puppet%8 zstd}.sort ) end it "should return all flavors if set" do - fixture = File.read(my_fixture('pkginfo_flavors.list')) - expect(described_class).to receive(:execpipe).with(%w{/bin/pkg_info -a}).and_yield(fixture) + fixture = File.read(my_fixture('pkginfo.list')) + expect(described_class).to receive(:execpipe).with(%w{/bin/pkg_info -a -z}).and_yield(fixture) instances = described_class.instances.map {|p| {:name => p.get(:name), - :ensure => p.get(:ensure), :flavor => p.get(:flavor)}} - expect(instances.size).to eq(2) - expect(instances[0]).to eq({:name => 'bash', :ensure => '3.1.17', :flavor => 'static'}) - expect(instances[1]).to eq({:name => 'vim', :ensure => '7.0.42', :flavor => 'no_x11'}) + :flavor => p.get(:flavor), :branch => p.get(:branch)}} + expect(instances.size).to eq(6) + expect(instances[0]).to eq({:name => 'autoconf%2.13', :flavor => :absent, :branch => '%2.13'}) + expect(instances[1]).to eq({:name => 'autoconf%2.56', :flavor => :absent, :branch => '%2.56'}) + expect(instances[2]).to eq({:name => 'bash', :flavor => :absent, :branch => :absent}) + expect(instances[3]).to eq({:name => 'postfix%stable', :flavor => 'ldap', :branch => '%stable'}) + expect(instances[4]).to eq({:name => 'puppet%8', :flavor => :absent, :branch => '%8'}) + expect(instances[5]).to eq({:name => 'zstd', :flavor => :absent, :branch => :absent}) end end context "#install" do - it "should fail if the resource doesn't have a source" do - expect(Puppet::FileSystem).to receive(:exist?).with('/etc/pkg.conf').and_return(false) - - expect { - provider.install - }.to raise_error(Puppet::Error, /must specify a package source/) - end - - it "should fail if /etc/pkg.conf exists, but is not readable" do - expect(Puppet::FileSystem).to receive(:exist?).with('/etc/pkg.conf').and_return(true) - expect(File).to receive(:open).with('/etc/pkg.conf', 'rb').and_raise(Errno::EACCES) - - expect { - provider.install - }.to raise_error(Errno::EACCES, /Permission denied/) - end - - it "should fail if /etc/pkg.conf exists, but there is no installpath" do - expect_read_from_pkgconf([]) - expect { - provider.install - }.to raise_error(Puppet::Error, /No valid installpath found in \/etc\/pkg\.conf and no source was set/) - end - - it "should install correctly when given a directory-unlike source" do - source = '/whatever.tgz' - provider.resource[:source] = source - expect_pkgadd_with_source(source) - - provider.install - end - - it "should install correctly when given a directory-like source" do - source = '/whatever/' - provider.resource[:source] = source - expect_pkgadd_with_env_and_name(source) do - provider.install - end - end - - it "should install correctly when given a CDROM installpath" do - dir = '/mnt/cdrom/5.2/packages/amd64/' - expect_read_from_pkgconf(["installpath = #{dir}"]) - expect_pkgadd_with_env_and_name(dir) do - provider.install - end - end - - it "should install correctly when given a ftp mirror" do - url = 'ftp://your.ftp.mirror/pub/OpenBSD/5.2/packages/amd64/' - expect_read_from_pkgconf(["installpath = #{url}"]) - expect_pkgadd_with_env_and_name(url) do - provider.install - end - end - - it "should set the resource's source parameter" do - url = 'ftp://your.ftp.mirror/pub/OpenBSD/5.2/packages/amd64/' - expect_read_from_pkgconf(["installpath = #{url}"]) - expect_pkgadd_with_env_and_name(url) do - provider.install - end - - expect(provider.resource[:source]).to eq(url) - end - - it "should strip leading whitespace in installpath" do - dir = '/one/' - lines = ["# Notice the extra spaces after the ='s\n", - "installpath = #{dir}\n", - "# And notice how each line ends with a newline\n"] - - expect_read_from_pkgconf(lines) - expect_pkgadd_with_env_and_name(dir) do - provider.install - end - end - - it "should not require spaces around the equals" do - dir = '/one/' - lines = ["installpath=#{dir}"] - - expect_read_from_pkgconf(lines) - expect_pkgadd_with_env_and_name(dir) do - provider.install - end - end - - it "should be case-insensitive" do - dir = '/one/' - lines = ["INSTALLPATH = #{dir}"] - - expect_read_from_pkgconf(lines) - expect_pkgadd_with_env_and_name(dir) do - provider.install - end - end - - it "should ignore unknown keywords" do - dir = '/one/' - lines = ["foo = bar\n", - "installpath = #{dir}\n"] - - expect_read_from_pkgconf(lines) - expect_pkgadd_with_env_and_name(dir) do - provider.install - end - end - - it "should preserve trailing spaces" do - dir = '/one/ ' - lines = ["installpath = #{dir}"] - - expect_read_from_pkgconf(lines) - expect_pkgadd_with_source(dir) - - provider.install - end - - it "should append installpath" do - urls = ["ftp://your.ftp.mirror/pub/OpenBSD/5.2/packages/amd64/", - "http://another.ftp.mirror/pub/OpenBSD/5.2/packages/amd64/"] - lines = ["installpath = #{urls[0]}\n", - "installpath += #{urls[1]}\n"] - - expect_read_from_pkgconf(lines) - expect_pkgadd_with_env_and_name(urls.join(":")) do - provider.install - end - end - - it "should handle append on first installpath" do - url = "ftp://your.ftp.mirror/pub/OpenBSD/5.2/packages/amd64/" - lines = ["installpath += #{url}\n"] - - expect_read_from_pkgconf(lines) - expect_pkgadd_with_env_and_name(url) do - provider.install - end - end - - %w{ installpath installpath= installpath+=}.each do |line| - it "should reject '#{line}'" do - expect_read_from_pkgconf([line]) - expect { - provider.install - }.to raise_error(Puppet::Error, /No valid installpath found in \/etc\/pkg\.conf and no source was set/) - end - end - it 'should use install_options as Array' do - provider.resource[:source] = '/tma1/' - provider.resource[:install_options] = ['-r', '-z'] - expect(provider).to receive(:pkgadd).with(['-r', '-z', 'bash']) + provider.resource[:install_options] = ['-z'] + expect(provider).to receive(:pkgadd).with(['-r', '-z', 'bash--']) provider.install end end - context "#latest" do - before do - provider.resource[:source] = '/tmp/tcsh.tgz' - provider.resource[:name] = 'tcsh' - allow(provider).to receive(:pkginfo).with('tcsh') - end - - it "should return the ensure value if the package is already installed" do - allow(provider).to receive(:properties).and_return({:ensure => '4.2.45'}) - allow(provider).to receive(:pkginfo).with('-Q', 'tcsh') - expect(provider.latest).to eq('4.2.45') - end - - it "should recognize a new version" do - pkginfo_query = 'tcsh-6.18.01p1' - allow(provider).to receive(:pkginfo).with('-Q', 'tcsh').and_return(pkginfo_query) - expect(provider.latest).to eq('6.18.01p1') - end - - it "should recognize a newer version" do - allow(provider).to receive(:properties).and_return({:ensure => '1.6.8'}) - pkginfo_query = 'tcsh-1.6.10' - allow(provider).to receive(:pkginfo).with('-Q', 'tcsh').and_return(pkginfo_query) - expect(provider.latest).to eq('1.6.10') - end - - it "should recognize a package that is already the newest" do - pkginfo_query = 'tcsh-6.18.01p0 (installed)' - allow(provider).to receive(:pkginfo).with('-Q', 'tcsh').and_return(pkginfo_query) - expect(provider.latest).to eq('6.18.01p0') - end - end - context "#get_full_name" do - it "should return the full unversioned package name when updating with a flavor" do - provider.resource[:ensure] = 'latest' + it "should return the full unversioned package name when installing with a flavor" do + provider.resource[:ensure] = 'present' provider.resource[:flavor] = 'static' expect(provider.get_full_name).to eq('bash--static') end - it "should return the full unversioned package name when updating without a flavor" do - provider.resource[:name] = 'puppet' - provider.resource[:ensure] = 'latest' - expect(provider.get_full_name).to eq('puppet') - end - - it "should use the ensure parameter if it is numeric" do - provider.resource[:name] = 'zsh' - provider.resource[:ensure] = '1.0' - expect(provider.get_full_name).to eq('zsh-1.0') - end - - it "should lookup the correct version" do - output = 'bash-3.1.17 GNU Bourne Again Shell' - expect(provider).to receive(:execpipe).with(%w{/bin/pkg_info -I bash}).and_yield(output) - expect(provider.get_full_name).to eq('bash-3.1.17') + it "should return the full unversioned package name when installing with a branch" do + provider.resource[:name] = 'bash%stable' + expect(provider.get_full_name).to eq('bash--%stable') end - it "should lookup the correction version with flavors" do - provider.resource[:name] = 'fossil' - provider.resource[:flavor] = 'static' - output = 'fossil-1.29v0-static simple distributed software configuration management' - expect(provider).to receive(:execpipe).with(%w{/bin/pkg_info -I fossil}).and_yield(output) - expect(provider.get_full_name).to eq('fossil-1.29v0-static') + it "should return the full unversioned package name when installing without a flavor" do + provider.resource[:name] = 'puppet' + expect(provider.get_full_name).to eq('puppet--') end - end - context "#get_version" do - it "should return nil if execution fails" do - expect(provider).to receive(:execpipe).and_raise(Puppet::ExecutionFailure, 'wawawa') - expect(provider.get_version).to be_nil + it "should return unversioned package name when installing without flavor or branch" do + expect(provider.get_full_name).to eq('bash--') end - it "should return the package version if in the output" do - output = 'bash-3.1.17 GNU Bourne Again Shell' - expect(provider).to receive(:execpipe).with(%w{/bin/pkg_info -I bash}).and_yield(output) - expect(provider.get_version).to eq('3.1.17') + it "should return the full unversioned package name when installing with branch and flavor" do + provider.resource[:name] = 'postfix%stable' + provider.resource[:flavor] = 'ldap-mysql' + expect(provider.get_full_name).to eq('postfix--ldap-mysql%stable') end - it "should return the empty string if the package is not present" do - provider.resource[:name] = 'zsh' - expect(provider).to receive(:execpipe).with(%w{/bin/pkg_info -I zsh}).and_yield(StringIO.new('')) - expect(provider.get_version).to eq('') - end end context "#query" do - it "should return the installed version if present" do - fixture = File.read(my_fixture('pkginfo.detail')) - expect(provider).to receive(:pkginfo).with('bash').and_return(fixture) - expect(provider.query).to eq({ :ensure => '3.1.17' }) + it "should return package info if present" do + fixture = File.read(my_fixture('pkginfo.list')) + expect(described_class).to receive(:execpipe).with(%w{/bin/pkg_info -a -z}).and_yield(fixture) + expect(provider.query).to eq({:branch=>nil, :flavor=>nil, :name=>"bash", :provider=>:openbsd}) end it "should return nothing if not present" do + fixture = File.read(my_fixture('pkginfo.list')) provider.resource[:name] = 'zsh' - expect(provider).to receive(:pkginfo).with('zsh').and_return('') + expect(described_class).to receive(:execpipe).with(%w{/bin/pkg_info -a -z}).and_yield(fixture) expect(provider.query).to be_nil end end @@ -361,8 +131,8 @@ def expect_pkgadd_with_env_and_name(source, &block) end context "#uninstall_options" do - it "should return nill by default" do - expect(provider.uninstall_options).to be_nil + it "should return empty array by default" do + expect(provider.uninstall_options).to eq([]) end it "should return uninstall_options when set" do @@ -384,7 +154,7 @@ def expect_pkgadd_with_env_and_name(source, &block) context "#uninstall" do describe 'when uninstalling' do it 'should use erase to purge' do - expect(provider).to receive(:pkgdelete).with('-c', '-q', 'bash') + expect(provider).to receive(:pkgdelete).with('-c', '-qq', [], 'bash--') provider.purge end end @@ -392,7 +162,7 @@ def expect_pkgadd_with_env_and_name(source, &block) describe 'with uninstall_options' do it 'should use uninstall_options as Array' do provider.resource[:uninstall_options] = ['-q', '-c'] - expect(provider).to receive(:pkgdelete).with(['-q', '-c'], 'bash') + expect(provider).to receive(:pkgdelete).with(['-q', '-c'], 'bash--') provider.uninstall end end @@ -407,9 +177,8 @@ def expect_pkgadd_with_env_and_name(source, &block) expect(provider.flavor).to eq('no_x11-python') end - it 'should remove and install the new flavor if different' do + it 'should reinstall the new flavor if different' do provider.resource[:flavor] = 'no_x11-ruby' - expect(provider).to receive(:uninstall).ordered expect(provider).to receive(:install).ordered provider.flavor = provider.resource[:flavor] end