From 3df0490c9dbc59e27869e09864177536400a5ae3 Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Thu, 5 Aug 2010 11:09:25 -0700 Subject: [#4298] Puppet apply prints an error if the file to apply doesn't exist Also warns you it's skipping files if you pass it more than one file to apply. Reviewed-by: Nick Lewis Signed-off-by: Matt Robinson --- spec/unit/application/apply_spec.rb | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'spec/unit') diff --git a/spec/unit/application/apply_spec.rb b/spec/unit/application/apply_spec.rb index 0b00d1a2e..8c53136d0 100755 --- a/spec/unit/application/apply_spec.rb +++ b/spec/unit/application/apply_spec.rb @@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/application/apply' +require 'puppet/file_bucket/dipper' describe Puppet::Application::Apply do before :each do @@ -53,7 +54,6 @@ describe Puppet::Application::Apply do Puppet.stubs(:trap) Puppet::Log.stubs(:level=) Puppet.stubs(:parse_config) - require 'lib/puppet/file_bucket/dipper' Puppet::FileBucket::Dipper.stubs(:new) STDIN.stubs(:read) @@ -212,7 +212,8 @@ describe Puppet::Application::Apply do @apply.main end - it "should set the manifest if some files are passed on command line" do + it "should set the manifest if a file is passed on command line and the file exists" do + File.stubs(:exist?).with('site.pp').returns true @apply.command_line.stubs(:args).returns(['site.pp']) Puppet.expects(:[]=).with(:manifest,"site.pp") @@ -220,6 +221,23 @@ describe Puppet::Application::Apply do @apply.main end + it "should raise an error if a file is passed on command line and the file does not exist" do + File.stubs(:exist?).with('noexist.pp').returns false + @apply.command_line.stubs(:args).returns(['noexist.pp']) + lambda { @apply.main }.should raise_error(RuntimeError, 'Could not find file noexist.pp') + end + + it "should set the manifest to the first file and warn other files will be skipped" do + File.stubs(:exist?).with('starwarsIV').returns true + File.expects(:exist?).with('starwarsI').never + @apply.command_line.stubs(:args).returns(['starwarsIV', 'starwarsI', 'starwarsII']) + + Puppet.expects(:[]=).with(:manifest,"starwarsIV") + Puppet.expects(:warning).with('Only one file can be applied per run. Skipping starwarsI, starwarsII') + + @apply.main + end + it "should collect the node facts" do Puppet::Node::Facts.expects(:find).returns(@facts) @@ -232,7 +250,7 @@ describe Puppet::Application::Apply do lambda { @apply.main }.should raise_error end - it "should find the node" do + it "should look for the node" do Puppet::Node.expects(:find).returns(@node) @apply.main -- cgit From 82b4f04f6b8fee7ada275fc63e519a08e1c2b0a5 Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Sat, 14 Aug 2010 18:25:24 -0700 Subject: Maint. -- Fix test failures broken by previous commit This basically involved adding a search method to the yaml indirector, which I did by copying the one from ssl_file and fiddling with it until the tests passed. Since the most straight forward way to do this required extending the interface to the path method I added tests for the additional behaviour. --- spec/unit/indirector/yaml_spec.rb | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'spec/unit') diff --git a/spec/unit/indirector/yaml_spec.rb b/spec/unit/indirector/yaml_spec.rb index 134d476ba..86c13c5a0 100755 --- a/spec/unit/indirector/yaml_spec.rb +++ b/spec/unit/indirector/yaml_spec.rb @@ -40,6 +40,18 @@ describe Puppet::Indirector::Yaml, " when choosing file location" do @store.path(:me).should =~ %r{^/client/yaml/dir} end + it "should use the extension if one is specified" do + Puppet.run_mode.expects(:master?).returns true + Puppet.settings.expects(:value).with(:yamldir).returns "/server/yaml/dir" + @store.path(:me,'.farfignewton').should =~ %r{\.farfignewton$} + end + + it "should assume an extension of .yaml if none is specified" do + Puppet.run_mode.expects(:master?).returns true + Puppet.settings.expects(:value).with(:yamldir).returns "/server/yaml/dir" + @store.path(:me).should =~ %r{\.yaml$} + end + it "should store all files in a single file root set in the Puppet defaults" do @store.path(:me).should =~ %r{^#{@dir}} end @@ -120,8 +132,8 @@ describe Puppet::Indirector::Yaml, " when choosing file location" do @request = stub 'request', :key => "*", :instance => @subject @one = mock 'one' @two = mock 'two' - @store.expects(:base).returns "/my/yaml/dir" - Dir.expects(:glob).with(File.join("/my/yaml/dir", @store.class.indirection_name.to_s, @request.key)).returns(%w{one.yaml two.yaml}) + @store.expects(:path).with(@request.key,'').returns :glob + Dir.expects(:glob).with(:glob).returns(%w{one.yaml two.yaml}) YAML.expects(:load_file).with("one.yaml").returns @one; YAML.expects(:load_file).with("two.yaml").returns @two; @store.search(@request).should == [@one, @two] @@ -130,16 +142,16 @@ describe Puppet::Indirector::Yaml, " when choosing file location" do it "should return an array containing a single instance of fact when globbing 'one*'" do @request = stub 'request', :key => "one*", :instance => @subject @one = mock 'one' - @store.expects(:base).returns "/my/yaml/dir" - Dir.expects(:glob).with(File.join("/my/yaml/dir", @store.class.indirection_name.to_s, @request.key)).returns(%w{one.yaml}) + @store.expects(:path).with(@request.key,'').returns :glob + Dir.expects(:glob).with(:glob).returns(%w{one.yaml}) YAML.expects(:load_file).with("one.yaml").returns @one; @store.search(@request).should == [@one] end it "should return an empty array when the glob doesn't match anything" do @request = stub 'request', :key => "f*ilglobcanfail*", :instance => @subject - @store.expects(:base).returns "/my/yaml/dir" - Dir.expects(:glob).with(File.join("/my/yaml/dir", @store.class.indirection_name.to_s, @request.key)).returns([]) + @store.expects(:path).with(@request.key,'').returns :glob + Dir.expects(:glob).with(:glob).returns [] @store.search(@request).should == [] end end -- cgit From 57bb06b557c74e227cb0f9799e698aecf90ea9a4 Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Mon, 16 Aug 2010 17:15:45 -0700 Subject: [#4545] Remove obsolete 'trac' specs The method that these specs were testing has been removed, causing the specs to fail. --- spec/unit/application/doc_spec.rb | 19 ------------------- 1 file changed, 19 deletions(-) (limited to 'spec/unit') diff --git a/spec/unit/application/doc_spec.rb b/spec/unit/application/doc_spec.rb index 7a22f5b2e..55da5e39a 100755 --- a/spec/unit/application/doc_spec.rb +++ b/spec/unit/application/doc_spec.rb @@ -27,10 +27,6 @@ describe Puppet::Application::Doc do @doc.should respond_to(:rdoc) end - it "should declare a trac command" do - @doc.should respond_to(:trac) - end - it "should declare a fallback for unknown options" do @doc.should respond_to(:handle_unknown) end @@ -270,21 +266,6 @@ describe Puppet::Application::Doc do end describe "when running" do - before :each do - end - - describe "in trac mode" do - it "should call trac for each reference" do - ref = stub 'ref' - Puppet::Util::Reference.stubs(:reference).with(:ref).returns(ref) - @doc.options.stubs(:[]).with(:references).returns([:ref]) - @doc.options.stubs(:[]).with(:mode).returns(:trac) - - ref.expects(:trac) - - @doc.trac - end - end describe "in rdoc mode" do before :each do -- cgit From 20f4b903acd91074778f379631cf7545fdff9eb8 Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Sun, 15 Aug 2010 18:56:26 -0700 Subject: Fix for #4518 -- classes not getting added to compiler.classes The responsibility for adding classes to the compiler's classes list (for use in constructing classes.txt) moved around a bit in the 0.25 to 2.6 transition before being dropped in a merge conflict resolution. Ooops. This restores it, and adds tests to prevent regression. --- spec/unit/resource/type_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'spec/unit') diff --git a/spec/unit/resource/type_spec.rb b/spec/unit/resource/type_spec.rb index 4d3942c5c..f58092ec5 100755 --- a/spec/unit/resource/type_spec.rb +++ b/spec/unit/resource/type_spec.rb @@ -412,6 +412,23 @@ describe Puppet::Resource::Type do @type = Puppet::Resource::Type.new(:hostclass, "foo") end + it "should add hostclass names to the classes list" do + @type.evaluate_code(@resource) + @compiler.catalog.classes.should be_include("foo") + end + + it "should add node names to the classes list" do + @type = Puppet::Resource::Type.new(:node, "foo") + @type.evaluate_code(@resource) + @compiler.catalog.classes.should be_include("foo") + end + + it "should not add defined resource names to the classes list" do + @type = Puppet::Resource::Type.new(:definition, "foo") + @type.evaluate_code(@resource) + @compiler.catalog.classes.should_not be_include("foo") + end + it "should set all of its parameters in a subscope" do subscope = stub 'subscope', :compiler => @compiler @type.expects(:subscope).with(@scope, @resource).returns subscope -- cgit From 491c31dcbdb0977c0377cb276cfe32a4c24e0e1a Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Sun, 22 Aug 2010 10:14:03 -0700 Subject: Fix for #4542 -- included classes weren't assigned proper stages This commit unifies the code paths on which classes are added, alters the default stage to respect the stage of the parent if any, and assures that the resource is notified if its stage is assigned (turning an implicit stage into an explicit one). --- spec/unit/parser/compiler_spec.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'spec/unit') diff --git a/spec/unit/parser/compiler_spec.rb b/spec/unit/parser/compiler_spec.rb index e8c06dd0b..22d52f257 100755 --- a/spec/unit/parser/compiler_spec.rb +++ b/spec/unit/parser/compiler_spec.rb @@ -430,7 +430,18 @@ describe Puppet::Parser::Compiler do lambda { @compiler.add_resource(@scope, resource) }.should raise_error(ArgumentError) end - it "should add edges from the class resources to the main stage if no stage is specified" do + it "should add edges from the class resources to the parent's stage if no stage is specified" do + main = @compiler.catalog.resource(:stage, :main) + foo_stage = resource(:stage, :foo_stage) + @compiler.add_resource(@scope, foo_stage) + resource = resource(:class, "foo") + @scope.stubs(:resource).returns(:stage => :foo_stage) + @compiler.add_resource(@scope, resource) + + @compiler.catalog.should be_edge(foo_stage, resource) + end + + it "should add edges from top-level class resources to the main stage if no stage is specified" do main = @compiler.catalog.resource(:stage, :main) resource = resource(:class, "foo") @compiler.add_resource(@scope, resource) -- cgit