diff options
author | Markus Roberts <Markus@reality.com> | 2010-06-28 17:10:20 -0700 |
---|---|---|
committer | Markus Roberts <Markus@reality.com> | 2010-06-28 17:10:20 -0700 |
commit | fdc8c3509b5ac5bc170c54d72b2c2bafb58409f2 (patch) | |
tree | 6ed2204d72c6924e867a1320d3b7e6728035f1a1 /spec/unit/application/cert_spec.rb | |
parent | 9a94ee274c39c261cd49e688a7bd7ea0eb73af50 (diff) | |
download | puppet-fdc8c3509b5ac5bc170c54d72b2c2bafb58409f2.tar.gz puppet-fdc8c3509b5ac5bc170c54d72b2c2bafb58409f2.tar.xz puppet-fdc8c3509b5ac5bc170c54d72b2c2bafb58409f2.zip |
[#3994-part 3] rename spec tests from *_spec_spec to *_spec.rb
Part 2 re-did the change on the spec files, which it shouldn't have.
Diffstat (limited to 'spec/unit/application/cert_spec.rb')
-rw-r--r-- | spec/unit/application/cert_spec.rb | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/spec/unit/application/cert_spec.rb b/spec/unit/application/cert_spec.rb new file mode 100644 index 000000000..ba6ba1d2d --- /dev/null +++ b/spec/unit/application/cert_spec.rb @@ -0,0 +1,172 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'puppet/application/cert' + +describe Puppet::Application::Cert do + before :each do + @cert_app = Puppet::Application[:cert] + Puppet::Util::Log.stubs(:newdestination) + Puppet::Util::Log.stubs(:level=) + end + + it "should ask Puppet::Application to parse Puppet configuration file" do + @cert_app.should_parse_config?.should be_true + end + + it "should declare a main command" do + @cert_app.should respond_to(:main) + end + + Puppet::SSL::CertificateAuthority::Interface::INTERFACE_METHODS.reject{ |m| m == :destroy }.each do |method| + it "should declare option --#{method}" do + @cert_app.should respond_to("handle_#{method}".to_sym) + end + end + + it "should set log level to info with the --verbose option" do + + Puppet::Log.expects(:level=).with(:info) + + @cert_app.handle_verbose(0) + end + + it "should set log level to debug with the --debug option" do + + Puppet::Log.expects(:level=).with(:debug) + + @cert_app.handle_debug(0) + end + + it "should set the fingerprint digest with the --digest option" do + @cert_app.handle_digest(:digest) + + @cert_app.digest.should == :digest + end + + it "should set mode to :destroy for --clean" do + @cert_app.handle_clean(0) + @cert_app.mode.should == :destroy + end + + it "should set all to true for --all" do + @cert_app.handle_all(0) + @cert_app.all.should be_true + end + + it "should set signed to true for --signed" do + @cert_app.handle_signed(0) + @cert_app.signed.should be_true + end + + Puppet::SSL::CertificateAuthority::Interface::INTERFACE_METHODS.reject { |m| m == :destroy }.each do |method| + it "should set mode to #{method} with option --#{method}" do + @cert_app.send("handle_#{method}".to_sym, nil) + + @cert_app.mode.should == method + end + end + + describe "during setup" do + + before :each do + Puppet::Log.stubs(:newdestination) + Puppet::SSL::Host.stubs(:ca_location=) + Puppet::SSL::CertificateAuthority.stubs(:new) + end + + it "should set console as the log destination" do + Puppet::Log.expects(:newdestination).with(:console) + + @cert_app.setup + end + + it "should print puppet config if asked to in Puppet config" do + @cert_app.stubs(:exit) + Puppet.settings.stubs(:print_configs?).returns(true) + + Puppet.settings.expects(:print_configs) + + @cert_app.setup + end + + it "should exit after printing puppet config if asked to in Puppet config" do + Puppet.settings.stubs(:print_configs?).returns(true) + + lambda { @cert_app.setup }.should raise_error(SystemExit) + end + + it "should set the CA location to 'only'" do + Puppet::SSL::Host.expects(:ca_location=).with(:only) + + @cert_app.setup + end + + it "should create a new certificate authority" do + Puppet::SSL::CertificateAuthority.expects(:new) + + @cert_app.setup + end + end + + describe "when running" do + before :each do + @cert_app.all = false + @ca = stub_everything 'ca' + @cert_app.ca = @ca + @cert_app.command_line.stubs(:args).returns([]) + end + + it "should delegate to the CertificateAuthority" do + @ca.expects(:apply) + + @cert_app.main + end + + it "should delegate with :all if option --all was given" do + @cert_app.handle_all(0) + + @ca.expects(:apply).with { |mode,to| to[:to] == :all } + + @cert_app.main + end + + it "should delegate to ca.apply with the hosts given on command line" do + @cert_app.command_line.stubs(:args).returns(["host"]) + + @ca.expects(:apply).with { |mode,to| to[:to] == ["host"]} + + @cert_app.main + end + + it "should send the currently set digest" do + @cert_app.command_line.stubs(:args).returns(["host"]) + @cert_app.handle_digest(:digest) + + @ca.expects(:apply).with { |mode,to| to[:digest] == :digest} + + @cert_app.main + end + + it "should delegate to ca.apply with current set mode" do + @cert_app.mode = "currentmode" + @cert_app.command_line.stubs(:args).returns(["host"]) + + @ca.expects(:apply).with { |mode,to| mode == "currentmode" } + + @cert_app.main + end + + it "should revoke cert if mode is clean" do + @cert_app.mode = :destroy + @cert_app.command_line.stubs(:args).returns(["host"]) + + @ca.expects(:apply).with { |mode,to| mode == :revoke } + @ca.expects(:apply).with { |mode,to| mode == :destroy } + + @cert_app.main + end + + end +end |