summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-08-23 13:25:40 -0500
committerLuke Kanies <luke@madstop.com>2007-08-23 13:25:40 -0500
commit724fef1269bd593496bca9827a0ad7d9361e92d4 (patch)
tree8b8fb73ee625680bcbc3913e2ee007c8b344f44f /test
parent3d68ed66ca7545c26b83a4c921d21f5aad710ee0 (diff)
downloadpuppet-724fef1269bd593496bca9827a0ad7d9361e92d4.tar.gz
puppet-724fef1269bd593496bca9827a0ad7d9361e92d4.tar.xz
puppet-724fef1269bd593496bca9827a0ad7d9361e92d4.zip
Everything up to the parser (and the Modules) is ready to support multiple environments, including the parser having an environment setting. I have also created my first spec-based tests, for the interpreter (and deleted the old test/unit tests).
Diffstat (limited to 'test')
-rwxr-xr-xtest/language/configuration.rb26
-rwxr-xr-xtest/language/functions.rb9
-rwxr-xr-xtest/language/interpreter.rb152
-rw-r--r--test/lib/puppettest/parsertesting.rb3
4 files changed, 26 insertions, 164 deletions
diff --git a/test/language/configuration.rb b/test/language/configuration.rb
index a17b5a7ae..409d4ca1d 100755
--- a/test/language/configuration.rb
+++ b/test/language/configuration.rb
@@ -424,17 +424,22 @@ class TestConfiguration < Test::Unit::TestCase
Puppet.features.expects(:rails?).returns(true)
Puppet::Rails.expects(:connect)
- args = {:name => "yay"}
- config.expects(:store_to_active_record).with(args)
- config.send(:store, args)
+ node = mock 'node'
+ resource_table = mock 'resources'
+ resource_table.expects(:values).returns(:resources)
+ config.instance_variable_set("@node", node)
+ config.instance_variable_set("@resource_table", resource_table)
+ config.expects(:store_to_active_record).with(node, :resources)
+ config.send(:store)
end
def test_store_to_active_record
config = mkconfig
- args = {:name => "yay"}
+ node = mock 'node'
+ node.expects(:name).returns("myname")
Puppet::Rails::Host.stubs(:transaction).yields
- Puppet::Rails::Host.expects(:store).with(args)
- config.send(:store_to_active_record, args)
+ Puppet::Rails::Host.expects(:store).with(node, :resources)
+ config.send(:store_to_active_record, node, :resources)
end
# Make sure that 'finish' gets called on all of our resources.
@@ -473,8 +478,10 @@ class TestConfiguration < Test::Unit::TestCase
# Get rid of the topscope
scopes.vertices.each { |v| scopes.remove_vertex!(v) }
+ bucket = []
scope = mock("scope")
- scope.expects(:to_trans).returns([])
+ bucket.expects(:copy_type_and_name).with(scope)
+ scope.expects(:to_trans).returns(bucket)
scopes.add_vertex! scope
# The topscope is the key to picking out the top of the graph.
@@ -510,7 +517,10 @@ class TestConfiguration < Test::Unit::TestCase
# Create our scopes.
top = mock("top")
- top.expects(:to_trans).returns(fakebucket.new("top"))
+ topbucket = fakebucket.new "top"
+ topbucket.expects(:copy_type_and_name).with(top)
+ top.stubs(:copy_type_and_name)
+ top.expects(:to_trans).returns(topbucket)
# The topscope is the key to picking out the top of the graph.
config.instance_variable_set("@topscope", top)
middle = mock("middle")
diff --git a/test/language/functions.rb b/test/language/functions.rb
index 42d8d7585..9314df179 100755
--- a/test/language/functions.rb
+++ b/test/language/functions.rb
@@ -208,8 +208,11 @@ class TestLangFunctions < Test::Unit::TestCase
:UseNodes => false
)
node = mknode
+ node.stubs(:environment).returns("yay")
- parsedate = interp.parsedate()
+ Puppet[:environment] = "yay"
+
+ version = interp.configuration_version(node)
objects = nil
assert_nothing_raised {
@@ -233,9 +236,9 @@ class TestLangFunctions < Test::Unit::TestCase
assert_nothing_raised {
objects = interp.compile(node)
}
- newdate = interp.parsedate()
+ newversion = interp.configuration_version(node)
- assert(parsedate != newdate, "Parse date did not change")
+ assert(version != newversion, "Parse date did not change")
end
def test_template_defined_vars
diff --git a/test/language/interpreter.rb b/test/language/interpreter.rb
deleted file mode 100755
index 1adcb7bde..000000000
--- a/test/language/interpreter.rb
+++ /dev/null
@@ -1,152 +0,0 @@
-#!/usr/bin/env ruby
-
-$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
-
-require 'facter'
-
-require 'puppet'
-require 'puppet/parser/interpreter'
-require 'puppet/parser/parser'
-require 'puppet/network/client'
-require 'puppettest'
-require 'puppettest/resourcetesting'
-require 'puppettest/parsertesting'
-require 'puppettest/servertest'
-require 'timeout'
-
-class TestInterpreter < PuppetTest::TestCase
- include PuppetTest
- include PuppetTest::ServerTest
- include PuppetTest::ParserTesting
- include PuppetTest::ResourceTesting
- AST = Puppet::Parser::AST
-
- # create a simple manifest that uses nodes to create a file
- def mknodemanifest(node, file)
- createdfile = tempfile()
-
- File.open(file, "w") { |f|
- f.puts "node %s { file { \"%s\": ensure => file, mode => 755 } }\n" %
- [node, createdfile]
- }
-
- return [file, createdfile]
- end
-
- def test_reloadfiles
- node = mknode(Facter["hostname"].value)
-
- file = tempfile()
-
- # Create a first version
- createdfile = mknodemanifest(node.name, file)
-
- interp = nil
- assert_nothing_raised {
- interp = Puppet::Parser::Interpreter.new(:Manifest => file)
- }
-
- config = nil
- assert_nothing_raised {
- config = interp.compile(node)
- }
- Puppet[:filetimeout] = -5
-
- # Now create a new file
- createdfile = mknodemanifest(node.name, file)
-
- newconfig = nil
- assert_nothing_raised {
- newconfig = interp.compile(node)
- }
-
- assert(config != newconfig, "Configs are somehow the same")
- end
-
- def test_parsedate
- Puppet[:filetimeout] = 0
- main = tempfile()
- sub = tempfile()
- mainfile = tempfile()
- subfile = tempfile()
- count = 0
- updatemain = proc do
- count += 1
- File.open(main, "w") { |f|
- f.puts "import '#{sub}'
- file { \"#{mainfile}\": content => #{count} }
- "
- }
- end
- updatesub = proc do
- count += 1
- File.open(sub, "w") { |f|
- f.puts "file { \"#{subfile}\": content => #{count} }
- "
- }
- end
-
- updatemain.call
- updatesub.call
-
- interp = Puppet::Parser::Interpreter.new(
- :Manifest => main,
- :Local => true
- )
-
- date = interp.parsedate
-
- # Now update the site file and make sure we catch it
- sleep 1
- updatemain.call
- newdate = interp.parsedate
- assert(date != newdate, "Parsedate was not updated")
- date = newdate
-
- # And then the subfile
- sleep 1
- updatesub.call
- newdate = interp.parsedate
- assert(date != newdate, "Parsedate was not updated")
- end
-
- # Make sure our whole chain works.
- def test_compile
- interp = mkinterp
- interp.expects(:parsefiles)
- parser = interp.instance_variable_get("@parser")
-
- node = mock('node')
- config = mock('config')
- config.expects(:compile).returns(:config)
- Puppet::Parser::Configuration.expects(:new).with(node, parser, :ast_nodes => interp.usenodes).returns(config)
- assert_equal(:config, interp.compile(node), "Did not return the results of config.compile")
- end
-
- # Make sure that reparsing is atomic -- failures don't cause a broken state, and we aren't subject
- # to race conditions if someone contacts us while we're reparsing.
- def test_atomic_reparsing
- Puppet[:filetimeout] = -10
- file = tempfile
- File.open(file, "w") { |f| f.puts %{file { '/tmp': ensure => directory }} }
- interp = mkinterp :Manifest => file, :UseNodes => false
-
- assert_nothing_raised("Could not compile the first time") do
- interp.compile(mknode("yay"))
- end
-
- oldparser = interp.send(:instance_variable_get, "@parser")
-
- # Now add a syntax failure
- File.open(file, "w") { |f| f.puts %{file { /tmp: ensure => directory }} }
- assert_nothing_raised("Could not compile the first time") do
- interp.compile(mknode("yay"))
- end
-
- # And make sure the old parser is still there
- newparser = interp.send(:instance_variable_get, "@parser")
- assert_equal(oldparser.object_id, newparser.object_id, "Failed parser still replaced existing parser")
- end
-end
-
-# $Id$
diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb
index 3e2930728..326c25756 100644
--- a/test/lib/puppettest/parsertesting.rb
+++ b/test/lib/puppettest/parsertesting.rb
@@ -49,9 +49,10 @@ module PuppetTest::ParserTesting
end
def mknode(name = nil)
+ require 'puppet/node'
name ||= "nodename"
Puppet::Network::Handler.handler(:node)
- Puppet::Network::Handler::Node::SimpleNode.new(name)
+ Puppet::Node.new(name)
end
def mkinterp(args = {})