From 2a3d195402900aa31843f7a7ff78026409cf43f5 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Fri, 1 Aug 2008 07:11:21 +1000 Subject: Specs for yaml indirector .search - I'm still learning! Updated, I was calling .base myself instead of the actual string --- spec/unit/indirector/yaml.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'spec/unit') diff --git a/spec/unit/indirector/yaml.rb b/spec/unit/indirector/yaml.rb index 3875d70aa..081ae9666 100755 --- a/spec/unit/indirector/yaml.rb +++ b/spec/unit/indirector/yaml.rb @@ -106,4 +106,33 @@ describe Puppet::Indirector::Yaml, " when choosing file location" do proc { @store.find(@request) }.should raise_error(Puppet::Error) end end + + describe Puppet::Indirector::Yaml, " when searching" do + it "should return an array of fact instances with one instance for each file when globbing *" 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}) + YAML.expects(:load_file).with("one.yaml").returns @one; + YAML.expects(:load_file).with("two.yaml").returns @two; + @store.search(@request).should == [@one, @two] + end + + 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}) + 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.search(@request).should == [] + end + end end -- cgit From 3ae7eca3928d5dd9d0c93e61ceedc38f60573eb5 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 7 Aug 2008 17:52:26 -0700 Subject: Fixing an ldap connectivity test Signed-off-by: Luke Kanies --- spec/unit/indirector/ldap.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'spec/unit') diff --git a/spec/unit/indirector/ldap.rb b/spec/unit/indirector/ldap.rb index 52abd413a..2c4060c4d 100755 --- a/spec/unit/indirector/ldap.rb +++ b/spec/unit/indirector/ldap.rb @@ -113,15 +113,25 @@ describe Puppet::Indirector::Ldap do describe "when connecting to ldap" do confine "LDAP is not available" => Puppet.features.ldap? + it "should create and start a Util::Ldap::Connection instance" do + conn = mock 'connection', :connection => "myconn", :start => nil + Puppet::Util::Ldap::Connection.expects(:instance).returns conn + + @searcher.connection.should == "myconn" + end + it "should only create the ldap connection when asked for it the first time" do - @searcher.connection.should equal(@searcher.connection) + conn = mock 'connection', :connection => "myconn", :start => nil + Puppet::Util::Ldap::Connection.expects(:instance).returns conn + + @searcher.connection end - it "should create and start a Util::Ldap::Connection instance" do + it "should cache the connection" do conn = mock 'connection', :connection => "myconn", :start => nil Puppet::Util::Ldap::Connection.expects(:instance).returns conn - @searcher.connection.should == "myconn" + @searcher.connection.should equal(@searcher.connection) end end -- cgit From 8a0cb16abd4c6a9cbf27d88593aa2b42a7375b94 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 7 Aug 2008 18:53:02 -0700 Subject: Added tests for TemplateWrapper's use of Scope#to_hash. We should deprecate the method_missing stuff in 0.25. Signed-off-by: Luke Kanies --- spec/unit/parser/templatewrapper.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'spec/unit') diff --git a/spec/unit/parser/templatewrapper.rb b/spec/unit/parser/templatewrapper.rb index 40465f955..2d4bd141b 100755 --- a/spec/unit/parser/templatewrapper.rb +++ b/spec/unit/parser/templatewrapper.rb @@ -6,7 +6,7 @@ describe Puppet::Parser::TemplateWrapper do before(:each) do compiler = stub('compiler', :environment => "foo") parser = stub('parser', :watch_file => true) - @scope = stub('scope', :compiler => compiler, :parser => parser) + @scope = stub('scope', :compiler => compiler, :parser => parser, :to_hash => {}) @file = "fake_template" Puppet::Module.stubs(:find_template).returns("/tmp/fake_template") FileTest.stubs(:exists?).returns("true") @@ -54,4 +54,15 @@ describe Puppet::Parser::TemplateWrapper do tw = Puppet::Parser::TemplateWrapper.new(@scope, @file) tw.has_variable?("chicken").should eql(false) end + + it "should set all of the scope's variables as instance variables" do + template_mock = mock("template", :result => "woot!") + File.expects(:read).with("/tmp/fake_template").returns("template contents") + ERB.expects(:new).with("template contents", 0, "-").returns(template_mock) + + @scope.expects(:to_hash).returns("one" => "foo") + @tw.result + + @tw.instance_variable_get("@one").should == "foo" + end end -- cgit From 6676b6b104e3f60dd14be18cbfb91b4cd96ec06e Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Thu, 14 Aug 2008 00:32:30 +1000 Subject: Fixes #1274 - allow class names to start with numbers --- spec/unit/parser/lexer.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'spec/unit') diff --git a/spec/unit/parser/lexer.rb b/spec/unit/parser/lexer.rb index 9972f7268..fb666054d 100755 --- a/spec/unit/parser/lexer.rb +++ b/spec/unit/parser/lexer.rb @@ -378,6 +378,15 @@ describe "Puppet::Parser::Lexer in the old tests" do } end + it "should correctly parse names with numerals" do + string = %w{1name name1 11names names11} + + string.each { |t| + @lexer.string = t + @lexer.fullscan.should == [[:NAME,t],[false,false]] + } + end + it "should correctly parse empty strings" do bit = '$var = ""' -- cgit