Skip to content

Commit

Permalink
Merge pull request puppetlabs#3905 from jasperla/pkgin_list
Browse files Browse the repository at this point in the history
(PUP-4546) Fix retrieving package version in #instances
  • Loading branch information
peterhuene committed May 13, 2015
2 parents 2c16bde + 5174c8c commit c58a6c3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
6 changes: 3 additions & 3 deletions lib/puppet/provider/package/pkgin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

commands :pkgin => "pkgin"

defaultfor :operatingsystem => [ :dragonfly , :smartos ]
defaultfor :operatingsystem => [ :dragonfly , :smartos, :netbsd ]

has_feature :installable, :uninstallable, :upgradeable, :versionable

def self.parse_pkgin_line(package)

# e.g.
# vim-7.2.446 = Vim editor (vi clone) without GUI
match, name, version, status = *package.match(/(\S+)-(\S+)(?: (=|>|<))?\s+.+$/)
# vim-7.2.446;Vim editor (vi clone) without GUI
match, name, version, status = *package.match(/([^\s;]+)-([^\s;]+)[;\s](=|>|<)?.+$/)
if match
{
:name => name,
Expand Down
36 changes: 23 additions & 13 deletions spec/unit/provider/package/pkgin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

describe "#instances" do
let(:pkgin_ls_output) do
"zlib-1.2.3 General purpose data compression library\nzziplib-0.13.59 Library for ZIP archive handling\n"
"zlib-1.2.3;General purpose data compression library\nzziplib-0.13.59;Library for ZIP archive handling\n"
end

before do
Expand Down Expand Up @@ -72,7 +72,7 @@

context "when the package is installed" do
let(:pkgin_search_output) do
"vim-7.2.446 = Vim editor (vi clone) without GUI\nvim-share-7.2.446 = Data files for the vim editor (vi clone)\n\n=: package is installed and up-to-date\n<: package is installed but newer version is available\n>: installed package has a greater version than available package\n"
"vim-7.2.446;=;Vim editor (vi clone) without GUI\nvim-share-7.2.446;=;Data files for the vim editor (vi clone)\n\n=: package is installed and up-to-date\n<: package is installed but newer version is available\n>: installed package has a greater version than available package\n"
end

it "returns installed version" do
Expand All @@ -83,7 +83,7 @@

context "when the package is out of date" do
let(:pkgin_search_output) do
"vim-7.2.447 < Vim editor (vi clone) without GUI\nvim-share-7.2.447 < Data files for the vim editor (vi clone)\n\n=: package is installed and up-to-date\n<: package is installed but newer version is available\n>: installed package has a greater version than available package\n"
"vim-7.2.447;<;Vim editor (vi clone) without GUI\nvim-share-7.2.447;<;Data files for the vim editor (vi clone)\n\n=: package is installed and up-to-date\n<: package is installed but newer version is available\n>: installed package has a greater version than available package\n"
end

it "returns the version to be installed" do
Expand All @@ -93,7 +93,7 @@

context "when the package is ahead of date" do
let(:pkgin_search_output) do
"vim-7.2.446 > Vim editor (vi clone) without GUI\nvim-share-7.2.446 > Data files for the vim editor (vi clone)\n\n=: package is installed and up-to-date\n<: package is installed but newer version is available\n>: installed package has a greater version than available package\n"
"vim-7.2.446;>;Vim editor (vi clone) without GUI\nvim-share-7.2.446;>;Data files for the vim editor (vi clone)\n\n=: package is installed and up-to-date\n<: package is installed but newer version is available\n>: installed package has a greater version than available package\n"
end

it "returns current version" do
Expand All @@ -105,12 +105,12 @@
context "when multiple candidates do exists" do
let(:pkgin_search_output) do
<<-SEARCH
vim-7.1 > Vim editor (vi clone) without GUI
vim-share-7.1 > Data files for the vim editor (vi clone)
vim-7.2.446 = Vim editor (vi clone) without GUI
vim-share-7.2.446 = Data files for the vim editor (vi clone)
vim-7.3 < Vim editor (vi clone) without GUI
vim-share-7.3 < Data files for the vim editor (vi clone)
vim-7.1;>;Vim editor (vi clone) without GUI
vim-share-7.1;>;Data files for the vim editor (vi clone)
vim-7.2.446;=;Vim editor (vi clone) without GUI
vim-share-7.2.446;=;Data files for the vim editor (vi clone)
vim-7.3;<;Vim editor (vi clone) without GUI
vim-share-7.3;<;Data files for the vim editor (vi clone)
=: package is installed and up-to-date
<: package is installed but newer version is available
Expand All @@ -137,7 +137,7 @@

describe "#parse_pkgin_line" do
context "with an installed package" do
let(:package) { "vim-7.2.446 = Vim editor (vi clone) without GUI" }
let(:package) { "vim-7.2.446;=;Vim editor (vi clone) without GUI" }

it "extracts the name and status" do
expect(provider_class.parse_pkgin_line(package)).to eq({ :name => "vim" ,
Expand All @@ -147,7 +147,7 @@
end

context "with an installed package with a hyphen in the name" do
let(:package) { "ruby18-puppet-0.25.5nb1 > Configuration management framework written in Ruby" }
let(:package) { "ruby18-puppet-0.25.5nb1;>;Configuration management framework written in Ruby" }

it "extracts the name and status" do
expect(provider_class.parse_pkgin_line(package)).to eq({ :name => "ruby18-puppet",
Expand All @@ -156,8 +156,18 @@
end
end

context "with an installed package with a hyphen in the name and package description" do
let(:package) { "ruby200-facter-2.4.3nb1;=;Cross-platform Ruby library for retrieving facts from OS" }

it "extracts the name and status" do
expect(provider_class.parse_pkgin_line(package)).to eq({ :name => "ruby200-facter",
:status => "=" ,
:ensure => "2.4.3nb1" })
end
end

context "with a package not yet installed" do
let(:package) { "vim-7.2.446 Vim editor (vi clone) without GUI" }
let(:package) { "vim-7.2.446;Vim editor (vi clone) without GUI" }

it "extracts the name and status" do
expect(provider_class.parse_pkgin_line(package)).to eq({ :name => "vim" ,
Expand Down

0 comments on commit c58a6c3

Please sign in to comment.