summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Bode <dan@reductivelabs.com>2010-07-04 20:38:43 -0400
committerMarkus Roberts <Markus@reality.com>2010-07-07 11:59:49 -0700
commit4a6428b3e820876247b71ff1dcc6928946bb78ff (patch)
tree76b160943d7c6bb536508ebcb4ed211040450280
parent1e0d922b152cc61c15c91af49f43d5f693972579 (diff)
downloadpuppet-4a6428b3e820876247b71ff1dcc6928946bb78ff.tar.gz
puppet-4a6428b3e820876247b71ff1dcc6928946bb78ff.tar.xz
puppet-4a6428b3e820876247b71ff1dcc6928946bb78ff.zip
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.
-rwxr-xr-xlib/puppet/provider/service/redhat.rb2
-rwxr-xr-xspec/unit/provider/service/init_spec.rb47
-rwxr-xr-xspec/unit/provider/service/redhat_spec.rb29
3 files changed, 75 insertions, 3 deletions
diff --git a/lib/puppet/provider/service/redhat.rb b/lib/puppet/provider/service/redhat.rb
index ddcbe0e8c..27bdbb820 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 32bfaa204..6dd42f54c 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 47997dca3..591ef2d96 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-@not_services).each do |inst|
+ @class.expects(:new).with{|hash| hash[:name] == inst && hash[:path] == '/etc/init.d'}.returns("#{inst}_instance")
+ end
+ results = (@services-@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?)