summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-10-09 10:54:21 -0500
committerLuke Kanies <luke@madstop.com>2007-10-09 10:54:21 -0500
commit32753e11d9cd731760ec8ba3c4f1ad2e3402535e (patch)
tree0b6375bdefa041a7d4fbab9745ed084fb025bc30 /test
parentafa1dee5eb3a8b5249715e61f9894b04ab34a6ae (diff)
parent01f132d8b88467dfd314ad355f1cdf9f546945b3 (diff)
downloadpuppet-32753e11d9cd731760ec8ba3c4f1ad2e3402535e.tar.gz
puppet-32753e11d9cd731760ec8ba3c4f1ad2e3402535e.tar.xz
puppet-32753e11d9cd731760ec8ba3c4f1ad2e3402535e.zip
Merge branch 'master' of git://michaelobrien.info/puppet into michael
Diffstat (limited to 'test')
-rw-r--r--test/data/snippets/classpathtest4
-rwxr-xr-xtest/language/compile.rb14
-rwxr-xr-xtest/language/functions.rb10
-rwxr-xr-xtest/language/parser.rb3
-rwxr-xr-xtest/language/scope.rb11
-rwxr-xr-xtest/language/snippets.rb47
-rwxr-xr-xtest/language/transportable.rb34
-rw-r--r--test/lib/puppettest/parsertesting.rb15
-rwxr-xr-xtest/network/client/client.rb8
-rwxr-xr-xtest/network/client/master.rb14
-rwxr-xr-xtest/network/handler/configuration.rb27
-rwxr-xr-xtest/network/handler/master.rb3
-rwxr-xr-xtest/network/handler/runner.rb11
-rwxr-xr-xtest/rails/configuration.rb15
-rwxr-xr-xtest/ral/providers/service/debian.rb71
15 files changed, 139 insertions, 148 deletions
diff --git a/test/data/snippets/classpathtest b/test/data/snippets/classpathtest
index 68610958b..580333369 100644
--- a/test/data/snippets/classpathtest
+++ b/test/data/snippets/classpathtest
@@ -1,11 +1,11 @@
# $Id$
-define component {
+define mytype {
file { "/tmp/classtest": ensure => file, mode => 755 }
}
class testing {
- component { "componentname": }
+ mytype { "componentname": }
}
include testing
diff --git a/test/language/compile.rb b/test/language/compile.rb
index 5732acba3..7a8a613af 100755
--- a/test/language/compile.rb
+++ b/test/language/compile.rb
@@ -23,7 +23,7 @@ class TestCompile < Test::Unit::TestCase
def mkparser
# This should mock an interpreter
- @parser = stub 'parser', :version => "1.0"
+ @parser = stub 'parser', :version => "1.0", :nodes => {}
end
def mkcompile(options = {})
@@ -38,7 +38,7 @@ class TestCompile < Test::Unit::TestCase
def test_initialize
compile = nil
node = stub 'node', :name => "foo"
- parser = stub 'parser', :version => "1.0"
+ parser = stub 'parser', :version => "1.0", :nodes => {}
assert_nothing_raised("Could not init compile with all required options") do
compile = Compile.new(node, parser)
end
@@ -51,7 +51,7 @@ class TestCompile < Test::Unit::TestCase
# Now try it with some options
assert_nothing_raised("Could not init compile with extra options") do
- compile = Compile.new(node, parser, :ast_nodes => false)
+ compile = Compile.new(node, parser)
end
assert_equal(false, compile.ast_nodes?, "Did not set ast_nodes? correctly")
@@ -188,7 +188,7 @@ class TestCompile < Test::Unit::TestCase
# Make sure we either don't look for nodes, or that we find and evaluate the right object.
def test_evaluate_ast_node
# First try it with ast_nodes disabled
- compile = mkcompile :ast_nodes => false
+ compile = mkcompile
name = compile.node.name
compile.expects(:ast_nodes?).returns(false)
compile.parser.expects(:nodes).never
@@ -201,7 +201,7 @@ class TestCompile < Test::Unit::TestCase
# Now try it with them enabled, but no node found.
nodes = mock 'node_hash'
- compile = mkcompile :ast_nodes => true
+ compile = mkcompile
name = compile.node.name
compile.expects(:ast_nodes?).returns(true)
compile.parser.stubs(:nodes).returns(nodes)
@@ -221,7 +221,7 @@ class TestCompile < Test::Unit::TestCase
end
# Finally, make sure it works dandily when we have a node
- compile = mkcompile :ast_nodes => true
+ compile = mkcompile
compile.expects(:ast_nodes?).returns(true)
node = stub 'node', :classname => "c"
@@ -240,7 +240,7 @@ class TestCompile < Test::Unit::TestCase
"Did not create node resource")
# Lastly, check when we actually find the default.
- compile = mkcompile :ast_nodes => true
+ compile = mkcompile
compile.expects(:ast_nodes?).returns(true)
node = stub 'node', :classname => "default"
diff --git a/test/language/functions.rb b/test/language/functions.rb
index 2a392e01a..db107fd36 100755
--- a/test/language/functions.rb
+++ b/test/language/functions.rb
@@ -202,16 +202,10 @@ class TestLangFunctions < Test::Unit::TestCase
f.puts "original text"
end
- manifest = tempfile()
file = tempfile()
- File.open(manifest, "w") do |f|
- f.puts %{file { "#{file}": content => template("#{template}") }}
- end
- interp = Puppet::Parser::Interpreter.new(
- :Manifest => manifest,
- :UseNodes => false
- )
+ Puppet[:code] = %{file { "#{file}": content => template("#{template}") }}
+ interp = Puppet::Parser::Interpreter.new
node = mknode
node.stubs(:environment).returns("yay")
diff --git a/test/language/parser.rb b/test/language/parser.rb
index 9109686cb..1e7adb45e 100755
--- a/test/language/parser.rb
+++ b/test/language/parser.rb
@@ -618,7 +618,8 @@ file { "/tmp/yayness":
f.puts "file { '#{file}': ensure => present }"
end
- interp = mkinterp :Manifest => top, :UseNodes => false
+ Puppet[:manifest] = top
+ interp = Puppet::Parser::Interpreter.new
code = nil
assert_nothing_raised do
diff --git a/test/language/scope.rb b/test/language/scope.rb
index b4db5ef40..22734a5fb 100755
--- a/test/language/scope.rb
+++ b/test/language/scope.rb
@@ -399,24 +399,17 @@ class TestScope < Test::Unit::TestCase
Puppet::Rails.init
sleep 1
children = []
- file = tempfile()
- File.open(file, "w") { |f|
- f.puts "
+ Puppet[:code] = "
class yay {
@@host { myhost: ip => \"192.168.0.2\" }
}
include yay
@@host { puppet: ip => \"192.168.0.3\" }
Host <<||>>"
- }
interp = nil
assert_nothing_raised {
- interp = Puppet::Parser::Interpreter.new(
- :Manifest => file,
- :UseNodes => false,
- :ForkSave => false
- )
+ interp = Puppet::Parser::Interpreter.new
}
config = nil
diff --git a/test/language/snippets.rb b/test/language/snippets.rb
index 7168a81d8..58a6e7f89 100755
--- a/test/language/snippets.rb
+++ b/test/language/snippets.rb
@@ -202,7 +202,7 @@ class TestSnippets < Test::Unit::TestCase
assert_nothing_raised {
assert_equal(
- "//testing/component[componentname]/File[/tmp/classtest]",
+ "//testing/Mytype[componentname]/File[/tmp/classtest]",
file.path)
}
end
@@ -449,45 +449,24 @@ class TestSnippets < Test::Unit::TestCase
#eval("alias %s %s" % [testname, mname])
testname = ("test_" + mname).intern
self.send(:define_method, testname) {
+ Puppet[:manifest] = snippet(file)
facts = {
"hostname" => "testhost",
"domain" => "domain.com",
"ipaddress" => "127.0.0.1",
"fqdn" => "testhost.domain.com"
}
- Facter.stubs(:each)
- facts.each do |name, value|
- Facter.stubs(:value).with(name).returns(value)
- end
- # first parse the file
- server = Puppet::Network::Handler.master.new(
- :Manifest => snippet(file),
- :Local => true
- )
- facts = Puppet::Node::Facts.new("testhost", facts)
- Puppet::Node::Facts.stubs(:save)
- Puppet::Node::Facts.stubs(:find).returns(facts)
- client = Puppet::Network::Client.master.new(
- :Master => server,
- :Cache => false
- )
- client.class.stubs(:facts).returns(facts.values)
-
- assert(client.local)
- assert_nothing_raised {
- client.getconfig()
- }
- client = Puppet::Network::Client.master.new(
- :Master => server,
- :Cache => false
- )
+ node = Puppet::Node.new("testhost")
+ node.merge(facts)
- assert(client.local)
- # Now do it again
- Puppet::Type.allclear
- assert_nothing_raised {
- client.getconfig()
+ config = nil
+ assert_nothing_raised("Could not compile configuration") {
+ config = Puppet::Node::Configuration.find(node)
+ }
+
+ assert_nothing_raised("Could not convert configuration") {
+ config = config.to_ral
}
Puppet::Type.eachtype { |type|
@@ -500,12 +479,10 @@ class TestSnippets < Test::Unit::TestCase
assert(obj.name)
}
}
- @configuration = client.configuration
+ @configuration = config
assert_nothing_raised {
self.send(mname)
}
-
- client.clear
}
mname = mname.intern
end
diff --git a/test/language/transportable.rb b/test/language/transportable.rb
index 31931c937..4e4573e0b 100755
--- a/test/language/transportable.rb
+++ b/test/language/transportable.rb
@@ -47,37 +47,17 @@ class TestTransportable < Test::Unit::TestCase
assert(newobj.type, "Bucket has no type")
end
- # Verify that we correctly strip out collectable objects, since they should
- # not be sent to the client.
- def test_collectstrip
- top = mk_transtree do |object, depth, width|
- if width % 2 == 1
- object.collectable = true
- end
- end
-
- assert(top.flatten.find_all { |o| o.collectable }.length > 0,
- "Could not find any collectable objects")
-
- # Now strip out the collectable objects
- top.collectstrip!
-
- # And make sure they're actually gone
- assert_equal(0, top.flatten.find_all { |o| o.collectable }.length,
- "Still found collectable objects")
- end
-
# Make sure our 'delve' command is working
def test_delve
top = mk_transtree do |object, depth, width|
if width % 2 == 1
- object.collectable = true
+ object.file = :funtest
end
end
objects = []
buckets = []
- collectable = []
+ found = []
count = 0
assert_nothing_raised {
@@ -87,8 +67,8 @@ class TestTransportable < Test::Unit::TestCase
buckets << object
else
objects << object
- if object.collectable
- collectable << object
+ if object.file == :funtest
+ found << object
end
end
end
@@ -98,9 +78,9 @@ class TestTransportable < Test::Unit::TestCase
assert(objects.include?(obj), "Missing obj %s[%s]" % [obj.type, obj.name])
end
- assert_equal(collectable.length,
- top.flatten.find_all { |o| o.collectable }.length,
- "Found incorrect number of collectable objects")
+ assert_equal(found.length,
+ top.flatten.find_all { |o| o.file == :funtest }.length,
+ "Found incorrect number of objects")
end
end
diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb
index 62fa7213e..3e3ce6cb9 100644
--- a/test/lib/puppettest/parsertesting.rb
+++ b/test/lib/puppettest/parsertesting.rb
@@ -54,10 +54,8 @@ module PuppetTest::ParserTesting
Puppet::Node.new(name)
end
- def mkinterp(args = {})
- args[:Code] ||= "" unless args.include?(:Manifest)
- args[:Local] ||= true
- Puppet::Parser::Interpreter.new(args)
+ def mkinterp
+ Puppet::Parser::Interpreter.new
end
def mkparser
@@ -301,11 +299,10 @@ module PuppetTest::ParserTesting
# This assumes no nodes
def assert_creates(manifest, *files)
interp = nil
+ oldmanifest = Puppet[:manifest]
+ Puppet[:manifest] = manifest
assert_nothing_raised {
- interp = Puppet::Parser::Interpreter.new(
- :Manifest => manifest,
- :UseNodes => false
- )
+ interp = Puppet::Parser::Interpreter.new
}
trans = nil
@@ -323,6 +320,8 @@ module PuppetTest::ParserTesting
files.each do |file|
assert(FileTest.exists?(file), "Did not create %s" % file)
end
+ ensure
+ Puppet[:manifest] = oldmanifest
end
def mk_transobject(file = "/etc/passwd")
diff --git a/test/network/client/client.rb b/test/network/client/client.rb
index 484c794e4..a297a87e1 100755
--- a/test/network/client/client.rb
+++ b/test/network/client/client.rb
@@ -141,17 +141,13 @@ class TestClient < Test::Unit::TestCase
end
def test_classfile
- manifest = tempfile()
+ Puppet[:code] = "class yaytest {}\n class bootest {}\n include yaytest, bootest"
- File.open(manifest, "w") do |file|
- file.puts "class yaytest {}\n class bootest {}\n include yaytest, bootest"
- end
+ Puppet::Node::Facts.indirection.stubs(:save)
master = client = nil
assert_nothing_raised() {
master = Puppet::Network::Handler.master.new(
- :Manifest => manifest,
- :UseNodes => false,
:Local => false
)
}
diff --git a/test/network/client/master.rb b/test/network/client/master.rb
index 0a3b75b91..4ae77abc2 100755
--- a/test/network/client/master.rb
+++ b/test/network/client/master.rb
@@ -48,8 +48,10 @@ class TestMasterClient < Test::Unit::TestCase
def mkmaster(options = {})
options[:UseNodes] = false
options[:Local] = true
- unless options[:Code]
- options[:Manifest] ||= mktestmanifest
+ if code = options[:Code]
+ Puppet[:code] = code
+ else
+ Puppet[:manifest] = options[:Manifest] || mktestmanifest
end
# create our master
# this is the default server setup
@@ -395,6 +397,8 @@ end
manifest = tempfile()
File.open(manifest, "w") { |f| f.puts "file { '#{file}': content => yay }" }
+ Puppet::Node::Facts.indirection.stubs(:save)
+
driver = mkmaster(:Manifest => manifest)
driver.local = false
master = mkclient(driver)
@@ -404,7 +408,7 @@ end
assert(! master.fresh?(master.class.facts),
"Considered fresh with no compile at all")
-
+
assert_nothing_raised { master.run }
assert(master.fresh?(master.class.facts),
"not considered fresh after compile")
@@ -479,7 +483,9 @@ end
master.local = false
driver = master.send(:instance_variable_get, "@driver")
driver.local = false
+ Puppet::Node::Facts.indirection.stubs(:save)
# Retrieve the configuration
+
master.getconfig
# Now the config is up to date, so get rid of the @objects var and
@@ -507,6 +513,8 @@ end
driver = master.send(:instance_variable_get, "@driver")
driver.local = false
+ Puppet::Node::Facts.indirection.stubs(:save)
+
assert_nothing_raised("Could not compile config") do
master.getconfig
end
diff --git a/test/network/handler/configuration.rb b/test/network/handler/configuration.rb
index 29a393769..1c08fd196 100755
--- a/test/network/handler/configuration.rb
+++ b/test/network/handler/configuration.rb
@@ -25,9 +25,7 @@ class TestHandlerConfiguration < Test::Unit::TestCase
config = Config.new
# First test the defaults
- args = {}
- config.instance_variable_set("@options", args)
- config.expects(:create_interpreter).with(args).returns(:interp)
+ config.expects(:create_interpreter).returns(:interp)
assert_equal(:interp, config.send(:interpreter), "Did not return the interpreter")
# Now run it again and make sure we get the same thing
@@ -39,20 +37,8 @@ class TestHandlerConfiguration < Test::Unit::TestCase
args = {}
# Try it first with defaults.
- Puppet::Parser::Interpreter.expects(:new).with(:Local => config.local?).returns(:interp)
- assert_equal(:interp, config.send(:create_interpreter, args), "Did not return the interpreter")
-
- # Now reset it and make sure a specified manifest passes through
- file = tempfile
- args[:Manifest] = file
- Puppet::Parser::Interpreter.expects(:new).with(:Local => config.local?, :Manifest => file).returns(:interp)
- assert_equal(:interp, config.send(:create_interpreter, args), "Did not return the interpreter")
-
- # And make sure the code does, too
- args.delete(:Manifest)
- args[:Code] = "yay"
- Puppet::Parser::Interpreter.expects(:new).with(:Local => config.local?, :Code => "yay").returns(:interp)
- assert_equal(:interp, config.send(:create_interpreter, args), "Did not return the interpreter")
+ Puppet::Parser::Interpreter.expects(:new).returns(:interp)
+ assert_equal(:interp, config.send(:create_interpreter), "Did not return the interpreter")
end
# Make sure node objects get appropriate data added to them.
@@ -67,7 +53,7 @@ class TestHandlerConfiguration < Test::Unit::TestCase
config.send(:add_node_data, fakenode)
# Now try it with classes.
- config.instance_variable_set("@options", {:Classes => %w{a b}})
+ config.classes = %w{a b}
list = []
fakenode = Object.new
fakenode.expects(:merge).with(:facts)
@@ -126,8 +112,9 @@ class TestHandlerConfiguration < Test::Unit::TestCase
# Now a non-local
config = Config.new(:Local => false)
- obj = Object.new
- yamld = Object.new
+ assert(! config.local?, "Config wrongly thinks it's local")
+ obj = mock 'dumpee'
+ yamld = mock 'yaml'
obj.expects(:to_yaml).with(:UseBlock => true).returns(yamld)
CGI.expects(:escape).with(yamld).returns(:translated)
assert_equal(:translated, config.send(:translate, obj), "Did not return translated config")
diff --git a/test/network/handler/master.rb b/test/network/handler/master.rb
index 42c4d22c9..6c4451d06 100755
--- a/test/network/handler/master.rb
+++ b/test/network/handler/master.rb
@@ -56,11 +56,10 @@ class TestMaster < Test::Unit::TestCase
@@tmpfiles << file2
client = master = nil
+ Puppet[:manifest] = manifest
assert_nothing_raised() {
# this is the default server setup
master = Puppet::Network::Handler.master.new(
- :Manifest => manifest,
- :UseNodes => false,
:Local => true
)
}
diff --git a/test/network/handler/runner.rb b/test/network/handler/runner.rb
index 23883a17c..50a00862a 100755
--- a/test/network/handler/runner.rb
+++ b/test/network/handler/runner.rb
@@ -7,15 +7,14 @@ require 'puppettest'
class TestHandlerRunner < Test::Unit::TestCase
include PuppetTest
- def mkclient(file)
+ def mkclient(code)
master = nil
client = nil
+ Puppet[:code] = code
# create our master
assert_nothing_raised() {
# this is the default server setup
master = Puppet::Network::Handler.master.new(
- :Manifest => file,
- :UseNodes => false,
:Local => true
)
}
@@ -38,8 +37,7 @@ class TestHandlerRunner < Test::Unit::TestCase
created = tempfile()
# We specify the schedule here, because I was having problems with
# using default schedules.
- File.open(file, "w") do |f|
- f.puts %{
+ code = %{
class yayness {
schedule { "yayness": period => weekly }
file { "#{created}": ensure => file, schedule => yayness }
@@ -47,9 +45,8 @@ class TestHandlerRunner < Test::Unit::TestCase
include yayness
}
- end
- client = mkclient(file)
+ client = mkclient(code)
runner = nil
assert_nothing_raised {
diff --git a/test/rails/configuration.rb b/test/rails/configuration.rb
index 752ea5375..277753945 100755
--- a/test/rails/configuration.rb
+++ b/test/rails/configuration.rb
@@ -25,7 +25,6 @@ class ConfigurationRailsTests < PuppetTest::TestCase
def test_finish_before_store
railsinit
compile = mkcompile
- compile.ast_nodes = true
parser = compile.parser
node = parser.newnode [compile.node.name], :code => AST::ASTArray.new(:children => [
@@ -52,19 +51,9 @@ class ConfigurationRailsTests < PuppetTest::TestCase
Puppet[:storeconfigs] = true
}
- file = tempfile()
- File.open(file, "w") { |f|
- f.puts "file { \"/etc\": owner => root }"
- }
+ Puppet[:code] = "file { \"/etc\": owner => root }"
- interp = nil
- assert_nothing_raised {
- interp = Puppet::Parser::Interpreter.new(
- :Manifest => file,
- :UseNodes => false,
- :ForkSave => false
- )
- }
+ interp = Puppet::Parser::Interpreter.new
facts = {}
Facter.each { |fact, val| facts[fact] = val }
diff --git a/test/ral/providers/service/debian.rb b/test/ral/providers/service/debian.rb
new file mode 100755
index 000000000..f74141f9e
--- /dev/null
+++ b/test/ral/providers/service/debian.rb
@@ -0,0 +1,71 @@
+#!/usr/bin/env ruby
+#
+# Created by David Schmitt on 2007-09-13
+# Copyright (c) 2007. All rights reserved.
+
+$:.unshift("../../../lib") if __FILE__ =~ /\.rb$/
+
+require 'puppettest'
+
+class TestDebianServiceProvider < Test::Unit::TestCase
+ include PuppetTest
+ include Puppet::Util
+
+ def prepare_provider(servicename, output)
+ service = Puppet::Type.type(:service).create(
+ :name => servicename, :provider => :debian
+ )
+
+ provider = service.provider
+ assert(provider, "did not get debian provider")
+
+ metaclass = class << provider
+ self
+ end
+
+ metaclass.instance_eval do
+ define_method :update do |*args|
+ return output
+ end
+ end
+
+ provider
+ end
+
+ def assert_enabled( servicename, output)
+ provider = prepare_provider( servicename, output )
+ assert_equal(:true, provider.enabled?,
+ "Service provider=debian thinks service is disabled, when it isn't")
+ end
+
+ def assert_disabled( servicename, output )
+ provider = prepare_provider( servicename, output )
+ assert_equal(:false, provider.enabled?,
+ "Service provider=debian thinks service is enabled, when it isn't")
+ end
+
+ # Testing #822
+ def test_file_rc
+ # These messages are from file-rc's
+ # update-rc.d -n -f $service remove
+ assert_enabled("test1", "/etc/runlevel.tmp not installed as /etc/runlevel.conf\n")
+ assert_disabled("test2", "Nothing to do.\n")
+ end
+
+ def test_sysv_rc
+ # These messages are from file-rc's
+ # update-rc.d -n -f $service remove
+ assert_enabled("test3", """ Removing any system startup links for /etc/init.d/test3 ...
+ /etc/rc0.d/K11test3
+ /etc/rc1.d/K11test3
+ /etc/rc2.d/S89test3
+ /etc/rc3.d/S89test3
+ /etc/rc4.d/S89test3
+ /etc/rc5.d/S89test3
+ /etc/rc6.d/K11test3
+""")
+ assert_disabled("test4", " Removing any system startup links for /etc/init.d/test4 ...\n")
+ end
+end
+
+# $Id$