diff options
author | Luke Kanies <luke@madstop.com> | 2008-07-07 17:11:59 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-07-07 17:11:59 -0500 |
commit | 667fac18cc3682374de991bb740ae834d8c17bee (patch) | |
tree | ff6f50b14c92fb856095c8e87bdb8ebc9080dbc8 | |
parent | 21d49578376b4adcf29e08b50cc14457bc4dcb26 (diff) | |
download | puppet-667fac18cc3682374de991bb740ae834d8c17bee.tar.gz puppet-667fac18cc3682374de991bb740ae834d8c17bee.tar.xz puppet-667fac18cc3682374de991bb740ae834d8c17bee.zip |
Fixed #1226 - Gems can now specify source repositories.
Added tests for the bit that's changed here (and caught
a couple of bugs in the original patch).
This is all a modification of Sam Quigley's work.
Signed-off-by: Luke Kanies <luke@madstop.com>
-rw-r--r-- | CHANGELOG | 2 | ||||
-rwxr-xr-x | lib/puppet/provider/package/gem.rb | 35 | ||||
-rw-r--r-- | spec/unit/provider/package/gem.rb | 66 |
3 files changed, 79 insertions, 24 deletions
@@ -1,4 +1,6 @@ 0.24.? + Fixed #1226 - gems can now specify source repositories. + Fixed #1232 - the rundir no longer specifies a user/group, and there are now client- and server-specific yaml directories. diff --git a/lib/puppet/provider/package/gem.rb b/lib/puppet/provider/package/gem.rb index 373af431e..133243c86 100755 --- a/lib/puppet/provider/package/gem.rb +++ b/lib/puppet/provider/package/gem.rb @@ -69,29 +69,34 @@ Puppet::Type.type(:package).provide :gem, :parent => Puppet::Provider::Package d def install(useversion = true) command = [command(:gemcmd), "install"] - if (! @resource.should(:ensure).is_a? Symbol) and useversion - command << "-v" << @resource.should(:ensure) + if (! resource[:ensure].is_a? Symbol) and useversion + command << "-v" << resource[:ensure] end # Always include dependencies command << "--include-dependencies" - if source = @resource[:source] - scheme = URI.parse(blah).scheme rescue nil # the URI scheme if there is one, nil otherwise - - if scheme.nil? + if source = resource[:source] + begin + uri = URI.parse(source) + rescue => detail + fail "Invalid source '%s': %s" % [uri, detail] + end + + case uri.scheme + when nil: # no URI scheme => interpret the source as a local file command << source - elsif scheme.downcase == "file" - command << source.path - elsif scheme.downcase == "puppet" + when /file/i + command << uri.path + when 'puppet' # we don't support puppet:// URLs (yet) raise Puppet::Error.new("puppet:// URLs are not supported as gem sources") - else + else # interpret it as a gem repository - command << "--source" << "#{source}" << @resource[:name] + command << "--source" << "#{source}" << resource[:name] end else - command << @resource[:name] + command << resource[:name] end output = execute(command) @@ -103,17 +108,17 @@ Puppet::Type.type(:package).provide :gem, :parent => Puppet::Provider::Package d def latest # This always gets the latest version available. - hash = self.class.gemlist(:justme => @resource[:name]) + hash = self.class.gemlist(:justme => resource[:name]) return hash[:ensure] end def query - self.class.gemlist(:justme => @resource[:name], :local => true) + self.class.gemlist(:justme => resource[:name], :local => true) end def uninstall - gemcmd "uninstall", "-x", "-a", @resource[:name] + gemcmd "uninstall", "-x", "-a", resource[:name] end def update diff --git a/spec/unit/provider/package/gem.rb b/spec/unit/provider/package/gem.rb index 24f2ad66d..3dc1fa347 100644 --- a/spec/unit/provider/package/gem.rb +++ b/spec/unit/provider/package/gem.rb @@ -1,7 +1,6 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../../spec_helper' -require 'puppet/provider/package/gem' provider_class = Puppet::Type.type(:package).provider(:gem) @@ -14,26 +13,75 @@ describe provider_class do describe "when installing" do before do # Create a mock resource - @resource = mock 'resource' + @resource = stub 'resource' # A catch all; no parameters set @resource.stubs(:[]).returns nil # We have to set a name, though @resource.stubs(:[]).with(:name).returns "myresource" - - # BTW, you get odd error messages from rspec if you forget to mock "should" here... - @resource.stubs(:should).with(:ensure).returns :installed + @resource.stubs(:[]).with(:ensure).returns :installed @provider = provider_class.new @provider.stubs(:resource).returns @resource - # Create a provider that uses the mock -# @provider = provider_class.new(@resource) end - it "should execute the gem command with 'install', dependencies, and the package name" do - @provider.expects(:execute).with(provider_class.command(:gemcmd), 'install', "--include-dependences", "myresource") + it "should use the path to the gem" do + provider_class.stubs(:command).with(:gemcmd).returns "/my/gem" + @provider.expects(:execute).with { |args| args[0] == "/my/gem" }.returns "" + @provider.install + end + + it "should specify that the gem is being installed" do + @provider.expects(:execute).with { |args| args[1] == "install" }.returns "" + @provider.install + end + + it "should specify that dependencies should be included" do + @provider.expects(:execute).with { |args| args[2] == "--include-dependencies" }.returns "" + @provider.install + end + + it "should specify the package name" do + @provider.expects(:execute).with { |args| args[3] == "myresource" }.returns "" @provider.install end + + describe "when a source is specified" do + describe "as a normal file" do + it "should use the file name instead of the gem name" do + @resource.stubs(:[]).with(:source).returns "/my/file" + @provider.expects(:execute).with { |args| args[3] == "/my/file" }.returns "" + @provider.install + end + end + describe "as a file url" do + it "should use the file name instead of the gem name" do + @resource.stubs(:[]).with(:source).returns "file:///my/file" + @provider.expects(:execute).with { |args| args[3] == "/my/file" }.returns "" + @provider.install + end + end + describe "as a puppet url" do + it "should fail" do + @resource.stubs(:[]).with(:source).returns "puppet://my/file" + lambda { @provider.install }.should raise_error(Puppet::Error) + end + end + describe "as a non-file and non-puppet url" do + it "should treat the source as a gem repository" do + @resource.stubs(:[]).with(:source).returns "http://host/my/file" + @provider.expects(:execute).with { |args| args[3..5] == ["--source", "http://host/my/file", "myresource"] }.returns "" + @provider.install + end + end + describe "with an invalid uri" do + it "should fail" do + URI.expects(:parse).raises(ArgumentError) + @resource.stubs(:[]).with(:source).returns "http:::::uppet:/:/my/file" + lambda { @provider.install }.should raise_error(Puppet::Error) + end + end + end end end |