summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-09-23 20:42:08 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-09-23 20:42:08 +0000
commit8211df036e1d2d24e1084616fc3fc4891b06cfdd (patch)
tree597f8b999cf5210a7ceff5ef1e1977f1de08c241 /test
parentd20ac8e0b564e5413d571f2059de559e0783b72d (diff)
downloadpuppet-8211df036e1d2d24e1084616fc3fc4891b06cfdd.tar.gz
puppet-8211df036e1d2d24e1084616fc3fc4891b06cfdd.tar.xz
puppet-8211df036e1d2d24e1084616fc3fc4891b06cfdd.zip
Many, many changes toward a completely functional system. The only current problems with my home config are that apache's stupid init script does not do status and that packages are not working as non-root users (which makes sense).
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@703 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
-rwxr-xr-xtest/language/tc_snippets.rb3
-rw-r--r--test/parser/tc_parser.rb116
-rwxr-xr-xtest/server/tc_fileserver.rb98
-rw-r--r--test/types/tc_fileignoresource.rb4
-rwxr-xr-xtest/types/tc_filesources.rb106
-rw-r--r--test/types/tc_type.rb4
6 files changed, 321 insertions, 10 deletions
diff --git a/test/language/tc_snippets.rb b/test/language/tc_snippets.rb
index bb736b37e..c04b3ae5d 100755
--- a/test/language/tc_snippets.rb
+++ b/test/language/tc_snippets.rb
@@ -244,7 +244,8 @@ class TestSnippets < TestPuppet
def snippet_argumentdefaults(trans)
file1 = "/tmp/argumenttest1"
file2 = "/tmp/argumenttest2"
- #@@tmpfiles << file
+ @@tmpfiles << file1
+ @@tmpfiles << file2
assert(FileTest.exists?(file1))
assert(File.stat(file1).mode & 007777 == 0755)
diff --git a/test/parser/tc_parser.rb b/test/parser/tc_parser.rb
index de2d75ddc..4e3d83a63 100644
--- a/test/parser/tc_parser.rb
+++ b/test/parser/tc_parser.rb
@@ -58,6 +58,122 @@ class TestParser < TestPuppet
ret = parser.parse
}
end
+
+ def mkmanifest(file)
+ name = File.join(tmpdir, "file%s" % rand(100))
+ @@tmpfiles << name
+
+ File.open(file, "w") { |f|
+ f.puts "file { \"%s\": create => true, mode => 755 }\n" %
+ name
+ }
+ end
+
+ def test_importglobbing
+ basedir = File.join(tmpdir(), "importesting")
+ @@tmpfiles << basedir
+ Dir.mkdir(basedir)
+
+ subdir = "subdir"
+ Dir.mkdir(File.join(basedir, subdir))
+ manifest = File.join(basedir, "manifest")
+ File.open(manifest, "w") { |f|
+ f.puts "import \"%s/*\"" % subdir
+ }
+
+ 4.times { |i|
+ path = File.join(basedir, subdir, "subfile%s" % i)
+ mkmanifest(path)
+ }
+
+ assert_nothing_raised("Could not parse multiple files") {
+ parser = Puppet::Parser::Parser.new()
+ parser.file = manifest
+ parser.parse
+ }
+ end
+
+ def test_zdefaults
+ basedir = File.join(tmpdir(), "defaulttesting")
+ @@tmpfiles << basedir
+ Dir.mkdir(basedir)
+
+ defs1 = {
+ "testing" => "value"
+ }
+
+ defs2 = {
+ "one" => "two",
+ "three" => "four",
+ "five" => false,
+ "seven" => "eight",
+ "nine" => true,
+ "eleven" => "twelve"
+ }
+
+ mkdef = proc { |hash|
+ hash.collect { |arg, value|
+ "%s = %s" % [arg, value]
+ }.join(", ")
+ }
+ manifest = File.join(basedir, "manifest")
+ File.open(manifest, "w") { |f|
+ f.puts "
+ define method(#{mkdef.call(defs1)}, other) {
+ $variable = $testing
+ }
+
+ define othermethod(#{mkdef.call(defs2)}, goodness) {
+ $more = less
+ }
+
+ method {
+ other => yayness
+ }
+
+ othermethod {
+ goodness => rahness
+ }
+"
+ }
+
+ ast = nil
+ assert_nothing_raised("Could not parse multiple files") {
+ parser = Puppet::Parser::Parser.new()
+ parser.file = manifest
+ ast = parser.parse
+ }
+
+ assert(ast, "Did not receive AST while parsing defaults")
+
+ scope = nil
+ assert_nothing_raised("Could not evaluate defaults parse tree") {
+ scope = Puppet::Parser::Scope.new()
+ objects = scope.evaluate(ast)
+ }
+
+ method = nil
+ othermethod = nil
+ assert_nothing_raised {
+ method = scope.find { |child|
+ child.is_a?(Puppet::Parser::Scope) and child.type == "method"
+ }
+ defs1.each { |var, value|
+ curval = method.lookupvar(var)
+ assert_equal(value, curval, "Did not get default")
+ }
+ }
+
+ assert_nothing_raised {
+ method = scope.find { |child|
+ child.is_a?(Puppet::Parser::Scope) and child.type == "othermethod"
+ }
+ defs2.each { |var, value|
+ curval = method.lookupvar(var)
+ assert_equal(value, curval, "Did not get default")
+ }
+ }
+ end
end
# $Id$
diff --git a/test/server/tc_fileserver.rb b/test/server/tc_fileserver.rb
index 4235a725c..17003a6fe 100755
--- a/test/server/tc_fileserver.rb
+++ b/test/server/tc_fileserver.rb
@@ -416,6 +416,23 @@ class TestFileServer < TestPuppet
files.each { |file|
assert_describe(sfile, file, server)
}
+
+ # And then describe some files that we know aren't there
+ retval = nil
+ assert_nothing_raised("Describing non-existent files raised an error") {
+ retval = server.describe(sfile + "noexisties")
+ }
+
+ assert_equal("", retval, "Description of non-existent files returned a value")
+
+ # Now try to describe some sources that don't even exist
+ retval = nil
+ assert_raise(Puppet::Server::FileServerError,
+ "Describing non-existent mount did not raise an error") {
+ retval = server.describe("/notmounted/" + "noexisties")
+ }
+
+ assert_nil(retval, "Description of non-existent mounts returned a value")
end
# test that our config file is parsing and working as planned
@@ -424,9 +441,6 @@ class TestFileServer < TestPuppet
basedir = File.join(tmpdir, "fileserverconfigfiletesting")
@@tmpfiles << basedir
- conftext = "# a test config file\n \n"
-
-
# make some dirs for mounting
Dir.mkdir(basedir)
mounts = {}
@@ -541,6 +555,72 @@ class TestFileServer < TestPuppet
end
+ # Test that we smoothly handle invalid config files
+ def test_configfailures
+ # create an example file with each of them
+ conffile = tempfile()
+
+ invalidmounts = {
+ "noexist" => "[noexist]
+ path /this/path/does/not/exist
+ allow 192.168.0.*
+"
+}
+
+ invalidconfigs = [
+"[not valid]
+ path /this/path/does/not/exist
+ allow 192.168.0.*
+",
+"[valid]
+ invalidstatement
+ path /etc
+ allow 192.168.0.*
+",
+"[valid]
+ allow 192.168.0.*
+"
+]
+
+ invalidmounts.each { |mount, text|
+ File.open(conffile, "w") { |f|
+ f.print text
+ }
+
+
+ # create a server with the file
+ server = nil
+ assert_nothing_raised {
+ server = Puppet::Server::FileServer.new(
+ :Local => true,
+ :Config => conffile
+ )
+ }
+
+ assert_raise(Puppet::Server::FileServerError,
+ "Invalid mount was mounted") {
+ server.list(mount)
+ }
+ }
+
+ invalidconfigs.each_with_index { |text, i|
+ File.open(conffile, "w") { |f|
+ f.print text
+ }
+
+
+ # create a server with the file
+ server = nil
+ assert_raise(Puppet::Server::FileServerError,
+ "Invalid config %s did not raise error" % i) {
+ server = Puppet::Server::FileServer.new(
+ :Local => true,
+ :Config => conffile
+ )
+ }
+ }
+ end
+
# verify we reread the config file when it changes
def test_filereread
server = nil
@@ -572,12 +652,14 @@ class TestFileServer < TestPuppet
list = nil
assert_nothing_raised {
- list = server.list("/thing/", false, false, "test1.domain.com", "127.0.0.1")
+ list = server.list("/thing/", false, false,
+ "test1.domain.com", "127.0.0.1")
}
assert(list != "", "List returned nothing in rereard test")
assert_raise(Puppet::Server::AuthorizationError, "List allowed invalid host") {
- list = server.list("/thing/", false, false, "test2.domain.com", "127.0.0.1")
+ list = server.list("/thing/", false, false,
+ "test2.domain.com", "127.0.0.1")
}
sleep 1
@@ -591,11 +673,13 @@ class TestFileServer < TestPuppet
}
assert_raise(Puppet::Server::AuthorizationError, "List allowed invalid host") {
- list = server.list("/thing/", false, false, "test1.domain.com", "127.0.0.1")
+ list = server.list("/thing/", false, false,
+ "test1.domain.com", "127.0.0.1")
}
assert_nothing_raised {
- list = server.list("/thing/", false, false, "test2.domain.com", "127.0.0.1")
+ list = server.list("/thing/", false, false,
+ "test2.domain.com", "127.0.0.1")
}
assert(list != "", "List returned nothing in rereard test")
diff --git a/test/types/tc_fileignoresource.rb b/test/types/tc_fileignoresource.rb
index c67a48618..40013e6de 100644
--- a/test/types/tc_fileignoresource.rb
+++ b/test/types/tc_fileignoresource.rb
@@ -237,7 +237,7 @@ class TestFileIgnoreSources < FileTesting
#makes Puppet file Object
assert_nothing_raised {
- tofile = Puppet::Type::PFile.new(
+ tofile = Puppet::Type::PFile.create(
:name => topath,
:source => frompath,
:recurse => true,
@@ -247,7 +247,7 @@ class TestFileIgnoreSources < FileTesting
}
#make a component and adds the file
- comp = Puppet::Type::Component.new(
+ comp = Puppet::Type::Component.create(
:name => "component"
)
comp.push tofile
diff --git a/test/types/tc_filesources.rb b/test/types/tc_filesources.rb
index c4a35682c..0de4157bc 100755
--- a/test/types/tc_filesources.rb
+++ b/test/types/tc_filesources.rb
@@ -39,6 +39,11 @@ class TestFileSources < FileTesting
rescue
system("rm -rf %s" % Puppet[:checksumfile])
end
+ if defined? @port
+ @port += 1
+ else
+ @port = 8800
+ end
super
end
@@ -440,4 +445,105 @@ class TestFileSources < FileTesting
system("kill -INT %s" % serverpid)
}
end
+
+ def test_networkSourcesWithoutService
+ server = nil
+
+ Puppet[:autosign] = true
+ Puppet[:masterport] = 8765
+
+ serverpid = nil
+ assert_nothing_raised() {
+ server = Puppet::Server.new(
+ :Handlers => {
+ :CA => {}, # so that certs autogenerate
+ }
+ )
+
+ }
+ serverpid = fork {
+ assert_nothing_raised() {
+ #trap(:INT) { server.shutdown; Kernel.exit! }
+ trap(:INT) { server.shutdown }
+ server.start
+ }
+ }
+ @@tmppids << serverpid
+
+ sleep(1)
+
+ name = File.join(tmpdir(), "nosourcefile")
+ file = Puppet::Type::PFile.create(
+ :source => "puppet://localhost/dist/file",
+ :name => name
+ )
+
+ assert_nothing_raised {
+ file.retrieve
+ }
+
+ comp = newcomp("nosource", file)
+
+ assert_nothing_raised {
+ comp.evaluate
+ }
+
+ assert(!FileTest.exists?(name), "File with no source exists anyway")
+ end
+
+ def test_unmountedNetworkSources
+ server = nil
+ mounts = {
+ "/" => "root",
+ "/noexistokay" => "noexist"
+ }
+
+ fileserverconf = mkfileserverconf(mounts)
+
+ Puppet[:autosign] = true
+ Puppet[:masterport] = @port
+
+ serverpid = nil
+ assert_nothing_raised() {
+ server = Puppet::Server.new(
+ :Port => @port,
+ :Handlers => {
+ :CA => {}, # so that certs autogenerate
+ :FileServer => {
+ :Config => fileserverconf
+ }
+ }
+ )
+
+ }
+
+ serverpid = fork {
+ assert_nothing_raised() {
+ #trap(:INT) { server.shutdown; Kernel.exit! }
+ trap(:INT) { server.shutdown }
+ server.start
+ }
+ }
+ @@tmppids << serverpid
+
+ sleep(1)
+
+ name = File.join(tmpdir(), "nosourcefile")
+ file = Puppet::Type::PFile.create(
+ :source => "puppet://localhost/noexist/file",
+ :name => name
+ )
+
+ assert_nothing_raised {
+ file.retrieve
+ }
+
+ comp = newcomp("nosource", file)
+
+ assert_nothing_raised {
+ comp.evaluate
+ }
+
+ assert(!FileTest.exists?(name), "File with no source exists anyway")
+ end
end
diff --git a/test/types/tc_type.rb b/test/types/tc_type.rb
index f746f287b..16c0644b1 100644
--- a/test/types/tc_type.rb
+++ b/test/types/tc_type.rb
@@ -110,4 +110,8 @@ class TestType < TestPuppet
assert_equal("testing", group.name, "Could not retrieve name")
end
+
+ # Test that global noop works
+ def test_zglobalnoop
+ end
end