summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-03-09 23:17:34 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-03-09 23:17:34 +0000
commitb336e7e59d3497b96dd42b6dbc1855176e6e830d (patch)
tree0442207e70709db2237a5131bbe6922e998bba45 /test
parentb6d829b66bc83f943e929b3f6b036b3aff11187f (diff)
Parameters and states can now register regexes as allowed values. Also, there are (finally) tests associated with params and states, although they should be much more comprehensive.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@999 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
-rw-r--r--test/types/parameter.rb107
-rw-r--r--test/types/state.rb92
-rwxr-xr-xtest/types/symlink.rb26
3 files changed, 225 insertions, 0 deletions
diff --git a/test/types/parameter.rb b/test/types/parameter.rb
new file mode 100644
index 000000000..d95ef461d
--- /dev/null
+++ b/test/types/parameter.rb
@@ -0,0 +1,107 @@
+if __FILE__ == $0
+ $:.unshift '..'
+ $:.unshift '../../lib'
+ $puppetbase = "../.."
+end
+
+require 'puppet/type'
+require 'puppettest'
+require 'test/unit'
+
+class TestState < Test::Unit::TestCase
+ include TestPuppet
+
+ def newparam(name = :fakeparam)
+ assert_nothing_raised {
+ param = Class.new(Puppet::Parameter) do
+ @name = :fakeparam
+ end
+ param.initvars
+
+ return param
+ }
+ end
+
+ def newinst(param)
+ assert_nothing_raised {
+ return param.new
+ }
+ end
+
+ # Test the basic newvalue stuff.
+ def test_newvalue
+ param = newparam()
+
+ # Try it with both symbols and strings.
+ assert_nothing_raised {
+ param.newvalues(:one, "two")
+ }
+
+ inst = newinst(param)
+
+ assert_nothing_raised {
+ inst.value = "one"
+ }
+
+ assert_equal(:one, inst.value)
+
+ assert_nothing_raised {
+ inst.value = :two
+ }
+ assert_equal(:two, inst.value)
+
+ assert_raise(ArgumentError) {
+ inst.value = :three
+ }
+ assert_equal(:two, inst.value)
+ end
+
+ # Test using regexes.
+ def test_regexvalues
+ param = newparam
+
+ assert_nothing_raised {
+ param.newvalues(/^\d+$/)
+ }
+ assert(param.match?("14"))
+ assert(param.match?(14))
+
+ inst = newinst(param)
+
+ assert_nothing_raised {
+ inst.value = 14
+ }
+
+ assert_nothing_raised {
+ inst.value = "14"
+ }
+
+ assert_raise(ArgumentError) {
+ inst.value = "a14"
+ }
+ end
+
+ # Test using both. Equality should beat matching.
+ def test_regexesandnormals
+ param = newparam
+
+ assert_nothing_raised {
+ param.newvalues(:one, /^\w+$/)
+ }
+
+ inst = newinst(param)
+
+ assert_nothing_raised {
+ inst.value = "one"
+ }
+
+ assert_equal(:one, inst.value, "Value used regex instead of equality")
+
+ assert_nothing_raised {
+ inst.value = "two"
+ }
+ assert_equal("two", inst.value, "Matched value didn't take")
+ end
+end
+
+# $Id$
diff --git a/test/types/state.rb b/test/types/state.rb
new file mode 100644
index 000000000..88df6575d
--- /dev/null
+++ b/test/types/state.rb
@@ -0,0 +1,92 @@
+if __FILE__ == $0
+ $:.unshift '..'
+ $:.unshift '../../lib'
+ $puppetbase = "../.."
+end
+
+require 'puppet/type'
+require 'puppettest'
+require 'test/unit'
+
+class TestState < Test::Unit::TestCase
+ include TestPuppet
+
+ def newinst(state)
+ inst = nil
+ assert_nothing_raised {
+ return state.new(:parent => nil)
+ }
+ end
+
+ def newstate(name = :fakestate)
+ assert_nothing_raised {
+ state = Class.new(Puppet::State) do
+ @name = :fakeparam
+ end
+ state.initvars
+
+ return state
+ }
+ end
+
+ def test_newvalue
+ state = newstate()
+
+ assert_nothing_raised {
+ state.newvalue(:one) do
+ @is = 1
+ end
+ }
+
+ assert_nothing_raised {
+ state.newvalue("two") do
+ @is = 2
+ end
+ }
+
+ inst = newinst(state)
+
+ assert_nothing_raised {
+ inst.should = "one"
+ }
+
+ assert_equal(:one, inst.should)
+ assert_nothing_raised { inst.set_one }
+ assert_equal(1, inst.is)
+
+ assert_nothing_raised {
+ inst.should = :two
+ }
+
+ assert_equal(:two, inst.should)
+ assert_nothing_raised { inst.set_two }
+ assert_equal(2, inst.is)
+ end
+
+ def test_newvaluewithregexes
+ state = newstate()
+
+ assert_nothing_raised {
+ state.newvalue(/^\w+$/) do |value|
+ @is = value.upcase
+ return :regex_matched
+ end
+ }
+
+ inst = newinst(state)
+
+ assert_nothing_raised {
+ inst.should = "yayness"
+ }
+
+ assert_equal("yayness", inst.should)
+
+ assert_nothing_raised {
+ inst.sync
+ }
+
+ assert_equal("yayness".upcase, inst.is)
+ end
+end
+
+# $Id$
diff --git a/test/types/symlink.rb b/test/types/symlink.rb
index a07a2fbb6..21b1e865b 100755
--- a/test/types/symlink.rb
+++ b/test/types/symlink.rb
@@ -88,4 +88,30 @@ class TestSymlink < Test::Unit::TestCase
}
}
end
+
+ def test_createdrecursion
+ source = tempfile()
+ file = File.join(source, "file")
+ dest = tempfile()
+ link = File.join(dest, "file")
+
+ objects = []
+ objects << Puppet.type(:file).create(
+ :path => source,
+ :ensure => "directory"
+ )
+ objects << Puppet.type(:file).create(
+ :path => file,
+ :ensure => "file"
+ )
+ objects << Puppet.type(:symlink).create(
+ :path => dest,
+ :ensure => source,
+ :recurse => true
+ )
+
+ assert_apply(*objects)
+
+ assert(FileTest.symlink?(link), "Link was not created")
+ end
end