~nvalcarcel/ubuntu/lucid/puppet/fix-546677

« back to all changes in this revision

Viewing changes to spec/unit/provider/service/debian.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env ruby
 
2
#
 
3
# Unit testing for the debian service provider
 
4
#
 
5
 
 
6
require File.dirname(__FILE__) + '/../../../spec_helper'
 
7
 
 
8
provider_class = Puppet::Type.type(:service).provider(:debian)
 
9
 
 
10
describe provider_class do
 
11
 
 
12
    before(:each) do
 
13
        # Create a mock resource
 
14
        @resource = stub 'resource'
 
15
 
 
16
        @provider = provider_class.new
 
17
 
 
18
        # A catch all; no parameters set
 
19
        @resource.stubs(:[]).returns(nil)
 
20
 
 
21
        # But set name, source and path
 
22
        @resource.stubs(:[]).with(:name).returns "myservice"
 
23
        @resource.stubs(:[]).with(:ensure).returns :enabled
 
24
        @resource.stubs(:ref).returns "Service[myservice]"
 
25
 
 
26
        @provider.resource = @resource
 
27
 
 
28
        @provider.stubs(:command).with(:update_rc).returns "update_rc"
 
29
        @provider.stubs(:command).with(:invoke_rc).returns "invoke_rc"
 
30
 
 
31
        @provider.stubs(:update_rc)
 
32
        @provider.stubs(:invoke_rc)
 
33
    end
 
34
 
 
35
    it "should have an enabled? method" do
 
36
        @provider.should respond_to(:enabled?)
 
37
    end
 
38
 
 
39
    it "should have an enable method" do
 
40
        @provider.should respond_to(:enable)
 
41
    end
 
42
 
 
43
    it "should have a disable method" do
 
44
        @provider.should respond_to(:disable)
 
45
    end
 
46
 
 
47
    describe "when enabling" do
 
48
        it "should call update-rc.d twice" do
 
49
            @provider.expects(:update_rc).twice
 
50
            @provider.enable
 
51
        end
 
52
    end
 
53
 
 
54
    describe "when disabling" do
 
55
        it "should call update-rc.d twice" do
 
56
            @provider.expects(:update_rc).twice
 
57
            @provider.disable
 
58
        end
 
59
    end
 
60
    
 
61
    describe "when checking whether it is enabled" do
 
62
        it "should call Kernel.system() with the appropriate parameters" do
 
63
            @provider.expects(:system).with("/usr/sbin/invoke-rc.d", "--query", @resource[:name], "start").once
 
64
            @provider.enabled?
 
65
        end
 
66
        
 
67
        it "should return true when invoke-rc.d exits with 104 status" do
 
68
            @provider.stubs(:system)
 
69
            $?.stubs(:exitstatus).returns(104)
 
70
            @provider.enabled?.should == :true
 
71
        end
 
72
        
 
73
        it "should return true when invoke-rc.d exits with 106 status" do
 
74
            @provider.stubs(:system)
 
75
            $?.stubs(:exitstatus).returns(106)
 
76
            @provider.enabled?.should == :true
 
77
        end
 
78
        
 
79
        # pick a range of non-[104.106] numbers, strings and booleans to test with.
 
80
        [-100, -1, 0, 1, 100, "foo", "", :true, :false].each do |exitstatus|
 
81
            it "should return false when invoke-rc.d exits with #{exitstatus} status" do
 
82
                @provider.stubs(:system)
 
83
                $?.stubs(:exitstatus).returns(exitstatus)
 
84
                @provider.enabled?.should == :false
 
85
            end
 
86
        end
 
87
    end
 
88
 
 
89
 end