summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@puppetlabs.com>2011-04-20 15:22:57 -0700
committerDaniel Pittman <daniel@puppetlabs.com>2011-04-20 15:23:14 -0700
commit7b3744cd363c817c515f865ccdf45bdfbdb5796b (patch)
tree0480a774a5a06dd2a79052a164f96829c7129200
parent220f3086e0254fb681a8dfece5238d0dff861f6f (diff)
downloadpuppet-7b3744cd363c817c515f865ccdf45bdfbdb5796b.tar.gz
puppet-7b3744cd363c817c515f865ccdf45bdfbdb5796b.tar.xz
puppet-7b3744cd363c817c515f865ccdf45bdfbdb5796b.zip
maint: stop stubbing log level setting.
The underlying problem turned up when another test (as a side effect) changed the logging level to be more verbose, and a very distant test broke. This revealed that we didn't preserve that global state around tests. Fixing that further revealed that we stubbed setting that log level all over the place, as a point fix for the same problem, and to assert the operation of various tools. So, additionally, we strip out all that stubbing, and assert on the desired effect rather than the mechanism for achieving it. Reviewed-By: Max Martin <max@puppetlabs.com>
-rwxr-xr-xspec/spec_helper.rb3
-rwxr-xr-xspec/unit/application/agent_spec.rb9
-rwxr-xr-xspec/unit/application/apply_spec.rb10
-rwxr-xr-xspec/unit/application/cert_spec.rb10
-rwxr-xr-x[-rw-r--r--]spec/unit/application/device_spec.rb10
-rwxr-xr-xspec/unit/application/doc_spec.rb8
-rwxr-xr-xspec/unit/application/filebucket_spec.rb10
-rwxr-xr-xspec/unit/application/kick_spec.rb10
-rwxr-xr-xspec/unit/application/master_spec.rb10
-rwxr-xr-xspec/unit/application/queue_spec.rb9
-rwxr-xr-xspec/unit/application/resource_spec.rb10
-rwxr-xr-xspec/unit/application_spec.rb4
12 files changed, 24 insertions, 79 deletions
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 1187c1caf..b04ec6ffd 100755
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -50,6 +50,8 @@ RSpec.configure do |config|
@logs = []
Puppet::Util::Log.newdestination(Puppet::Test::LogCollector.new(@logs))
+
+ @log_level = Puppet::Util::Log.level
end
config.after :each do
@@ -62,6 +64,7 @@ RSpec.configure do |config|
@logs.clear
Puppet::Util::Log.close_all
+ Puppet::Util::Log.level = @log_level
GC.enable
end
diff --git a/spec/unit/application/agent_spec.rb b/spec/unit/application/agent_spec.rb
index 03cf14429..b30a8cc6c 100755
--- a/spec/unit/application/agent_spec.rb
+++ b/spec/unit/application/agent_spec.rb
@@ -18,7 +18,6 @@ describe Puppet::Application::Agent do
Puppet::Agent.stubs(:new).returns(@agent)
@puppetd.preinit
Puppet::Util::Log.stubs(:newdestination)
- Puppet::Util::Log.stubs(:level=)
Puppet::Node.indirection.stubs(:terminus_class=)
Puppet::Node.indirection.stubs(:cache_class=)
@@ -223,18 +222,14 @@ describe Puppet::Application::Agent do
it "should set log level to debug if --debug was passed" do
@puppetd.options.stubs(:[]).with(:debug).returns(true)
-
- Puppet::Util::Log.expects(:level=).with(:debug)
-
@puppetd.setup_logs
+ Puppet::Util::Log.level.should == :debug
end
it "should set log level to info if --verbose was passed" do
@puppetd.options.stubs(:[]).with(:verbose).returns(true)
-
- Puppet::Util::Log.expects(:level=).with(:info)
-
@puppetd.setup_logs
+ Puppet::Util::Log.level.should == :info
end
[:verbose, :debug].each do |level|
diff --git a/spec/unit/application/apply_spec.rb b/spec/unit/application/apply_spec.rb
index dca2a4156..ec3f083db 100755
--- a/spec/unit/application/apply_spec.rb
+++ b/spec/unit/application/apply_spec.rb
@@ -9,7 +9,6 @@ describe Puppet::Application::Apply do
before :each do
@apply = Puppet::Application[:apply]
Puppet::Util::Log.stubs(:newdestination)
- Puppet::Util::Log.stubs(:level=)
end
[:debug,:loadclasses,:verbose,:use_nodes,:detailed_exitcodes].each do |option|
@@ -51,7 +50,6 @@ describe Puppet::Application::Apply do
before :each do
Puppet::Log.stubs(:newdestination)
- Puppet::Log.stubs(:level=)
Puppet.stubs(:parse_config)
Puppet::FileBucket::Dipper.stubs(:new)
STDIN.stubs(:read)
@@ -84,18 +82,14 @@ describe Puppet::Application::Apply do
it "should set log level to debug if --debug was passed" do
@apply.options.stubs(:[]).with(:debug).returns(true)
-
- Puppet::Log.expects(:level=).with(:debug)
-
@apply.setup
+ Puppet::Log.level.should == :debug
end
it "should set log level to info if --verbose was passed" do
@apply.options.stubs(:[]).with(:verbose).returns(true)
-
- Puppet::Log.expects(:level=).with(:info)
-
@apply.setup
+ Puppet::Log.level.should == :info
end
it "should print puppet config if asked to in Puppet config" do
diff --git a/spec/unit/application/cert_spec.rb b/spec/unit/application/cert_spec.rb
index a1b5eb19a..4a91c1e6c 100755
--- a/spec/unit/application/cert_spec.rb
+++ b/spec/unit/application/cert_spec.rb
@@ -6,7 +6,6 @@ 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 operate in master run_mode" do
@@ -28,22 +27,17 @@ describe Puppet::Application::Cert do
end
it "should set log level to info with the --verbose option" do
-
- Puppet::Log.expects(:level=).with(:info)
-
@cert_app.handle_verbose(0)
+ Puppet::Log.level.should == :info
end
it "should set log level to debug with the --debug option" do
-
- Puppet::Log.expects(:level=).with(:debug)
-
@cert_app.handle_debug(0)
+ Puppet::Log.level.should == :debug
end
it "should set the fingerprint digest with the --digest option" do
@cert_app.handle_digest(:digest)
-
@cert_app.digest.should == :digest
end
diff --git a/spec/unit/application/device_spec.rb b/spec/unit/application/device_spec.rb
index 086e321e9..832b7e55b 100644..100755
--- a/spec/unit/application/device_spec.rb
+++ b/spec/unit/application/device_spec.rb
@@ -10,10 +10,8 @@ require 'puppet/configurer'
describe Puppet::Application::Device do
before :each do
@device = Puppet::Application[:device]
-# @device.stubs(:puts)
@device.preinit
Puppet::Util::Log.stubs(:newdestination)
- Puppet::Util::Log.stubs(:level=)
Puppet::Node.indirection.stubs(:terminus_class=)
Puppet::Node.indirection.stubs(:cache_class=)
@@ -144,18 +142,14 @@ describe Puppet::Application::Device do
it "should set log level to debug if --debug was passed" do
@device.options.stubs(:[]).with(:debug).returns(true)
-
- Puppet::Util::Log.expects(:level=).with(:debug)
-
@device.setup_logs
+ Puppet::Util::Log.level.should == :debug
end
it "should set log level to info if --verbose was passed" do
@device.options.stubs(:[]).with(:verbose).returns(true)
-
- Puppet::Util::Log.expects(:level=).with(:info)
-
@device.setup_logs
+ Puppet::Util::Log.level.should == :info
end
[:verbose, :debug].each do |level|
diff --git a/spec/unit/application/doc_spec.rb b/spec/unit/application/doc_spec.rb
index 66a833b9d..43a4b9849 100755
--- a/spec/unit/application/doc_spec.rb
+++ b/spec/unit/application/doc_spec.rb
@@ -11,7 +11,6 @@ describe Puppet::Application::Doc do
@doc.stubs(:puts)
@doc.preinit
Puppet::Util::Log.stubs(:newdestination)
- Puppet::Util::Log.stubs(:level=)
end
it "should ask Puppet::Application to not parse Puppet configuration file" do
@@ -186,7 +185,6 @@ describe Puppet::Application::Doc do
before :each do
@doc.options.stubs(:[]).returns(false)
Puppet.stubs(:parse_config)
- Puppet::Util::Log.stubs(:level=)
Puppet::Util::Log.stubs(:newdestination)
end
@@ -232,16 +230,14 @@ describe Puppet::Application::Doc do
it "should set log level to debug if --debug" do
@doc.options.stubs(:[]).with(:debug).returns(true)
- Puppet::Util::Log.expects(:level=).with(:debug)
-
@doc.setup_rdoc
+ Puppet::Util::Log.level.should == :debug
end
it "should set log level to info if --verbose" do
@doc.options.stubs(:[]).with(:verbose).returns(true)
- Puppet::Util::Log.expects(:level=).with(:info)
-
@doc.setup_rdoc
+ Puppet::Util::Log.level.should == :info
end
it "should set log destination to console if --verbose" do
diff --git a/spec/unit/application/filebucket_spec.rb b/spec/unit/application/filebucket_spec.rb
index 8ba86be9e..92bc0410a 100755
--- a/spec/unit/application/filebucket_spec.rb
+++ b/spec/unit/application/filebucket_spec.rb
@@ -41,7 +41,6 @@ describe Puppet::Application::Filebucket do
before :each do
Puppet::Log.stubs(:newdestination)
Puppet.stubs(:settraps)
- Puppet::Log.stubs(:level=)
Puppet.stubs(:parse_config)
Puppet::FileBucket::Dipper.stubs(:new)
@filebucket.options.stubs(:[]).with(any_parameters)
@@ -62,18 +61,14 @@ describe Puppet::Application::Filebucket do
it "should set log level to debug if --debug was passed" do
@filebucket.options.stubs(:[]).with(:debug).returns(true)
-
- Puppet::Log.expects(:level=).with(:debug)
-
@filebucket.setup
+ Puppet::Log.level.should == :debug
end
it "should set log level to info if --verbose was passed" do
@filebucket.options.stubs(:[]).with(:verbose).returns(true)
-
- Puppet::Log.expects(:level=).with(:info)
-
@filebucket.setup
+ Puppet::Log.level.should == :info
end
it "should Parse puppet config" do
@@ -140,7 +135,6 @@ describe Puppet::Application::Filebucket do
before :each do
Puppet::Log.stubs(:newdestination)
Puppet.stubs(:settraps)
- Puppet::Log.stubs(:level=)
Puppet.stubs(:parse_config)
Puppet::FileBucket::Dipper.stubs(:new)
@filebucket.options.stubs(:[]).with(any_parameters)
diff --git a/spec/unit/application/kick_spec.rb b/spec/unit/application/kick_spec.rb
index 29e4caea4..742c0fff6 100755
--- a/spec/unit/application/kick_spec.rb
+++ b/spec/unit/application/kick_spec.rb
@@ -10,7 +10,6 @@ describe Puppet::Application::Kick, :if => Puppet.features.posix? do
Puppet::Util::Ldap::Connection.stubs(:new).returns(stub_everything)
@kick = Puppet::Application[:kick]
Puppet::Util::Log.stubs(:newdestination)
- Puppet::Util::Log.stubs(:level=)
end
describe ".new" do
@@ -120,7 +119,6 @@ describe Puppet::Application::Kick, :if => Puppet.features.posix? do
@kick.classes = []
@kick.tags = []
@kick.hosts = []
- Puppet::Log.stubs(:level=)
@kick.stubs(:trap)
@kick.stubs(:puts)
Puppet.stubs(:parse_config)
@@ -130,18 +128,14 @@ describe Puppet::Application::Kick, :if => Puppet.features.posix? do
it "should set log level to debug if --debug was passed" do
@kick.options.stubs(:[]).with(:debug).returns(true)
-
- Puppet::Log.expects(:level=).with(:debug)
-
@kick.setup
+ Puppet::Log.level.should == :debug
end
it "should set log level to info if --verbose was passed" do
@kick.options.stubs(:[]).with(:verbose).returns(true)
-
- Puppet::Log.expects(:level=).with(:info)
-
@kick.setup
+ Puppet::Log.level.should == :info
end
it "should Parse puppet config" do
diff --git a/spec/unit/application/master_spec.rb b/spec/unit/application/master_spec.rb
index ea5d3f518..2a24086f3 100755
--- a/spec/unit/application/master_spec.rb
+++ b/spec/unit/application/master_spec.rb
@@ -11,7 +11,6 @@ describe Puppet::Application::Master do
@daemon = stub_everything 'daemon'
Puppet::Daemon.stubs(:new).returns(@daemon)
Puppet::Util::Log.stubs(:newdestination)
- Puppet::Util::Log.stubs(:level=)
Puppet::Node.indirection.stubs(:terminus_class=)
Puppet::Node.indirection.stubs(:cache_class=)
@@ -111,7 +110,6 @@ describe Puppet::Application::Master do
before :each do
Puppet::Log.stubs(:newdestination)
Puppet.stubs(:settraps)
- Puppet::Log.stubs(:level=)
Puppet::SSL::CertificateAuthority.stubs(:instance)
Puppet::SSL::CertificateAuthority.stubs(:ca?)
Puppet.settings.stubs(:use)
@@ -121,18 +119,14 @@ describe Puppet::Application::Master do
it "should set log level to debug if --debug was passed" do
@master.options.stubs(:[]).with(:debug).returns(true)
-
- Puppet::Log.expects(:level=).with(:debug)
-
@master.setup
+ Puppet::Log.level.should == :debug
end
it "should set log level to info if --verbose was passed" do
@master.options.stubs(:[]).with(:verbose).returns(true)
-
- Puppet::Log.expects(:level=).with(:info)
-
@master.setup
+ Puppet::Log.level.should == :info
end
it "should set console as the log destination if no --logdest and --daemonize" do
diff --git a/spec/unit/application/queue_spec.rb b/spec/unit/application/queue_spec.rb
index 87713ca97..d71c879a9 100755
--- a/spec/unit/application/queue_spec.rb
+++ b/spec/unit/application/queue_spec.rb
@@ -10,7 +10,6 @@ describe Puppet::Application::Queue do
@queue.stubs(:puts)
@daemon = stub_everything 'daemon', :daemonize => nil
Puppet::Util::Log.stubs(:newdestination)
- Puppet::Util::Log.stubs(:level=)
Puppet::Resource::Catalog.indirection.stubs(:terminus_class=)
end
@@ -113,18 +112,14 @@ describe Puppet::Application::Queue do
it "should set log level to debug if --debug was passed" do
@queue.options.stubs(:[]).with(:debug).returns(true)
-
- Puppet::Util::Log.expects(:level=).with(:debug)
-
@queue.setup_logs
+ Puppet::Util::Log.level.should == :debug
end
it "should set log level to info if --verbose was passed" do
@queue.options.stubs(:[]).with(:verbose).returns(true)
-
- Puppet::Util::Log.expects(:level=).with(:info)
-
@queue.setup_logs
+ Puppet::Util::Log.level.should == :info
end
[:verbose, :debug].each do |level|
diff --git a/spec/unit/application/resource_spec.rb b/spec/unit/application/resource_spec.rb
index 673bd65d7..af60f12c1 100755
--- a/spec/unit/application/resource_spec.rb
+++ b/spec/unit/application/resource_spec.rb
@@ -7,7 +7,6 @@ describe Puppet::Application::Resource do
before :each do
@resource = Puppet::Application[:resource]
Puppet::Util::Log.stubs(:newdestination)
- Puppet::Util::Log.stubs(:level=)
Puppet::Resource.indirection.stubs(:terminus_class=)
end
@@ -95,7 +94,6 @@ describe Puppet::Application::Resource do
describe "during setup" do
before :each do
Puppet::Log.stubs(:newdestination)
- Puppet::Log.stubs(:level=)
Puppet.stubs(:parse_config)
end
@@ -108,19 +106,15 @@ describe Puppet::Application::Resource do
it "should set log level to debug if --debug was passed" do
@resource.options.stubs(:[]).with(:debug).returns(true)
-
- Puppet::Log.expects(:level=).with(:debug)
-
@resource.setup
+ Puppet::Log.level.should == :debug
end
it "should set log level to info if --verbose was passed" do
@resource.options.stubs(:[]).with(:debug).returns(false)
@resource.options.stubs(:[]).with(:verbose).returns(true)
-
- Puppet::Log.expects(:level=).with(:info)
-
@resource.setup
+ Puppet::Log.level.should == :info
end
it "should Parse puppet config" do
diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb
index f46959092..de1ca1257 100755
--- a/spec/unit/application_spec.rb
+++ b/spec/unit/application_spec.rb
@@ -369,10 +369,8 @@ describe Puppet::Application do
it "should honor option #{level}" do
@app.options.stubs(:[]).with(level).returns(true)
Puppet::Util::Log.stubs(:newdestination)
-
- Puppet::Util::Log.expects(:level=).with(level == :verbose ? :info : :debug)
-
@app.setup
+ Puppet::Util::Log.level.should == (level == :verbose ? :info : :debug)
end
end