diff options
| author | Nick Lewis <nick@puppetlabs.com> | 2010-12-16 11:34:09 -0800 |
|---|---|---|
| committer | Nick Lewis <nick@puppetlabs.com> | 2010-12-16 11:34:09 -0800 |
| commit | a2ff092d8302e09aa79f9bb16636f8298316c3c7 (patch) | |
| tree | cb67d36e37e252edceef1cd848cc32d679f5d20e /spec/unit/application | |
| parent | 4b35402ba85d8842d757becec5c8a7bf4d6f6654 (diff) | |
| parent | 480c399f183627f5f588e9dc9f5f86f683c0e468 (diff) | |
| download | puppet-a2ff092d8302e09aa79f9bb16636f8298316c3c7.tar.gz puppet-a2ff092d8302e09aa79f9bb16636f8298316c3c7.tar.xz puppet-a2ff092d8302e09aa79f9bb16636f8298316c3c7.zip | |
Merge branch 'next'
Diffstat (limited to 'spec/unit/application')
| -rwxr-xr-x | spec/unit/application/agent_spec.rb | 24 | ||||
| -rwxr-xr-x | spec/unit/application/apply_spec.rb | 22 | ||||
| -rwxr-xr-x | spec/unit/application/cert_spec.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/application/describe_spec.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/application/doc_spec.rb | 2 | ||||
| -rw-r--r-- | spec/unit/application/filebucket_spec.rb | 2 | ||||
| -rw-r--r-- | spec/unit/application/inspect_spec.rb | 79 | ||||
| -rwxr-xr-x | spec/unit/application/kick_spec.rb | 10 | ||||
| -rw-r--r-- | spec/unit/application/master_spec.rb | 25 | ||||
| -rwxr-xr-x | spec/unit/application/queue_spec.rb | 12 | ||||
| -rwxr-xr-x | spec/unit/application/resource_spec.rb | 26 |
11 files changed, 143 insertions, 63 deletions
diff --git a/spec/unit/application/agent_spec.rb b/spec/unit/application/agent_spec.rb index 50ef00c57..cee6a0d1a 100755 --- a/spec/unit/application/agent_spec.rb +++ b/spec/unit/application/agent_spec.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../../spec_helper' +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'puppet/agent' require 'puppet/application/agent' @@ -21,9 +21,9 @@ describe Puppet::Application::Agent do Puppet::Util::Log.stubs(:newdestination) Puppet::Util::Log.stubs(:level=) - Puppet::Node.stubs(:terminus_class=) - Puppet::Node.stubs(:cache_class=) - Puppet::Node::Facts.stubs(:terminus_class=) + Puppet::Node.indirection.stubs(:terminus_class=) + Puppet::Node.indirection.stubs(:cache_class=) + Puppet::Node::Facts.indirection.stubs(:terminus_class=) end it "should operate in agent run_mode" do @@ -179,11 +179,11 @@ describe Puppet::Application::Agent do FileTest.stubs(:exists?).returns(true) Puppet[:libdir] = "/dev/null/lib" Puppet::SSL::Host.stubs(:ca_location=) - Puppet::Transaction::Report.stubs(:terminus_class=) - Puppet::Transaction::Report.stubs(:cache_class=) - Puppet::Resource::Catalog.stubs(:terminus_class=) - Puppet::Resource::Catalog.stubs(:cache_class=) - Puppet::Node::Facts.stubs(:terminus_class=) + Puppet::Transaction::Report.indirection.stubs(:terminus_class=) + Puppet::Transaction::Report.indirection.stubs(:cache_class=) + Puppet::Resource::Catalog.indirection.stubs(:terminus_class=) + Puppet::Resource::Catalog.indirection.stubs(:cache_class=) + Puppet::Node::Facts.indirection.stubs(:terminus_class=) @host = stub_everything 'host' Puppet::SSL::Host.stubs(:new).returns(@host) Puppet.stubs(:settraps) @@ -307,13 +307,13 @@ describe Puppet::Application::Agent do end it "should tell the report handler to use REST" do - Puppet::Transaction::Report.expects(:terminus_class=).with(:rest) + Puppet::Transaction::Report.indirection.expects(:terminus_class=).with(:rest) @puppetd.setup end it "should tell the report handler to cache locally as yaml" do - Puppet::Transaction::Report.expects(:cache_class=).with(:yaml) + Puppet::Transaction::Report.indirection.expects(:cache_class=).with(:yaml) @puppetd.setup end @@ -325,7 +325,7 @@ describe Puppet::Application::Agent do end it "should tell the catalog handler to use cache" do - Puppet::Resource::Catalog.expects(:cache_class=).with(:yaml) + Puppet::Resource::Catalog.indirection.expects(:cache_class=).with(:yaml) @puppetd.setup end diff --git a/spec/unit/application/apply_spec.rb b/spec/unit/application/apply_spec.rb index f07416378..e2b6ff5ab 100755 --- a/spec/unit/application/apply_spec.rb +++ b/spec/unit/application/apply_spec.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../../spec_helper' +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'puppet/application/apply' require 'puppet/file_bucket/dipper' @@ -57,7 +57,7 @@ describe Puppet::Application::Apply do Puppet.stubs(:parse_config) Puppet::FileBucket::Dipper.stubs(:new) STDIN.stubs(:read) - Puppet::Transaction::Report.stubs(:cache_class=) + Puppet::Transaction::Report.indirection.stubs(:cache_class=) @apply.options.stubs(:[]).with(any_parameters) end @@ -116,7 +116,7 @@ describe Puppet::Application::Apply do end it "should tell the report handler to cache locally as yaml" do - Puppet::Transaction::Report.expects(:cache_class=).with(:yaml) + Puppet::Transaction::Report.indirection.expects(:cache_class=).with(:yaml) @apply.setup end @@ -185,14 +185,14 @@ describe Puppet::Application::Apply do @apply.options.stubs(:[]) @facts = stub_everything 'facts' - Puppet::Node::Facts.stubs(:find).returns(@facts) + Puppet::Node::Facts.indirection.stubs(:find).returns(@facts) @node = stub_everything 'node' - Puppet::Node.stubs(:find).returns(@node) + Puppet::Node.indirection.stubs(:find).returns(@node) @catalog = stub_everything 'catalog' @catalog.stubs(:to_ral).returns(@catalog) - Puppet::Resource::Catalog.stubs(:find).returns(@catalog) + Puppet::Resource::Catalog.indirection.stubs(:find).returns(@catalog) STDIN.stubs(:read) @@ -248,25 +248,25 @@ describe Puppet::Application::Apply do end it "should collect the node facts" do - Puppet::Node::Facts.expects(:find).returns(@facts) + Puppet::Node::Facts.indirection.expects(:find).returns(@facts) @apply.main end it "should raise an error if we can't find the node" do - Puppet::Node::Facts.expects(:find).returns(nil) + Puppet::Node::Facts.indirection.expects(:find).returns(nil) lambda { @apply.main }.should raise_error end it "should look for the node" do - Puppet::Node.expects(:find).returns(@node) + Puppet::Node.indirection.expects(:find).returns(@node) @apply.main end it "should raise an error if we can't find the node" do - Puppet::Node.expects(:find).returns(nil) + Puppet::Node.indirection.expects(:find).returns(nil) lambda { @apply.main }.should raise_error end @@ -292,7 +292,7 @@ describe Puppet::Application::Apply do end it "should compile the catalog" do - Puppet::Resource::Catalog.expects(:find).returns(@catalog) + Puppet::Resource::Catalog.indirection.expects(:find).returns(@catalog) @apply.main end diff --git a/spec/unit/application/cert_spec.rb b/spec/unit/application/cert_spec.rb index 4663fc938..c7f463ea2 100755 --- a/spec/unit/application/cert_spec.rb +++ b/spec/unit/application/cert_spec.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../../spec_helper' +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'puppet/application/cert' diff --git a/spec/unit/application/describe_spec.rb b/spec/unit/application/describe_spec.rb index 7c64ff86d..47b98a17b 100755 --- a/spec/unit/application/describe_spec.rb +++ b/spec/unit/application/describe_spec.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../../spec_helper' +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'puppet/application/describe' diff --git a/spec/unit/application/doc_spec.rb b/spec/unit/application/doc_spec.rb index 55da5e39a..0fd2c2084 100755 --- a/spec/unit/application/doc_spec.rb +++ b/spec/unit/application/doc_spec.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../../spec_helper' +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'puppet/application/doc' require 'puppet/util/reference' diff --git a/spec/unit/application/filebucket_spec.rb b/spec/unit/application/filebucket_spec.rb index e6272f179..8b811d7c5 100644 --- a/spec/unit/application/filebucket_spec.rb +++ b/spec/unit/application/filebucket_spec.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../../spec_helper' +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'puppet/application/filebucket' require 'puppet/file_bucket/dipper' diff --git a/spec/unit/application/inspect_spec.rb b/spec/unit/application/inspect_spec.rb new file mode 100644 index 000000000..a3cc74d86 --- /dev/null +++ b/spec/unit/application/inspect_spec.rb @@ -0,0 +1,79 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'puppet/application/inspect' +require 'puppet/resource/catalog' +require 'puppet/indirector/catalog/yaml' +require 'puppet/indirector/report/rest' + +describe Puppet::Application::Inspect do + before :each do + @inspect = Puppet::Application[:inspect] + end + + describe "during setup" do + it "should print its configuration if asked" do + Puppet[:configprint] = "all" + + Puppet.settings.expects(:print_configs).returns(true) + lambda { @inspect.setup }.should raise_error(SystemExit) + end + + it "should fail if reporting is turned off" do + Puppet[:report] = false + lambda { @inspect.setup }.should raise_error(/report=true/) + end + end + + describe "when executing" do + before :each do + Puppet[:report] = true + Puppet::Util::Log.stubs(:newdestination) + Puppet::Transaction::Report::Rest.any_instance.stubs(:save) + @inspect.setup + end + + it "should retrieve the local catalog" do + Puppet::Resource::Catalog::Yaml.any_instance.expects(:find).with {|request| request.key == Puppet[:certname] }.returns(Puppet::Resource::Catalog.new) + + @inspect.run_command + end + + it "should save the report to REST" do + Puppet::Resource::Catalog::Yaml.any_instance.stubs(:find).returns(Puppet::Resource::Catalog.new) + Puppet::Transaction::Report::Rest.any_instance.expects(:save).with {|request| request.instance.host == Puppet[:certname] } + + @inspect.run_command + end + + it "should audit the specified properties" do + catalog = Puppet::Resource::Catalog.new + file = Tempfile.new("foo") + file.puts("file contents") + file.flush + resource = Puppet::Resource.new(:file, file.path, :parameters => {:audit => "all"}) + catalog.add_resource(resource) + Puppet::Resource::Catalog::Yaml.any_instance.stubs(:find).returns(catalog) + + events = nil + + Puppet::Transaction::Report::Rest.any_instance.expects(:save).with do |request| + events = request.instance.resource_statuses.values.first.events + end + + @inspect.run_command + + properties = events.inject({}) do |property_values, event| + property_values.merge(event.property => event.previous_value) + end + properties["ensure"].should == :file + properties["content"].should == "{md5}#{Digest::MD5.hexdigest("file contents\n")}" + end + end + + after :all do + Puppet::Resource::Catalog.indirection.reset_terminus_class + Puppet::Transaction::Report.indirection.terminus_class = :processor + end +end diff --git a/spec/unit/application/kick_spec.rb b/spec/unit/application/kick_spec.rb index dea7ec147..227874171 100755 --- a/spec/unit/application/kick_spec.rb +++ b/spec/unit/application/kick_spec.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../../spec_helper' +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'puppet/application/kick' @@ -163,7 +163,7 @@ describe Puppet::Application::Kick do @kick.options.stubs(:[]).with(:all).returns(true) @kick.stubs(:puts) - Puppet::Node.expects(:search).with("whatever",:fqdn => :something).returns([]) + Puppet::Node.indirection.expects(:search).with("whatever",:fqdn => :something).returns([]) @kick.setup end @@ -172,7 +172,7 @@ describe Puppet::Application::Kick do @kick.options.stubs(:[]).with(:all).returns(true) @kick.stubs(:puts) - Puppet::Node.expects(:search).with("whatever",:fqdn => nil).returns([]) + Puppet::Node.indirection.expects(:search).with("whatever",:fqdn => nil).returns([]) @kick.setup end @@ -182,7 +182,7 @@ describe Puppet::Application::Kick do @kick.stubs(:puts) @kick.classes = ['class'] - Puppet::Node.expects(:search).with("whatever", :class => "class", :fqdn => nil).returns([]) + Puppet::Node.indirection.expects(:search).with("whatever", :class => "class", :fqdn => nil).returns([]) @kick.setup end @@ -279,7 +279,7 @@ describe Puppet::Application::Kick do end it "should call run on a Puppet::Run for the given host" do - @agent_run.expects(:save).with('https://host:8139/production/run/host').returns(@agent_run) + Puppet::Run.indirection.expects(:save).with(@agent_run, 'https://host:8139/production/run/host').returns(@agent_run) @kick.run_for_host('host') end diff --git a/spec/unit/application/master_spec.rb b/spec/unit/application/master_spec.rb index e657445a4..cf8593108 100644 --- a/spec/unit/application/master_spec.rb +++ b/spec/unit/application/master_spec.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../../spec_helper' +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'puppet/application/master' require 'puppet/daemon' @@ -14,12 +14,13 @@ describe Puppet::Application::Master do Puppet::Util::Log.stubs(:newdestination) Puppet::Util::Log.stubs(:level=) - Puppet::Node.stubs(:terminus_class=) - Puppet::Node.stubs(:cache_class=) - Puppet::Node::Facts.stubs(:terminus_class=) - Puppet::Node::Facts.stubs(:cache_class=) - Puppet::Transaction::Report.stubs(:terminus_class=) - Puppet::Resource::Catalog.stubs(:terminus_class=) + Puppet::Node.indirection.stubs(:terminus_class=) + Puppet::Node.indirection.stubs(:cache_class=) + Puppet::Node::Facts.indirection.stubs(:terminus_class=) + Puppet::Node::Facts.indirection.stubs(:cache_class=) + Puppet::Transaction::Report.indirection.stubs(:terminus_class=) + Puppet::Resource::Catalog.indirection.stubs(:terminus_class=) + Puppet::SSL::Host.stubs(:ca_location=) end it "should operate in master run_mode" do @@ -183,7 +184,7 @@ describe Puppet::Application::Master do end it "should cache class in yaml" do - Puppet::Node.expects(:cache_class=).with(:yaml) + Puppet::Node.indirection.expects(:cache_class=).with(:yaml) @master.setup end @@ -298,7 +299,7 @@ describe Puppet::Application::Master do it "should compile a catalog for the specified node" do @master.options[:node] = "foo" - Puppet::Resource::Catalog.expects(:find).with("foo").returns Puppet::Resource::Catalog.new + Puppet::Resource::Catalog.indirection.expects(:find).with("foo").returns Puppet::Resource::Catalog.new $stdout.stubs(:puts) @master.compile @@ -306,7 +307,7 @@ describe Puppet::Application::Master do it "should convert the catalog to a pure-resource catalog and use 'jj' to pretty-print the catalog" do catalog = Puppet::Resource::Catalog.new - Puppet::Resource::Catalog.expects(:find).returns catalog + Puppet::Resource::Catalog.indirection.expects(:find).returns catalog catalog.expects(:to_resource).returns("rescat") @@ -318,7 +319,7 @@ describe Puppet::Application::Master do it "should exit with error code 30 if no catalog can be found" do @master.options[:node] = "foo" - Puppet::Resource::Catalog.expects(:find).returns nil + Puppet::Resource::Catalog.indirection.expects(:find).returns nil @master.expects(:exit).with(30) $stderr.expects(:puts) @@ -327,7 +328,7 @@ describe Puppet::Application::Master do it "should exit with error code 30 if there's a failure" do @master.options[:node] = "foo" - Puppet::Resource::Catalog.expects(:find).raises ArgumentError + Puppet::Resource::Catalog.indirection.expects(:find).raises ArgumentError @master.expects(:exit).with(30) $stderr.expects(:puts) diff --git a/spec/unit/application/queue_spec.rb b/spec/unit/application/queue_spec.rb index bd0d53ab1..2ff9001af 100755 --- a/spec/unit/application/queue_spec.rb +++ b/spec/unit/application/queue_spec.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../../spec_helper' +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'puppet/application/queue' require 'puppet/indirector/catalog/queue' @@ -13,7 +13,7 @@ describe Puppet::Application::Queue do Puppet::Util::Log.stubs(:newdestination) Puppet::Util::Log.stubs(:level=) - Puppet::Resource::Catalog.stubs(:terminus_class=) + Puppet::Resource::Catalog.indirection.stubs(:terminus_class=) end it "should ask Puppet::Application to parse Puppet configuration file" do @@ -80,7 +80,7 @@ describe Puppet::Application::Queue do @queue.daemon.stubs(:daemonize) Puppet.stubs(:info) Puppet.features.stubs(:stomp?).returns true - Puppet::Resource::Catalog.stubs(:terminus_class=) + Puppet::Resource::Catalog.indirection.stubs(:terminus_class=) Puppet.stubs(:settraps) Puppet.settings.stubs(:print_config?) Puppet.settings.stubs(:print_config) @@ -144,7 +144,7 @@ describe Puppet::Application::Queue do end it "should configure the Catalog class to use ActiveRecord" do - Puppet::Resource::Catalog.expects(:terminus_class=).with(:active_record) + Puppet::Resource::Catalog.indirection.expects(:terminus_class=).with(:active_record) @queue.setup end @@ -171,8 +171,8 @@ describe Puppet::Application::Queue do end it "should log and save each catalog passed by the queue" do - catalog = mock 'catalog', :name => 'eh' - catalog.expects(:save) + catalog = Puppet::Resource::Catalog.new('eh') + Puppet::Resource::Catalog.indirection.expects(:save).with(catalog) Puppet::Resource::Catalog::Queue.expects(:subscribe).yields(catalog) Puppet.expects(:notice).times(2) diff --git a/spec/unit/application/resource_spec.rb b/spec/unit/application/resource_spec.rb index b6c52b11e..3e3f8296b 100755 --- a/spec/unit/application/resource_spec.rb +++ b/spec/unit/application/resource_spec.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../../spec_helper' +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'puppet/application/resource' @@ -162,21 +162,21 @@ describe Puppet::Application::Resource do @resource.stubs(:puts) @resource.host = 'host' - Puppet::Resource.stubs(:find ).never - Puppet::Resource.stubs(:search).never - Puppet::Resource.stubs(:save ).never + Puppet::Resource.indirection.stubs(:find ).never + Puppet::Resource.indirection.stubs(:search).never + Puppet::Resource.indirection.stubs(:save ).never end it "should search for resources" do @resource.command_line.stubs(:args).returns(['type']) - Puppet::Resource.expects(:search).with('https://host:8139/production/resources/type/', {}).returns([]) + Puppet::Resource.indirection.expects(:search).with('https://host:8139/production/resources/type/', {}).returns([]) @resource.main end it "should describe the given resource" do @resource.command_line.stubs(:args).returns(['type', 'name']) x = stub_everything 'resource' - Puppet::Resource.expects(:find).with('https://host:8139/production/resources/type/name').returns(x) + Puppet::Resource.indirection.expects(:find).with('https://host:8139/production/resources/type/name').returns(x) @resource.main end @@ -184,7 +184,7 @@ describe Puppet::Application::Resource do @resource.command_line.stubs(:args).returns(['type','name','param=temp']) res = stub "resource" - res.expects(:save).with('https://host:8139/production/resources/type/name').returns(res) + Puppet::Resource.indirection.expects(:save).with(res, 'https://host:8139/production/resources/type/name').returns(res) res.expects(:collect) res.expects(:to_manifest) Puppet::Resource.expects(:new).with('type', 'name', :parameters => {'param' => 'temp'}).returns(res) @@ -199,20 +199,20 @@ describe Puppet::Application::Resource do @resource.stubs(:puts) @resource.host = nil - Puppet::Resource.stubs(:find ).never - Puppet::Resource.stubs(:search).never - Puppet::Resource.stubs(:save ).never + Puppet::Resource.indirection.stubs(:find ).never + Puppet::Resource.indirection.stubs(:search).never + Puppet::Resource.indirection.stubs(:save ).never end it "should search for resources" do - Puppet::Resource.expects(:search).with('type/', {}).returns([]) + Puppet::Resource.indirection.expects(:search).with('type/', {}).returns([]) @resource.main end it "should describe the given resource" do @resource.command_line.stubs(:args).returns(['type','name']) x = stub_everything 'resource' - Puppet::Resource.expects(:find).with('type/name').returns(x) + Puppet::Resource.indirection.expects(:find).with('type/name').returns(x) @resource.main end @@ -220,7 +220,7 @@ describe Puppet::Application::Resource do @resource.command_line.stubs(:args).returns(['type','name','param=temp']) res = stub "resource" - res.expects(:save).with('type/name').returns(res) + Puppet::Resource.indirection.expects(:save).with(res, 'type/name').returns(res) res.expects(:collect) res.expects(:to_manifest) Puppet::Resource.expects(:new).with('type', 'name', :parameters => {'param' => 'temp'}).returns(res) |
