diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-23 04:49:56 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-23 04:49:56 +0000 |
| commit | 9bb5c50d0b30b4dfb82b6b705dfcbf0e126a9d61 (patch) | |
| tree | e41fbeb90e4050ea2af6d37e7b443cf9f84be162 /test | |
| parent | be711d357857f5e6d4a28a22bd60dd89e9e136c0 (diff) | |
Not downcasing facts any longer, closing #210 (although not using the patch from mpalmer, since I had not noticed the patch was there). Also, making all nodes, classes, and definitions case insensitive, closing #344. Finally, I added case insensitivity to the language in general, which should preserve backwards compatibility and probably makes the most sense in the long run anyway.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1964 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
| -rwxr-xr-x | test/client/master.rb | 17 | ||||
| -rwxr-xr-x | test/language/ast.rb | 21 | ||||
| -rwxr-xr-x | test/language/ast/casestatement.rb | 67 | ||||
| -rwxr-xr-x | test/language/ast/selector.rb | 53 | ||||
| -rwxr-xr-x | test/language/interpreter.rb | 30 | ||||
| -rwxr-xr-x | test/language/node.rb | 4 | ||||
| -rwxr-xr-x | test/lib/puppettest.rb | 9 | ||||
| -rw-r--r-- | test/lib/puppettest/parsertesting.rb | 28 | ||||
| -rwxr-xr-x | test/other/statechange.rb | 111 | ||||
| -rwxr-xr-x | test/other/transactions.rb | 117 |
10 files changed, 393 insertions, 64 deletions
diff --git a/test/client/master.rb b/test/client/master.rb index 987649a74..5b34e6a7e 100755 --- a/test/client/master.rb +++ b/test/client/master.rb @@ -427,6 +427,23 @@ end assert_equal(Process.uid, File.stat(destfile).uid) end end + + # Test retrieving all of the facts. + def test_facts + facts = nil + assert_nothing_raised do + facts = Puppet::Client::MasterClient.facts + end + Facter.to_hash.each do |fact, value| + assert_equal(facts[fact.downcase], value, "%s is not equal" % fact.inspect) + end + + # Make sure the puppet version got added + assert_equal(Puppet::PUPPETVERSION, facts["clientversion"], "client version did not get added") + + # And make sure the ruby version is in there + assert_equal(RUBY_VERSION, facts["rubyversion"], "ruby version did not get added") + end end # $Id$ diff --git a/test/language/ast.rb b/test/language/ast.rb index 3fb6f5c0d..ffec7e66a 100755 --- a/test/language/ast.rb +++ b/test/language/ast.rb @@ -16,26 +16,7 @@ class TestAST < Test::Unit::TestCase include PuppetTest::RailsTesting include PuppetTest::ParserTesting include PuppetTest::ResourceTesting - - # A fake class that we can use for testing evaluation. - class FakeAST - attr_writer :evaluate - - def evaluate(*args) - return @evaluate - end - - def initialize(val = nil) - if val - @evaluate = val - end - end - - def safeevaluate(*args) - evaluate() - end - end - + if defined? ActiveRecord # Verify that our collection stuff works. def test_collection diff --git a/test/language/ast/casestatement.rb b/test/language/ast/casestatement.rb new file mode 100755 index 000000000..493474909 --- /dev/null +++ b/test/language/ast/casestatement.rb @@ -0,0 +1,67 @@ +#!/usr/bin/env ruby +# +# Created by Luke A. Kanies on 2006-12-22. +# Copyright (c) 2006. All rights reserved. + +$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ + +require 'puppettest' +require 'puppettest/parsertesting' + +class TestCaseStatement < Test::Unit::TestCase + include PuppetTest + include PuppetTest::ParserTesting + AST = Puppet::Parser::AST + + class ActiveAST < FakeAST + def self.clear + $evaluated = [] + end + def evaluate + $evaluated ||= [] + $evaluated << @evaluate + end + end + + def test_evaluate + ast = nil + scope = mkscope + param = nameobj("MyParam") + + hash = { + "myparam" => ActiveAST.new("lower"), + "MyParam" => ActiveAST.new("upper"), + true => ActiveAST.new(true) + } + options = ["myparam", "MyParam"].collect do |p| + AST::CaseOpt.new(:value => FakeAST.new(p), :statements => hash[p]) + end + assert_nothing_raised do + ast = AST::CaseStatement.new(:test => param, :options => options) + end + + # Start out case-sensitive + Puppet[:casesensitive] = true + + result = nil + assert_nothing_raised do + result = ast.evaluate :scope => scope + end + assert(result, "did not get valid result") + assert_equal(["upper"], $evaluated, "Did not match case-sensitively") + assert(! hash["myparam"].evaluated?, "lower value was evaluated even though it did not match") + + # Now try it case-insensitive + Puppet[:casesensitive] = false + $evaluated.clear + hash["MyParam"].reset + assert_nothing_raised do + result = ast.evaluate :scope => scope + end + assert(result, "did not get valid result") + assert_equal(["lower"], result, "Did not match case-insensitively") + assert(! hash["MyParam"].evaluated?, "upper value was evaluated even though it did not match") + end +end + +# $Id$
\ No newline at end of file diff --git a/test/language/ast/selector.rb b/test/language/ast/selector.rb new file mode 100755 index 000000000..343134348 --- /dev/null +++ b/test/language/ast/selector.rb @@ -0,0 +1,53 @@ +#!/usr/bin/env ruby +# +# Created by Luke A. Kanies on 2006-12-22. +# Copyright (c) 2006. All rights reserved. + +$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ + +require 'puppettest' +require 'puppettest/parsertesting' + +class TestSelector < Test::Unit::TestCase + include PuppetTest + include PuppetTest::ParserTesting + AST = Puppet::Parser::AST + + def test_evaluate + sel = nil + scope = mkscope + param = nameobj("MyParam") + + hash = { + "myparam" => FakeAST.new("lower"), + "MyParam" => FakeAST.new("upper") + } + values = ["myparam", "MyParam"].collect do |p| + AST::ResourceParam.new(:param => FakeAST.new(p), :value => hash[p]) + end + assert_nothing_raised do + sel = AST::Selector.new(:param => param, :values => values) + end + + # Start out case-sensitive + Puppet[:casesensitive] = true + + result = nil + assert_nothing_raised do + result = sel.evaluate :scope => scope + end + assert_equal("upper", result, "Did not match case-sensitively") + assert(! hash["myparam"].evaluated?, "lower value was evaluated even though it did not match") + + # Now try it case-insensitive + Puppet[:casesensitive] = false + hash["MyParam"].reset + assert_nothing_raised do + result = sel.evaluate :scope => scope + end + assert_equal("lower", result, "Did not match case-insensitively") + assert(! hash["MyParam"].evaluated?, "upper value was evaluated even though it did not match") + end +end + +# $Id$
\ No newline at end of file diff --git a/test/language/interpreter.rb b/test/language/interpreter.rb index a19bec288..e82461d1b 100755 --- a/test/language/interpreter.rb +++ b/test/language/interpreter.rb @@ -610,7 +610,35 @@ class TestInterpreter < Test::Unit::TestCase end assert(klass, "Did not return class with no code") assert_nil(interp.findclass("", "nocode3").code) - + end + + # Make sure class, node, and define methods are case-insensitive + def test_structure_case_insensitivity + interp = mkinterp + + result = nil + assert_nothing_raised do + result = interp.newclass "Yayness" + end + assert_equal(result, interp.findclass("", "yayNess")) + + assert_nothing_raised do + result = interp.newdefine "FunTest" + end + assert_equal(result, interp.finddefine("", "fUntEst"), + "%s was not matched" % "fUntEst") + + assert_nothing_raised do + result = interp.newnode("MyNode").shift + end + assert_equal(result, interp.nodesearch("mYnOde"), + "mYnOde was not matched") + + assert_nothing_raised do + result = interp.newnode("YayTest.Domain.Com").shift + end + assert_equal(result, interp.nodesearch("yaYtEst.domAin.cOm"), + "yaYtEst.domAin.cOm was not matched") end # Now make sure we get appropriate behaviour with parent class conflicts. diff --git a/test/language/node.rb b/test/language/node.rb index 3f5ff5561..ccdc77fda 100755 --- a/test/language/node.rb +++ b/test/language/node.rb @@ -58,8 +58,8 @@ class TestParser < Test::Unit::TestCase # Now make sure we can look up each of the names hostnames.each do |name| - assert(interp.nodesearch_code(name), - "Could not find node %s" % name) + assert(interp.nodesearch(name), + "Could not find node %s" % name.inspect) end end diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb index e83cc9a04..67d1a29c9 100755 --- a/test/lib/puppettest.rb +++ b/test/lib/puppettest.rb @@ -55,6 +55,15 @@ module PuppetTest ENV["RUBYLIB"] = curlibs.join(":") end + + def logcollector + collector = [] + Puppet::Log.newdestination(collector) + cleanup do + Puppet::Log.close(collector) + end + collector + end def rake? $0 =~ /rake_test_loader/ diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb index c7d4ec961..f71ba6b82 100644 --- a/test/lib/puppettest/parsertesting.rb +++ b/test/lib/puppettest/parsertesting.rb @@ -5,6 +5,34 @@ module PuppetTest::ParserTesting include PuppetTest AST = Puppet::Parser::AST + # A fake class that we can use for testing evaluation. + class FakeAST + attr_writer :evaluate + + def evaluated? + defined? @evaluated and @evaluated + end + + def evaluate(*args) + @evaluated = true + return @evaluate + end + + def initialize(val = nil) + if val + @evaluate = val + end + end + + def reset + @evaluated = nil + end + + def safeevaluate(*args) + evaluate() + end + end + def astarray(*args) AST::ASTArray.new( :children => args diff --git a/test/other/statechange.rb b/test/other/statechange.rb new file mode 100755 index 000000000..09295a5f0 --- /dev/null +++ b/test/other/statechange.rb @@ -0,0 +1,111 @@ +#!/usr/bin/env ruby +# +# Created by Luke A. Kanies on 2006-12-21. +# Copyright (c) 2006. All rights reserved. + +$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ + +require 'puppettest' + +class TestStateChange < Test::Unit::TestCase + include PuppetTest + class FakeState + attr_accessor :is, :should, :parent + def change_to_s + "fake change" + end + def insync? + @is == @should + end + def log(msg) + Puppet::Log.create( + :level => :info, + :source => self, + :message => msg + ) + end + def noop + false + end + def path + "fakechange" + end + def sync + if insync? + return nil + else + @is = @should + return :fake_change + end + end + def to_s + path + end + end + + def mkchange + state = FakeState.new + state.is = :start + state.should = :finish + state.parent = :parent + change = nil + assert_nothing_raised do + change = Puppet::StateChange.new(state) + end + change.transaction = :trans + + assert_equal(:start, change.is, "@is did not get copied") + assert_equal(:finish, change.should, "@should did not get copied") + assert_equal(%w{fakechange change}, change.path, "path did not get set correctly") + + assert(! change.changed?, "change defaulted to already changed") + + return change + end + + def test_go + change = mkchange + + coll = logcollector() + + events = nil + # First make sure we get an immediate return + assert_nothing_raised do + events = change.go + end + assert_instance_of(Array, events, "events were not returned in an array") + assert_instance_of(Puppet::Event, events[0], "event array did not contain events") + + event = events.shift + {:event => :fake_change, :transaction => :trans, :source => :parent}.each do |method, val| + assert_equal(val, event.send(method), "Event did not set %s correctly" % method) + end + + assert(coll.detect { |l| l.message == "fake change" }, "Did not log change") + assert_equal(change.state.is, change.state.should, "did not call sync method") + + # Now make sure that proxy sources can be set. + assert_nothing_raised do + change.proxy = :other + end + # Reset, so we change again + change.state.is = :start + change.is = :start + assert_nothing_raised do + events = change.go + end + + assert_instance_of(Array, events, "events were not returned in an array") + assert_instance_of(Puppet::Event, events[0], "event array did not contain events") + + event = events.shift + {:event => :fake_change, :transaction => :trans, :source => :other}.each do |method, val| + assert_equal(val, event.send(method), "Event did not set %s correctly" % method) + end + + assert(coll.detect { |l| l.message == "fake change" }, "Did not log change") + assert_equal(change.state.is, change.state.should, "did not call sync method") + end +end + +# $Id$
\ No newline at end of file diff --git a/test/other/transactions.rb b/test/other/transactions.rb index 32a6b4acd..1b9257dec 100755 --- a/test/other/transactions.rb +++ b/test/other/transactions.rb @@ -26,6 +26,27 @@ class TestTransactions < Test::Unit::TestCase return type end + + # Create a new type that generates instances with shorter names. + def mkreducer(&block) + type = mkgenerator() do + def eval_generate + ret = [] + if title.length > 1 + ret << self.class.create(:title => title[0..-2]) + else + return nil + end + ret + end + end + + if block + type.class_eval(&block) + end + + return type + end def test_reports path1 = tempfile() @@ -253,26 +274,6 @@ class TestTransactions < Test::Unit::TestCase } end - # start a service, and then roll the modification back - # Disabled, because it wasn't really worth the effort. - def disabled_test_servicetrans - transaction = nil - service = newservice() - - component = newcomp("service",service) - - assert_nothing_raised() { - service[:ensure] = 1 - } - service.retrieve - assert(service.insync?, "Service did not start") - system("ps -ef | grep ruby") - trans = assert_events([:service_started], component) - service.retrieve - - assert_rollback_events(trans, [:service_stopped], "service") - end - # test that services are correctly restarted and that work is done # in the right order def test_refreshing @@ -607,17 +608,8 @@ class TestTransactions < Test::Unit::TestCase # Test mid-evaluation generation. def test_eval_generate $evaluated = [] - type = mkgenerator() do - def eval_generate - ret = [] - if title.length > 1 - ret << self.class.create(:title => title[0..-2]) - else - return nil - end - ret - end - + cleanup { $evaluated = nil } + type = mkreducer() do def evaluate $evaluated << self.title return [] @@ -644,14 +636,8 @@ class TestTransactions < Test::Unit::TestCase # Now make sure the appropriate relationships were added assert(trans.relgraph.edge?(yay, ya), "parent was not required by child") - assert(trans.relgraph.edge?(ya, rah), - "rah was not subscribed to ya") - - # And make sure the relationship is a subscription with a callback, - # not just a require. - assert_equal({:callback => :refresh, :event => :ALL_EVENTS}, - trans.relgraph[Puppet::Relationship.new(ya, rah)], - "The label was not retained") + assert(! trans.relgraph.edge?(ya, rah), + "generated child ya inherited depencency on rah") # Now make sure it in turn eval_generates appropriately assert_nothing_raised("failed to apply yay") do @@ -683,8 +669,6 @@ class TestTransactions < Test::Unit::TestCase # the generating resource assert(! trans.relgraph.edge?(yay, ra), "rah passed its dependencies on to its children") - assert(trans.relgraph.edge?(ya, rah), - "rah is not subscribed to ya") assert(! trans.relgraph.edge?(ya, ra), "children have a direct relationship") @@ -779,6 +763,57 @@ class TestTransactions < Test::Unit::TestCase assert(FileTest.exists?(path1), "required file was deleted") end + + # Make sure changes generated by eval_generated resources have proxies + # set to the top-level resource. + def test_proxy_resources + Struct.new("FakeEvalState", :path, :is, :should, :name) + Struct::FakeEvalState.send(:define_method, :insync?) { true } + Struct::FakeEvalState.send(:define_method, :info) { |*args| false } + + + type = mkreducer do + def evaluate + return Puppet::StateChange.new(Struct::FakeEvalState.new(:path, :is, :should, self.name)) + end + end + + resource = type.create :name => "test" + comp = newcomp(resource) + trans = comp.evaluate + trans.prepare + + assert_nothing_raised do + trans.eval_resource(resource) + end + + changes = trans.instance_variable_get("@changes") + + assert(changes.length > 0, "did not get any changes") + + changes.each do |change| + assert_equal(resource, change.source, "change did not get proxy set correctly") + end + end + + # Make sure changes in contained files still generate callback events. + def test_generated_callbacks + dir = tempfile() + maker = tempfile() + Dir.mkdir(dir) + file = File.join(dir, "file") + File.open(file, "w") { |f| f.puts "" } + File.chmod(0644, file) + File.chmod(0755, dir) # So only the child file causes a change + + dirobj = Puppet::Type.type(:file).create :mode => "755", :recurse => true, :path => dir + exec = Puppet::Type.type(:exec).create :title => "make", + :command => "touch #{maker}", :path => ENV['PATH'], :refreshonly => true, + :subscribe => dirobj + + assert_apply(dirobj, exec) + assert(FileTest.exists?(maker), "Did not make callback file") + end end # $Id$ |
