summaryrefslogtreecommitdiff
path: root/spec/unit/parser
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/parser')
-rwxr-xr-xspec/unit/parser/ast/asthash_spec.rb3
-rwxr-xr-xspec/unit/parser/ast/leaf_spec.rb16
-rwxr-xr-xspec/unit/parser/functions/create_resources_spec.rb25
3 files changed, 38 insertions, 6 deletions
diff --git a/spec/unit/parser/ast/asthash_spec.rb b/spec/unit/parser/ast/asthash_spec.rb
index d7fbbfae9..ab1281f91 100755
--- a/spec/unit/parser/ast/asthash_spec.rb
+++ b/spec/unit/parser/ast/asthash_spec.rb
@@ -91,7 +91,6 @@ describe Puppet::Parser::AST::ASTHash do
it "should return a valid string with to_s" do
hash = Puppet::Parser::AST::ASTHash.new(:value => { "a" => "b", "c" => "d" })
-
- hash.to_s.should == '{a => b, c => d}'
+ ["{a => b, c => d}", "{c => d, a => b}"].should be_include hash.to_s
end
end
diff --git a/spec/unit/parser/ast/leaf_spec.rb b/spec/unit/parser/ast/leaf_spec.rb
index ff3fed5e9..881506ea4 100755
--- a/spec/unit/parser/ast/leaf_spec.rb
+++ b/spec/unit/parser/ast/leaf_spec.rb
@@ -151,6 +151,14 @@ describe Puppet::Parser::AST::HashOrArrayAccess do
lambda { access.evaluate(@scope) }.should raise_error
end
+ it "should be able to return :undef for an unknown array index" do
+ @scope.stubs(:lookupvar).with { |name,options| name == 'a'}.returns(["val1", "val2", "val3"])
+
+ access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => 6 )
+
+ access.evaluate(@scope).should == :undef
+ end
+
it "should be able to return an hash value" do
@scope.stubs(:lookupvar).with { |name,options| name == 'a'}.returns({ "key1" => "val1", "key2" => "val2", "key3" => "val3" })
@@ -159,6 +167,14 @@ describe Puppet::Parser::AST::HashOrArrayAccess do
access.evaluate(@scope).should == "val2"
end
+ it "should be able to return :undef for unknown hash keys" do
+ @scope.stubs(:lookupvar).with { |name,options| name == 'a'}.returns({ "key1" => "val1", "key2" => "val2", "key3" => "val3" })
+
+ access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "key12" )
+
+ access.evaluate(@scope).should == :undef
+ end
+
it "should be able to return an hash value with a numerical key" do
@scope.stubs(:lookupvar).with { |name,options| name == "a"}.returns({ "key1" => "val1", "key2" => "val2", "45" => "45", "key3" => "val3" })
diff --git a/spec/unit/parser/functions/create_resources_spec.rb b/spec/unit/parser/functions/create_resources_spec.rb
index da76e75d0..64314f777 100755
--- a/spec/unit/parser/functions/create_resources_spec.rb
+++ b/spec/unit/parser/functions/create_resources_spec.rb
@@ -20,8 +20,9 @@ describe 'function for dynamically creating resources' do
it "should exist" do
Puppet::Parser::Functions.function(:create_resources).should == "function_create_resources"
end
- it 'should require two arguments' do
- lambda { @scope.function_create_resources(['foo']) }.should raise_error(ArgumentError, 'create_resources(): wrong number of arguments (1; must be 2)')
+ it 'should require two or three arguments' do
+ lambda { @scope.function_create_resources(['foo']) }.should raise_error(ArgumentError, 'create_resources(): wrong number of arguments (1; must be 2 or 3)')
+ lambda { @scope.function_create_resources(['foo', 'bar', 'blah', 'baz']) }.should raise_error(ArgumentError, 'create_resources(): wrong number of arguments (4; must be 2 or 3)')
end
describe 'when creating native types' do
before :each do
@@ -58,6 +59,11 @@ describe 'function for dynamically creating resources' do
foo.should be
rg.path_between(test,foo).should be
end
+ it 'should account for default values' do
+ @scope.function_create_resources(['file', {'/etc/foo'=>{'ensure'=>'present'}, '/etc/baz'=>{'group'=>'food'}}, {'group' => 'bar'}])
+ @compiler.catalog.resource(:file, "/etc/foo")['group'].should == 'bar'
+ @compiler.catalog.resource(:file, "/etc/baz")['group'].should == 'food'
+ end
end
describe 'when dynamically creating resource types' do
before :each do
@@ -103,6 +109,11 @@ notify{test:}
rg.path_between(test,blah).should be
@compiler.catalog.resource(:notify, "blah")['message'].should == 'two'
end
+ it 'should account for default values' do
+ @scope.function_create_resources(['foo', {'blah'=>{}}, {'one' => 'two'}])
+ @scope.compiler.compile
+ @compiler.catalog.resource(:notify, "blah")['message'].should == 'two'
+ end
end
describe 'when creating classes' do
before :each do
@@ -114,7 +125,7 @@ notify{tester:}
@scope.resource=Puppet::Parser::Resource.new('class', 't', :scope => @scope)
Puppet::Parser::Functions.function(:create_resources)
end
- it 'should be able to create classes', :'fails_on_ruby_1.9.2' => true do
+ it 'should be able to create classes' do
@scope.function_create_resources(['class', {'bar'=>{'one'=>'two'}}])
@scope.compiler.compile
@compiler.catalog.resource(:notify, "test")['message'].should == 'two'
@@ -123,7 +134,7 @@ notify{tester:}
it 'should fail to create non-existing classes' do
lambda { @scope.function_create_resources(['class', {'blah'=>{'one'=>'two'}}]) }.should raise_error(ArgumentError ,'could not find hostclass blah')
end
- it 'should be able to add edges', :'fails_on_ruby_1.9.2' => true do
+ it 'should be able to add edges' do
@scope.function_create_resources(['class', {'bar'=>{'one'=>'two', 'require' => 'Notify[tester]'}}])
@scope.compiler.compile
rg = @scope.compiler.catalog.to_ral.relationship_graph
@@ -133,5 +144,11 @@ notify{tester:}
tester.should be
rg.path_between(tester,test).should be
end
+ it 'should account for default values' do
+ @scope.function_create_resources(['class', {'bar'=>{}}, {'one' => 'two'}])
+ @scope.compiler.compile
+ @compiler.catalog.resource(:notify, "test")['message'].should == 'two'
+ @compiler.catalog.resource(:class, "bar").should_not be_nil#['message'].should == 'two'
+ end
end
end