Skip to content
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

add-puppet-gem-provider-for-puppet-agent #3728

Closed
Closed
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
10 changes: 10 additions & 0 deletions lib/puppet/provider/package/puppet_gem.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'puppet/provider/package'

Puppet::Type.type(:package).provide :puppet_gem, :parent => :gem do
desc "Puppet Ruby Gem support. This provider is useful for managing
gems needed by the ruby provided in the puppet-agent package."

has_feature :versionable, :install_options, :uninstall_options

commands :gemcmd => "/opt/puppetlabs/puppet/bin/gem"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

support windows too?

end
63 changes: 63 additions & 0 deletions spec/unit/provider/package/puppet_gem_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#! /usr/bin/env ruby
require 'spec_helper'

provider_class = Puppet::Type.type(:package).provider(:puppet_gem)

describe provider_class do
let(:resource) do
Puppet::Type.type(:package).new(
:name => 'myresource',
:ensure => :installed
)
end

let(:provider) do
provider = provider_class.new
provider.resource = resource
provider
end

let(:puppet_gem) { '/opt/puppetlabs/puppet/bin/gem' }

before :each do
resource.provider = provider
end

describe "when installing" do
it "should use the path to the gem" do
provider_class.expects(:which).with(puppet_gem).returns(puppet_gem)
provider.expects(:execute).with { |args| args[0] == puppet_gem }.returns ''
provider.install
end

it "should not append install_options by default" do
provider.expects(:execute).with { |args| args.length == 5 }.returns ''
provider.install
end

it "should allow setting an install_options parameter" do
resource[:install_options] = [ '--force', {'--bindir' => '/usr/bin' } ]
provider.expects(:execute).with { |args| args[5] == '--force' && args[6] == '--bindir=/usr/bin' }.returns ''
provider.install
end
end

describe "when uninstalling" do
it "should use the path to the gem" do
provider_class.expects(:which).with(puppet_gem).returns(puppet_gem)
provider.expects(:execute).with { |args| args[0] == puppet_gem }.returns ''
provider.install
end

it "should not append uninstall_options by default" do
provider.expects(:execute).with { |args| args.length == 5 }.returns ''
provider.uninstall
end

it "should allow setting an uninstall_options parameter" do
resource[:uninstall_options] = [ '--force', {'--bindir' => '/usr/bin' } ]
provider.expects(:execute).with { |args| args[5] == '--force' && args[6] == '--bindir=/usr/bin' }.returns ''
provider.uninstall
end
end
end