[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35
Markus Roberts
Markus at reality.com
Wed Jul 14 10:36:46 UTC 2010
The following commit has been merged in the upstream branch:
commit 4a6428b3e820876247b71ff1dcc6928946bb78ff
Author: Dan Bode <dan at reductivelabs.com>
Date: Sun Jul 4 20:38:43 2010 -0400
saving work for my unit tests. The redhat one still fails...
[4123] [4124] - combined unit test for both fixes since they share some common code.
proper unit tests to verify features for both patches.
diff --git a/lib/puppet/provider/service/redhat.rb b/lib/puppet/provider/service/redhat.rb
index ddcbe0e..27bdbb8 100755
--- a/lib/puppet/provider/service/redhat.rb
+++ b/lib/puppet/provider/service/redhat.rb
@@ -13,7 +13,7 @@ Puppet::Type.type(:service).provide :redhat, :parent => :init, :source => :init
def self.instances
# this exclude list is all from /sbin/service (5.x), but I did not exclude kudzu
- self.get_services(['/etc/init.d/'], ['functions', 'halt', 'killall', 'single', 'linuxconf'])
+ self.get_services(['/etc/init.d'], ['functions', 'halt', 'killall', 'single', 'linuxconf'])
end
def self.defpath
diff --git a/spec/unit/provider/service/init_spec.rb b/spec/unit/provider/service/init_spec.rb
index 32bfaa2..6dd42f5 100755
--- a/spec/unit/provider/service/init_spec.rb
+++ b/spec/unit/provider/service/init_spec.rb
@@ -10,6 +10,7 @@ provider_class = Puppet::Type.type(:service).provider(:init)
describe provider_class do
before :each do
+ @class = Puppet::Type.type(:service).provider(:init)
@resource = stub 'resource'
@resource.stubs(:[]).returns(nil)
@resource.stubs(:[]).with(:name).returns "myservice"
@@ -22,6 +23,52 @@ describe provider_class do
@provider.resource = @resource
end
+ describe "when getting all service instances" do
+ before :each do
+ @services = ['one', 'two', 'three', 'four']
+ Dir.stubs(:entries).returns @services
+ FileTest.stubs(:directory?).returns(true)
+ FileTest.stubs(:executable?).returns(true)
+ @class.stubs(:defpath).returns('tmp')
+ end
+ it "should return instances for all services" do
+ @services.each do |inst|
+ @class.expects(:new).with{|hash| hash[:name] == inst}.returns("#{inst}_instance")
+ end
+ results = @services.collect {|x| "#{x}_instance"}
+ @class.instances.should == results
+ end
+ it "should omit an array of services from exclude list" do
+ exclude = ['two', 'four']
+ (@services-exclude).each do |inst|
+ @class.expects(:new).with{|hash| hash[:name] == inst}.returns("#{inst}_instance")
+ end
+ results = (@services-exclude).collect {|x| "#{x}_instance"}
+ @class.get_services(@class.defpath, exclude).should == results
+ end
+ it "should omit a single service from the exclude list" do
+ exclude = 'two'
+ (@services-exclude.to_a).each do |inst|
+ @class.expects(:new).with{|hash| hash[:name] == inst}.returns("#{inst}_instance")
+ end
+ results = @services.reject{|x| x==exclude }.collect {|x| "#{x}_instance"}
+ @class.get_services(@class.defpath, exclude).should == results
+ end
+ it "should use defpath" do
+ @services.each do |inst|
+ @class.expects(:new).with{|hash| hash[:path] == @class.defpath}.returns("#{inst}_instance")
+ end
+ results = @services.sort.collect {|x| "#{x}_instance"}
+ @class.instances.sort.should == results
+ end
+ it "should set hasstatus to true for providers" do
+ @services.each do |inst|
+ @class.expects(:new).with{|hash| hash[:name] == inst && hash[:hasstatus] == true}.returns("#{inst}_instance")
+ end
+ results = @services.collect {|x| "#{x}_instance"}
+ @class.instances.should == results
+ end
+ end
describe "when searching for the init script" do
it "should discard paths that do not exist" do
diff --git a/spec/unit/provider/service/redhat_spec.rb b/spec/unit/provider/service/redhat_spec.rb
index 47997dc..591ef2d 100755
--- a/spec/unit/provider/service/redhat_spec.rb
+++ b/spec/unit/provider/service/redhat_spec.rb
@@ -2,7 +2,6 @@
#
# Unit testing for the RedHat service Provider
#
-
require File.dirname(__FILE__) + '/../../../spec_helper'
provider_class = Puppet::Type.type(:service).provider(:redhat)
@@ -10,15 +9,41 @@ provider_class = Puppet::Type.type(:service).provider(:redhat)
describe provider_class do
before :each do
+ @class = Puppet::Type.type(:service).provider(:redhat)
@resource = stub 'resource'
@resource.stubs(:[]).returns(nil)
@resource.stubs(:[]).with(:name).returns "myservice"
-
@provider = provider_class.new
+ @resource.stubs(:provider).returns @provider
@provider.resource = @resource
+ @provider.stubs(:get).with(:hasstatus).returns false
FileTest.stubs(:file?).with('/sbin/service').returns true
FileTest.stubs(:executable?).with('/sbin/service').returns true
end
+
+ # test self.instances
+ describe "when getting all service instances" do
+ before :each do
+ @services = ['one', 'two', 'three', 'four', 'kudzu', 'functions', 'halt', 'killall', 'single', 'linuxconf']
+ @not_services = ['functions', 'halt', 'killall', 'single', 'linuxconf']
+ Dir.stubs(:entries).returns @services
+ FileTest.stubs(:directory?).returns(true)
+ FileTest.stubs(:executable?).returns(true)
+ end
+ it "should return instances for all services" do
+ (@services- at not_services).each do |inst|
+ @class.expects(:new).with{|hash| hash[:name] == inst && hash[:path] == '/etc/init.d'}.returns("#{inst}_instance")
+ end
+ results = (@services- at not_services).collect {|x| "#{x}_instance"}
+ @class.instances.should == results
+ end
+ it "should call service status when initialized from provider" do
+ @resource.stubs(:[]).with(:status).returns nil
+ @provider.stubs(:get).with(:hasstatus).returns true
+ @provider.expects(:execute).with{|command, *args| command == ['/sbin/service', 'myservice', 'status']}
+ @provider.send(:status)
+ end
+ end
it "should have an enabled? method" do
@provider.should respond_to(:enabled?)
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list