summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-08-18 11:47:40 -0500
committerLuke Kanies <luke@madstop.com>2008-08-18 11:47:40 -0500
commite3971b9751141cd448a8197da024be43581f6dcd (patch)
tree3ae780db3d9dae0a4df10ec24f928bf3a844e749 /test
parent025edc5c3737f476119df4bab73ebdc68be19430 (diff)
parent2ec4e298c3274abc8eaad4230bca8d39a48d2e35 (diff)
downloadpuppet-e3971b9751141cd448a8197da024be43581f6dcd.tar.gz
puppet-e3971b9751141cd448a8197da024be43581f6dcd.tar.xz
puppet-e3971b9751141cd448a8197da024be43581f6dcd.zip
Merge branch '0.24.x'
Conflicts: CHANGELOG test/util/posixtest.rb
Diffstat (limited to 'test')
-rwxr-xr-xtest/language/functions.rb91
-rwxr-xr-xtest/language/scope.rb28
-rwxr-xr-xtest/ral/type/yumrepo.rb8
-rwxr-xr-xtest/util/posixtest.rb27
4 files changed, 140 insertions, 14 deletions
diff --git a/test/language/functions.rb b/test/language/functions.rb
index a5d52d7ac..97429802b 100755
--- a/test/language/functions.rb
+++ b/test/language/functions.rb
@@ -96,11 +96,12 @@ class TestLangFunctions < Test::Unit::TestCase
twop = File.join(Puppet[:templatedir], "two")
File.open(onep, "w") do |f|
- f.puts "template <%= one %>"
+ f.puts "<%- if @one.nil? then raise '@one undefined' end -%>" +
+ "template <%= @one %>"
end
File.open(twop, "w") do |f|
- f.puts "template <%= two %>"
+ f.puts "template <%= @two %>"
end
func = nil
assert_nothing_raised do
@@ -116,15 +117,27 @@ class TestLangFunctions < Test::Unit::TestCase
ast = varobj("output", func)
scope = mkscope
+
+ # Test that our manual exception throw fails the parse
assert_raise(Puppet::ParseError) do
ast.evaluate(scope)
end
+ # Test that our use of an undefined instance variable does not throw
+ # an exception, but only safely continues.
scope.setvar("one", "One")
- assert_raise(Puppet::ParseError) do
+ assert_nothing_raised do
ast.evaluate(scope)
end
+
+ # Ensure that we got the output we expected from that evaluation.
+ assert_equal("template One\ntemplate \n", scope.lookupvar("output"),
+ "Undefined template variables do not raise exceptions")
+
+ # Now, fill in the last variable and make sure the whole thing
+ # evaluates correctly.
scope.setvar("two", "Two")
+ scope.unsetvar("output")
assert_nothing_raised do
ast.evaluate(scope)
end
@@ -138,7 +151,7 @@ class TestLangFunctions < Test::Unit::TestCase
template = tempfile()
File.open(template, "w") do |f|
- f.puts "template <%= yayness %>"
+ f.puts "template <%= @yay.nil?() ? raise('yay undefined') : @yay %>"
end
func = nil
@@ -158,17 +171,77 @@ class TestLangFunctions < Test::Unit::TestCase
ast.evaluate(scope)
end
- scope.setvar("yayness", "this is yayness")
+ scope.setvar("yay", "this is yay")
assert_nothing_raised do
ast.evaluate(scope)
end
- assert_equal("template this is yayness\n", scope.lookupvar("output"),
+ assert_equal("template this is yay\n", scope.lookupvar("output"),
"Templates were not handled correctly")
end
+ # Make sure that legacy template variable access works as expected.
+ def test_legacyvariables
+ template = tempfile()
+
+ File.open(template, "w") do |f|
+ f.puts "template <%= deprecated %>"
+ end
+
+ func = nil
+ assert_nothing_raised do
+ func = Puppet::Parser::AST::Function.new(
+ :name => "template",
+ :ftype => :rvalue,
+ :arguments => AST::ASTArray.new(
+ :children => [stringobj(template)]
+ )
+ )
+ end
+ ast = varobj("output", func)
+
+ # Verify that we get an exception using old-style accessors.
+ scope = mkscope
+ assert_raise(Puppet::ParseError) do
+ ast.evaluate(scope)
+ end
+
+ # Verify that we evaluate and return their value correctly.
+ scope.setvar("deprecated", "deprecated value")
+ assert_nothing_raised do
+ ast.evaluate(scope)
+ end
+
+ assert_equal("template deprecated value\n", scope.lookupvar("output"),
+ "Deprecated template variables were not handled correctly")
+ end
+
+ # Make sure that problems with kernel method visibility still exist.
+ def test_kernel_module_shadows_deprecated_var_lookup
+ template = tempfile()
+ File.open(template, "w").puts("<%= binding %>")
+
+ func = nil
+ assert_nothing_raised do
+ func = Puppet::Parser::AST::Function.new(
+ :name => "template",
+ :ftype => :rvalue,
+ :arguments => AST::ASTArray.new(
+ :children => [stringobj(template)]
+ )
+ )
+ end
+ ast = varobj("output", func)
+
+ # Verify that Kernel methods still shadow deprecated variable lookups.
+ scope = mkscope
+ assert_nothing_raised("No exception for Kernel shadowed variable names") do
+ ast.evaluate(scope)
+ end
+ end
+
def test_tempatefunction_cannot_see_scopes
template = tempfile()
@@ -243,7 +316,7 @@ class TestLangFunctions < Test::Unit::TestCase
template = tempfile()
File.open(template, "w") do |f|
- f.puts "template <%= yayness %>"
+ f.puts "template <%= @yayness %>"
end
func = nil
@@ -263,10 +336,6 @@ class TestLangFunctions < Test::Unit::TestCase
false => "false",
}.each do |string, value|
scope = mkscope
- assert_raise(Puppet::ParseError) do
- ast.evaluate(scope)
- end
-
scope.setvar("yayness", string)
assert_equal(string, scope.lookupvar("yayness", false))
diff --git a/test/language/scope.rb b/test/language/scope.rb
index c96581a23..0fa211fc3 100755
--- a/test/language/scope.rb
+++ b/test/language/scope.rb
@@ -53,6 +53,34 @@ class TestScope < Test::Unit::TestCase
assert_equal(:undefined, scopes[name].lookupvar("third", false), "Found child var in top scope")
end
assert_equal("botval", scopes[:bot].lookupvar("third", false), "Could not find var in bottom scope")
+
+
+ # Test that the scopes convert to hash structures correctly.
+ # For topscope recursive vs non-recursive should be identical
+ assert_equal(topscope.to_hash(false), topscope.to_hash(true),
+ "Recursive and non-recursive hash is identical for topscope")
+
+ # Check the variable we expect is present.
+ assert_equal({"first" => "topval"}, topscope.to_hash(),
+ "topscope returns the expected hash of variables")
+
+ # Now, check that midscope does the right thing in all cases.
+ assert_equal({"second" => "midval"},
+ midscope.to_hash(false),
+ "midscope non-recursive hash contains only midscope variable")
+ assert_equal({"first" => "topval", "second" => "midval"},
+ midscope.to_hash(true),
+ "midscope recursive hash contains topscope variable also")
+
+ # Finally, check the ability to shadow symbols by adding a shadow to
+ # bottomscope, then checking that we see the right stuff.
+ botscope.setvar("first", "shadowval")
+ assert_equal({"third" => "botval", "first" => "shadowval"},
+ botscope.to_hash(false),
+ "botscope has the right non-recursive hash")
+ assert_equal({"third" => "botval", "first" => "shadowval", "second" => "midval"},
+ botscope.to_hash(true),
+ "botscope values shadow parent scope values")
end
def test_lookupvar
diff --git a/test/ral/type/yumrepo.rb b/test/ral/type/yumrepo.rb
index 273179bc4..a42fa9058 100755
--- a/test/ral/type/yumrepo.rb
+++ b/test/ral/type/yumrepo.rb
@@ -48,7 +48,10 @@ class TestYumRepo < Test::Unit::TestCase
:enabled => "1",
:gpgcheck => "1",
:includepkgs => "absent",
- :gpgkey => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora"
+ :gpgkey => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora",
+ :proxy => "http://proxy.example.com:80/",
+ :proxy_username => "username",
+ :proxy_password => "password"
}
repo = make_repo("base", values)
@@ -102,6 +105,9 @@ baseurl=http://example.com/yum/$releasever/$basearch/os/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora
+proxy=http://proxy.example.com:80/
+proxy_username=username
+proxy_password=password
EOF
end
diff --git a/test/util/posixtest.rb b/test/util/posixtest.rb
index 8fd11b086..f64a95d18 100755
--- a/test/util/posixtest.rb
+++ b/test/util/posixtest.rb
@@ -25,16 +25,39 @@ class TestPosixUtil < Test::Unit::TestCase
def test_get_posix_field
{:group => nonrootgroup, :passwd => nonrootuser}.each do |space, obj|
id = Puppet::Util.idfield(space)
- [obj.name, obj.send(id), obj.send(id).to_s].each do |test|
+ [obj.name, obj.send(id)].each do |test|
value = nil
assert_nothing_raised do
value = get_posix_field(space, :name, test)
end
- assert_equal(obj.name, value, "did not get correct value from get_posix_field")
+ assert_equal(obj.name, value, "did not get correct value from get_posix_field (known to be broken on some platforms)")
end
end
end
+ def test_search_posix_field
+ {:group => nonrootgroup, :passwd => nonrootuser}.each do |space, obj|
+ id = Puppet::Util.idfield(space)
+ [obj.name, obj.send(id)].each do |test|
+ value = nil
+ assert_nothing_raised do
+ value = search_posix_field(space, :name, test)
+ end
+ assert_equal(obj.name, value, "did not get correct value from search_posix_field")
+ end
+ end
+ end
+
+ def test_get_provider_value
+ user = nonrootuser
+ obj = mk_posix_resource(:user, user)
+
+ assert_nothing_raised do
+ assert_equal(user.uid, get_provider_value(:user, :uid, user.uid))
+ assert_equal(user.name, get_provider_value(:user, :name, user.name))
+ end
+ end
+
def test_gid_and_uid
{:user => nonrootuser, :group => nonrootgroup}.each do |type, obj|
method = idfield(type)