From eb5e42263c109096a2ab4aa31f062f3e603db0dd Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sun, 25 May 2008 20:17:55 -0500 Subject: Fixing #1256 -- CA tests now work with no ~/.puppet. I've set the default cadir and vardir to /dev/null, to hopefully catch this kind of test sooner next time. --- spec/spec_helper.rb | 5 +++++ spec/unit/ssl/certificate_authority.rb | 39 ++++++++++++++++------------------ 2 files changed, 23 insertions(+), 21 deletions(-) (limited to 'spec') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index db14b47cb..a1999a333 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -34,3 +34,8 @@ Spec::Runner.configure do |config| # teardown() if respond_to? :teardown # end end + +# Set the confdir and vardir to gibberish so that tests +# have to be correctly mocked. +Puppet[:confdir] = "/dev/null" +Puppet[:vardir] = "/dev/null" diff --git a/spec/unit/ssl/certificate_authority.rb b/spec/unit/ssl/certificate_authority.rb index 9cfea0a18..2ff324a6a 100755 --- a/spec/unit/ssl/certificate_authority.rb +++ b/spec/unit/ssl/certificate_authority.rb @@ -6,11 +6,19 @@ require 'puppet/ssl/certificate_authority' describe Puppet::SSL::CertificateAuthority do after do - # Clear out the var, yay unit tests. - Puppet::SSL::CertificateAuthority.instance_variable_set("@instance", nil) + Puppet::Util::Cacher.invalidate Puppet.settings.clearused end + def stub_ca_host + @key = mock 'key' + @key.stubs(:content).returns "cakey" + @cacert = mock 'certificate' + @cacert.stubs(:content).returns "cacertificate" + + @host = stub 'ssl_host', :key => @key, :certificate => @cacert, :name => Puppet::SSL::Host.ca_name + end + it "should have a class method for returning a singleton instance" do Puppet::SSL::CertificateAuthority.should respond_to(:instance) end @@ -25,12 +33,6 @@ describe Puppet::SSL::CertificateAuthority do Puppet::SSL::CertificateAuthority.stubs(:new).returns @ca end - after do - # Clear out the var, yay unit tests. - #Puppet::SSL::CertificateAuthority.instance_variable_set("@instance", nil) - Puppet::Util::Cacher.invalidate - end - it "should return an instance" do Puppet::SSL::CertificateAuthority.instance.should equal(@ca) end @@ -225,20 +227,16 @@ describe Puppet::SSL::CertificateAuthority do Puppet::SSL::CertificateAuthority.any_instance.stubs(:password?).returns true - # Set up the CA - @key = mock 'key' - @key.stubs(:content).returns "cakey" - Puppet::SSL::CertificateAuthority.any_instance.stubs(:key).returns @key - @cacert = mock 'certificate' - @cacert.stubs(:content).returns "cacertificate" + stub_ca_host + + Puppet::SSL::Host.expects(:new).with(Puppet::SSL::Host.ca_name).returns @host + @ca = Puppet::SSL::CertificateAuthority.new - @ca.host.stubs(:certificate).returns @cacert - @ca.host.stubs(:key).returns @key - @name = "myhost" @real_cert = stub 'realcert', :sign => nil @cert = stub 'certificate', :content => @real_cert + Puppet::SSL::Certificate.stubs(:new).returns @cert @cert.stubs(:content=) @@ -515,10 +513,9 @@ describe Puppet::SSL::CertificateAuthority do Puppet::SSL::CertificateAuthority.any_instance.stubs(:password?).returns true - # Set up the CA - @key = mock 'key' - @key.stubs(:content).returns "cakey" - @host = stub 'host', :key => @key + stub_ca_host + + Puppet::SSL::Host.expects(:new).returns @host Puppet::SSL::CertificateAuthority.any_instance.stubs(:host).returns @host @cacert = mock 'certificate' -- cgit