3
require File.dirname(__FILE__) + '/../../spec_helper'
5
require 'puppet/application/puppetca'
9
@puppetca = Puppet::Application[:puppetca]
10
Puppet::Util::Log.stubs(:newdestination)
11
Puppet::Util::Log.stubs(:level=)
14
it "should ask Puppet::Application to parse Puppet configuration file" do
15
@puppetca.should_parse_config?.should be_true
18
it "should declare a main command" do
19
@puppetca.should respond_to(:main)
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)
28
it "should set log level to info with the --verbose option" do
30
Puppet::Log.expects(:level=).with(:info)
32
@puppetca.handle_verbose(0)
35
it "should set log level to debug with the --debug option" do
37
Puppet::Log.expects(:level=).with(:debug)
39
@puppetca.handle_debug(0)
42
it "should set mode to :destroy for --clean" do
43
@puppetca.handle_clean(0)
44
@puppetca.mode.should == :destroy
47
it "should set all to true for --all" do
48
@puppetca.handle_all(0)
49
@puppetca.all.should be_true
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)
56
@puppetca.mode.should == method
60
describe "during setup" do
63
Puppet::Log.stubs(:newdestination)
64
Puppet::SSL::Host.stubs(:ca_location=)
65
Puppet::SSL::CertificateAuthority.stubs(:new)
68
it "should set console as the log destination" do
69
Puppet::Log.expects(:newdestination).with(:console)
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)
78
Puppet.settings.expects(:print_configs)
83
it "should exit after printing puppet config if asked to in Puppet config" do
84
Puppet.settings.stubs(:print_configs?).returns(true)
86
lambda { @puppetca.run_setup }.should raise_error(SystemExit)
89
it "should set the CA location to 'only'" do
90
Puppet::SSL::Host.expects(:ca_location=).with(:only)
95
it "should create a new certificate authority" do
96
Puppet::SSL::CertificateAuthority.expects(:new)
102
describe "when running" do
104
@puppetca.all = false
105
@ca = stub_everything 'ca'
107
ARGV.stubs(:collect).returns([])
110
it "should delegate to the CertificateAuthority" do
116
it "should delegate with :all if option --all was given" do
117
@puppetca.handle_all(0)
119
@ca.expects(:apply).with { |mode,to| to[:to] == :all }
124
it "should delegate to ca.apply with the hosts given on command line" do
125
ARGV.stubs(:collect).returns(["host"])
127
@ca.expects(:apply).with { |mode,to| to[:to] == ["host"]}
132
it "should delegate to ca.apply with current set mode" do
133
@puppetca.mode = "currentmode"
134
ARGV.stubs(:collect).returns(["host"])
136
@ca.expects(:apply).with { |mode,to| mode == "currentmode" }