diff options
| author | Jesse Wolfe <jes5199@gmail.com> | 2010-07-27 10:17:44 -0700 |
|---|---|---|
| committer | Jesse Wolfe <jes5199@gmail.com> | 2010-07-27 10:17:44 -0700 |
| commit | b53e7d78e2e87571ae53170e9716b9ccd75da6e2 (patch) | |
| tree | 58489a37bd0ee14b3d053a0e23f9638b4f6205e7 /spec | |
| parent | 94edd404130b4236f0c65a579857e3a25c5ee17f (diff) | |
| parent | ecf44e4408c168893d74af58a4c7c8606634a844 (diff) | |
Merge commit '2.6.1rc1' into next
Diffstat (limited to 'spec')
| -rwxr-xr-x | spec/unit/application_spec.rb | 14 | ||||
| -rwxr-xr-x | spec/unit/node/environment_spec.rb | 35 | ||||
| -rwxr-xr-x | spec/unit/parser/functions/extlookup_spec.rb | 85 | ||||
| -rw-r--r-- | spec/unit/parser/functions/include_spec.rb | 55 | ||||
| -rwxr-xr-x | spec/unit/parser/lexer_spec.rb | 3 | ||||
| -rw-r--r-- | spec/unit/resource/type_collection_spec.rb | 8 | ||||
| -rwxr-xr-x | spec/unit/simple_graph_spec.rb | 14 | ||||
| -rwxr-xr-x | spec/unit/type/file/content_spec.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/util/rdoc/parser_spec.rb | 6 | ||||
| -rwxr-xr-x | spec/unit/util/rdoc_spec.rb | 13 |
10 files changed, 214 insertions, 21 deletions
diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb index 3c354cce9..433809172 100755 --- a/spec/unit/application_spec.rb +++ b/spec/unit/application_spec.rb @@ -194,7 +194,6 @@ describe Puppet::Application do it "should create a new option parser when needed" do option_parser = stub "option parser" option_parser.stubs(:on) - option_parser.stubs(:default_argv=) OptionParser.expects(:new).returns(option_parser).once @app.option_parser.should == option_parser @app.option_parser.should == option_parser @@ -203,7 +202,6 @@ describe Puppet::Application do it "should pass the banner to the option parser" do option_parser = stub "option parser" option_parser.stubs(:on) - option_parser.stubs(:default_argv=) @app.class.instance_eval do banner "banner" end @@ -213,15 +211,6 @@ describe Puppet::Application do @app.option_parser end - it "should set the optionparser's args to the command line args" do - option_parser = stub "option parser" - option_parser.stubs(:on) - option_parser.expects(:default_argv=).with(%w{ fake args }) - @app.command_line.stubs(:args).returns(%w{ fake args }) - OptionParser.expects(:new).returns(option_parser) - @app.option_parser - end - it "should get options from Puppet.settings.optparse_addargs" do Puppet.settings.expects(:optparse_addargs).returns([]) @@ -237,7 +226,8 @@ describe Puppet::Application do end it "should ask OptionParser to parse the command-line argument" do - @app.option_parser.expects(:parse!) + @app.command_line.stubs(:args).returns(%w{ fake args }) + @app.option_parser.expects(:parse!).with(%w{ fake args }) @app.parse_options end diff --git a/spec/unit/node/environment_spec.rb b/spec/unit/node/environment_spec.rb index b400865a2..6edcce56c 100755 --- a/spec/unit/node/environment_spec.rb +++ b/spec/unit/node/environment_spec.rb @@ -53,6 +53,7 @@ describe Puppet::Node::Environment do @env = Puppet::Node::Environment.new("dev") @collection = Puppet::Resource::TypeCollection.new(@env) @collection.stubs(:perform_initial_import) + Thread.current[:known_resource_types] = nil end it "should create a resource type collection if none exists" do @@ -71,13 +72,41 @@ describe Puppet::Node::Environment do @env.known_resource_types end - it "should create and return a new collection rather than returning a stale collection" do - @env.known_resource_types.expects(:stale?).returns true + it "should return the same collection even if stale if it's the same thread" do + Puppet::Resource::TypeCollection.stubs(:new).returns @collection + @env.known_resource_types.stubs(:stale?).returns true - Puppet::Resource::TypeCollection.expects(:new).returns @collection + @env.known_resource_types.should equal(@collection) + end + + it "should return the current thread associated collection if there is one" do + Thread.current[:known_resource_types] = @collection @env.known_resource_types.should equal(@collection) end + + it "should give to all threads the same collection if it didn't change" do + Puppet::Resource::TypeCollection.expects(:new).with(@env).returns @collection + @env.known_resource_types + + t = Thread.new { + @env.known_resource_types.should equal(@collection) + } + t.join + end + + it "should give to new threads a new collection if it isn't stale" do + Puppet::Resource::TypeCollection.expects(:new).with(@env).returns @collection + @env.known_resource_types.expects(:stale?).returns(true) + + Puppet::Resource::TypeCollection.expects(:new).returns @collection + + t = Thread.new { + @env.known_resource_types.should equal(@collection) + } + t.join + end + end [:modulepath, :manifestdir].each do |setting| diff --git a/spec/unit/parser/functions/extlookup_spec.rb b/spec/unit/parser/functions/extlookup_spec.rb new file mode 100755 index 000000000..bf2880345 --- /dev/null +++ b/spec/unit/parser/functions/extlookup_spec.rb @@ -0,0 +1,85 @@ +#! /usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' +require 'tempfile' + +describe "the extlookup function" do + + before :each do + @scope = Puppet::Parser::Scope.new + + @scope.stubs(:environment).returns(Puppet::Node::Environment.new('production')) + end + + it "should exist" do + Puppet::Parser::Functions.function("extlookup").should == "function_extlookup" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_extlookup([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should raise a ParseError if there is more than 3 arguments" do + lambda { @scope.function_extlookup(["foo", "bar", "baz", "gazonk"]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return the default" do + result = @scope.function_extlookup([ "key", "default"]) + result.should == "default" + end + + it "should lookup the key in a supplied datafile" do + t = Tempfile.new('extlookup.csv') do + t.puts 'key,value' + t.puts 'nonkey,nonvalue' + t.close + + result = @scope.function_extlookup([ "key", "default", t.path]) + result.should == "value" + end + end + + it "should return an array if the datafile contains more than two columns" do + t = Tempfile.new('extlookup.csv') do + t.puts 'key,value1,value2' + t.puts 'nonkey,nonvalue,nonvalue' + t.close + + result = @scope.function_extlookup([ "key", "default", t.path]) + result.should == ["value1", "value2"] + end + end + + it "should raise an error if there's no matching key and no default" do + t = Tempfile.new('extlookup.csv') do + t.puts 'key,value' + t.puts 'nonkey,nonvalue' + t.close + + result = @scope.function_extlookup([ "key", nil, t.path]) + result.should == "value" + end + end + + describe "should look in $extlookup_datadir for data files listed by $extlookup_precedence" do + before do + @scope.stubs(:lookupvar).with('extlookup_datadir').returns("/tmp") + @scope.stubs(:lookupvar).with('extlookup_precedence').returns(["one","two"]) + File.open("/tmp/one.csv","w"){|one| one.puts "key,value1" } + File.open("/tmp/two.csv","w") do |two| + two.puts "key,value2" + two.puts "key2,value_two" + end + end + + it "when the key is in the first file" do + result = @scope.function_extlookup([ "key" ]) + result.should == "value1" + end + + it "when the key is in the second file" do + result = @scope.function_extlookup([ "key2" ]) + result.should == "value_two" + end + end +end diff --git a/spec/unit/parser/functions/include_spec.rb b/spec/unit/parser/functions/include_spec.rb new file mode 100644 index 000000000..e5f051906 --- /dev/null +++ b/spec/unit/parser/functions/include_spec.rb @@ -0,0 +1,55 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +describe "the 'include' function" do + + before :each do + Puppet::Node::Environment.stubs(:current).returns(nil) + @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foo")) + @scope = Puppet::Parser::Scope.new(:compiler => @compiler) + # MQR TODO: Without the following stub these tests cause hundreds of spurious errors in + # subsequent tests. With it, there are no spurious failures and all but one + # of the tests (marked pending, bellow) fail. This needs a better solution. + Puppet::Parser::Resource.stubs(:new).with('stage', :main, :scope => @scope).returns 'foo' + end + + it "should exist" do + Puppet::Parser::Functions.function("include").should == "function_include" + end + + it "should include a single class" do + inc = "foo" + @compiler.expects(:evaluate_classes).with {|klasses,parser,lazy| klasses == [inc]}.returns([inc]) + @scope.function_include("foo") + end + + it "should include multiple classes" do + inc = ["foo","bar"] + @compiler.expects(:evaluate_classes).with {|klasses,parser,lazy| klasses == inc}.returns(inc) + @scope.function_include(["foo","bar"]) + end + + it "should not lazily evaluate the included class" do + @compiler.expects(:evaluate_classes).with {|klasses,parser,lazy| lazy == false}.returns("foo") + @scope.function_include("foo") + end + + it "should allow a parent to include its child" do + pending "Resolution of MQR TODO item, above" + @parent_type = Puppet::Resource::Type.new(:hostclass, "parent") + @parent_resource = Puppet::Parser::Resource.new(:hostclass, "parent", :scope => @scope) + @subscope = @parent_type.subscope(@scope,@parent_resource) + @scope.environment.known_resource_types.stubs(:find_hostclass).with{|nses,name| name.downcase == "parent"}.returns(@parent_type) + + @type = Puppet::Resource::Type.new(:hostclass, "foo") + @type.stubs(:parent_scope).returns(@subscope) + @type.parent = "parent" + @resource = Puppet::Parser::Resource.new(:hostclass, "foo", :scope => @subscope) + @resource.stubs(:resource_type).returns(@type) + @scope.environment.known_resource_types.stubs(:find_hostclass).with{|nses,name| name.downcase == "foo"}.returns(@parent_type) + Puppet::Resource.stubs(:new).returns(@resource) + Puppet::Parser::Resource.stubs(:new).returns(@resource) + lambda { @subscope.function_include("foo") }.should_not raise_error + end +end diff --git a/spec/unit/parser/lexer_spec.rb b/spec/unit/parser/lexer_spec.rb index d3d2a0a31..a85d1b257 100755 --- a/spec/unit/parser/lexer_spec.rb +++ b/spec/unit/parser/lexer_spec.rb @@ -410,6 +410,9 @@ describe Puppet::Parser::Lexer,"when lexing strings" do %q{'single quoted string')} => [[:STRING,'single quoted string']], %q{"double quoted string"} => [[:STRING,'double quoted string']], %q{'single quoted string with an escaped "\\'"'} => [[:STRING,'single quoted string with an escaped "\'"']], + %q{'single quoted string with an escaped "\$"'} => [[:STRING,'single quoted string with an escaped "\$"']], + %q{'single quoted string with an escaped "\."'} => [[:STRING,'single quoted string with an escaped "\."']], + %q{'single quoted string with an escaped "\\\\"'} => [[:STRING,'single quoted string with an escaped "\\\\"']], %q{"string with an escaped '\\"'"} => [[:STRING,"string with an escaped '\"'"]], %q{"string with an escaped '\\$'"} => [[:STRING,"string with an escaped '$'"]], %q{"string with $v (but no braces)"} => [[:DQPRE,"string with "],[:VARIABLE,'v'],[:DQPOST,' (but no braces)']], diff --git a/spec/unit/resource/type_collection_spec.rb b/spec/unit/resource/type_collection_spec.rb index 09643cd24..45fc05da0 100644 --- a/spec/unit/resource/type_collection_spec.rb +++ b/spec/unit/resource/type_collection_spec.rb @@ -400,6 +400,14 @@ describe Puppet::Resource::TypeCollection do @parser.expects(:parse).raises ArgumentError lambda { @code.perform_initial_import }.should raise_error(Puppet::Error) end + + it "should not do anything if the ignore_import settings is set" do + Puppet.settings[:ignoreimport] = true + @parser.expects(:string=).never + @parser.expects(:file=).never + @parser.expects(:parse).never + @code.perform_initial_import + end end describe "when determining the configuration version" do diff --git a/spec/unit/simple_graph_spec.rb b/spec/unit/simple_graph_spec.rb index 83e674139..2ca8888c5 100755 --- a/spec/unit/simple_graph_spec.rb +++ b/spec/unit/simple_graph_spec.rb @@ -439,7 +439,8 @@ describe Puppet::SimpleGraph do @middle = Container.new("middle", ["e", "f", @two]) @top = Container.new("top", ["g", "h", @middle, @one, @three]) @empty = Container.new("empty", []) - + + @whit = Puppet::Type.type(:whit) @stage = Puppet::Type.type(:stage).new(:name => "foo") @contgraph = @top.to_graph @@ -499,8 +500,17 @@ describe Puppet::SimpleGraph do end end + it "should contain a whit-resource to mark the place held by the empty container" do + @depgraph.vertices.find_all { |v| v.is_a?(@whit) }.length.should == 1 + end + + it "should replace edges to empty containers with edges to their residual whit" do + emptys_whit = @depgraph.vertices.find_all { |v| v.is_a?(@whit) }.first + @depgraph.should be_edge("c", emptys_whit) + end + it "should no longer contain anything but the non-container objects" do - @depgraph.vertices.find_all { |v| ! v.is_a?(String) }.should be_empty + @depgraph.vertices.find_all { |v| ! v.is_a?(String) and ! v.is_a?(@whit)}.should be_empty end it "should copy labels" do diff --git a/spec/unit/type/file/content_spec.rb b/spec/unit/type/file/content_spec.rb index e4b9f9bc6..a01a14a59 100755 --- a/spec/unit/type/file/content_spec.rb +++ b/spec/unit/type/file/content_spec.rb @@ -362,7 +362,7 @@ describe content do end it "should send the correct indirection uri" do - @conn.expects(:request_get).with { |uri,headers| uri == "/production/file_content//path/to/source" }.yields(@response) + @conn.expects(:request_get).with { |uri,headers| uri == "/production/file_content/path/to/source" }.yields(@response) @content.write(@fh) end diff --git a/spec/unit/util/rdoc/parser_spec.rb b/spec/unit/util/rdoc/parser_spec.rb index a9c8190a6..79195e657 100755 --- a/spec/unit/util/rdoc/parser_spec.rb +++ b/spec/unit/util/rdoc/parser_spec.rb @@ -85,8 +85,8 @@ describe RDoc::Parser do @parser.scan_top_level(@topcontainer) end - it "should set the module as global if we parse the global manifests (ie <site> module)" do - @parser.stubs(:split_module).returns("<site>") + it "should set the module as global if we parse the global manifests (ie __site__ module)" do + @parser.stubs(:split_module).returns(RDoc::Parser::SITE) @parser.stubs(:parse_elements) @topcontainer.expects(:global=).with(true) @@ -131,7 +131,7 @@ describe RDoc::Parser do it "should return <site> for manifests not under module path" do File.stubs(:expand_path).returns("/path/to/manifests/init.pp") File.stubs(:identical?).returns(false) - @parser.split_module("/path/to/manifests/init.pp").should == "<site>" + @parser.split_module("/path/to/manifests/init.pp").should == RDoc::Parser::SITE end end diff --git a/spec/unit/util/rdoc_spec.rb b/spec/unit/util/rdoc_spec.rb index 65df26156..58c2034ee 100755 --- a/spec/unit/util/rdoc_spec.rb +++ b/spec/unit/util/rdoc_spec.rb @@ -75,6 +75,19 @@ describe Puppet::Util::RDoc do Puppet::Util::RDoc.manifestdoc([]) end + it "should use a parser with the correct environment" do + FileTest.stubs(:file?).returns(true) + Puppet::Util::RDoc.stubs(:output) + + parser = stub_everything + Puppet::Parser::Parser.stubs(:new).with{ |env| env.is_a?(Puppet::Node::Environment) }.returns(parser) + + parser.expects(:file=).with("file") + parser.expects(:parse) + + Puppet::Util::RDoc.manifestdoc(["file"]) + end + it "should puppet parse all given files" do FileTest.stubs(:file?).returns(true) Puppet::Util::RDoc.stubs(:output) |
