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

« back to all changes in this revision

Viewing changes to spec/unit/application/puppetca.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
require File.dirname(__FILE__) + '/../../spec_helper'
 
4
 
 
5
require 'puppet/application/puppetca'
 
6
 
 
7
describe "PuppetCA" do
 
8
    before :each do
 
9
        @puppetca = Puppet::Application[:puppetca]
 
10
        Puppet::Util::Log.stubs(:newdestination)
 
11
        Puppet::Util::Log.stubs(:level=)
 
12
    end
 
13
 
 
14
    it "should ask Puppet::Application to parse Puppet configuration file" do
 
15
        @puppetca.should_parse_config?.should be_true
 
16
    end
 
17
 
 
18
    it "should declare a main command" do
 
19
        @puppetca.should respond_to(:main)
 
20
    end
 
21
 
 
22
    Puppet::SSL::CertificateAuthority::Interface::INTERFACE_METHODS.reject{ |m| m == :destroy }.each do |method|
 
23
        it "should declare option --#{method}" do
 
24
            @puppetca.should respond_to("handle_#{method}".to_sym)
 
25
        end
 
26
    end
 
27
 
 
28
    it "should set log level to info with the --verbose option" do
 
29
 
 
30
        Puppet::Log.expects(:level=).with(:info)
 
31
 
 
32
        @puppetca.handle_verbose(0)
 
33
    end
 
34
 
 
35
    it "should set log level to debug with the --debug option" do
 
36
 
 
37
        Puppet::Log.expects(:level=).with(:debug)
 
38
 
 
39
        @puppetca.handle_debug(0)
 
40
    end
 
41
 
 
42
    it "should set mode to :destroy for --clean" do
 
43
        @puppetca.handle_clean(0)
 
44
        @puppetca.mode.should == :destroy
 
45
    end
 
46
 
 
47
    it "should set all to true for --all" do
 
48
        @puppetca.handle_all(0)
 
49
        @puppetca.all.should be_true
 
50
    end
 
51
 
 
52
    Puppet::SSL::CertificateAuthority::Interface::INTERFACE_METHODS.reject { |m| m == :destroy }.each do |method|
 
53
        it "should set mode to #{method} with option --#{method}" do
 
54
            @puppetca.send("handle_#{method}".to_sym, nil)
 
55
 
 
56
            @puppetca.mode.should == method
 
57
        end
 
58
    end
 
59
 
 
60
    describe "during setup" do
 
61
 
 
62
        before :each do
 
63
            Puppet::Log.stubs(:newdestination)
 
64
            Puppet::SSL::Host.stubs(:ca_location=)
 
65
            Puppet::SSL::CertificateAuthority.stubs(:new)
 
66
        end
 
67
 
 
68
        it "should set console as the log destination" do
 
69
            Puppet::Log.expects(:newdestination).with(:console)
 
70
 
 
71
            @puppetca.run_setup
 
72
        end
 
73
 
 
74
        it "should print puppet config if asked to in Puppet config" do
 
75
            @puppetca.stubs(:exit)
 
76
            Puppet.settings.stubs(:print_configs?).returns(true)
 
77
 
 
78
            Puppet.settings.expects(:print_configs)
 
79
 
 
80
            @puppetca.run_setup
 
81
        end
 
82
 
 
83
        it "should exit after printing puppet config if asked to in Puppet config" do
 
84
            Puppet.settings.stubs(:print_configs?).returns(true)
 
85
 
 
86
            lambda { @puppetca.run_setup }.should raise_error(SystemExit)
 
87
        end
 
88
 
 
89
        it "should set the CA location to 'only'" do
 
90
            Puppet::SSL::Host.expects(:ca_location=).with(:only)
 
91
 
 
92
            @puppetca.run_setup
 
93
        end
 
94
 
 
95
        it "should create a new certificate authority" do
 
96
            Puppet::SSL::CertificateAuthority.expects(:new)
 
97
 
 
98
            @puppetca.run_setup
 
99
        end
 
100
    end
 
101
 
 
102
    describe "when running" do
 
103
        before :each do
 
104
            @puppetca.all = false
 
105
            @ca = stub_everything 'ca'
 
106
            @puppetca.ca = @ca
 
107
            ARGV.stubs(:collect).returns([])
 
108
        end
 
109
 
 
110
        it "should delegate to the CertificateAuthority" do
 
111
            @ca.expects(:apply)
 
112
 
 
113
            @puppetca.main
 
114
        end
 
115
 
 
116
        it "should delegate with :all if option --all was given" do
 
117
            @puppetca.handle_all(0)
 
118
 
 
119
            @ca.expects(:apply).with { |mode,to| to[:to] == :all }
 
120
 
 
121
            @puppetca.main
 
122
        end
 
123
 
 
124
        it "should delegate to ca.apply with the hosts given on command line" do
 
125
            ARGV.stubs(:collect).returns(["host"])
 
126
 
 
127
            @ca.expects(:apply).with { |mode,to| to[:to] == ["host"]}
 
128
 
 
129
            @puppetca.main
 
130
        end
 
131
 
 
132
        it "should delegate to ca.apply with current set mode" do
 
133
            @puppetca.mode = "currentmode"
 
134
            ARGV.stubs(:collect).returns(["host"])
 
135
 
 
136
            @ca.expects(:apply).with { |mode,to| mode == "currentmode" }
 
137
 
 
138
            @puppetca.main
 
139
        end
 
140
 
 
141
    end
 
142
end