summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/indirector/ldap.rb16
-rwxr-xr-xspec/unit/indirector/yaml.rb29
-rwxr-xr-xspec/unit/parser/lexer.rb9
-rwxr-xr-xspec/unit/parser/templatewrapper.rb13
4 files changed, 63 insertions, 4 deletions
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
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
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 = ""'
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