diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/data/providers/host/parsed/valid_hosts | 19 | ||||
-rwxr-xr-x | test/language/functions.rb | 2 | ||||
-rwxr-xr-x | test/language/parser.rb | 93 | ||||
-rwxr-xr-x | test/language/scope.rb | 12 | ||||
-rwxr-xr-x | test/language/snippets.rb | 2 | ||||
-rwxr-xr-x | test/lib/puppettest.rb | 4 | ||||
-rw-r--r-- | test/lib/puppettest/parsertesting.rb | 13 | ||||
-rwxr-xr-x | test/network/handler/master.rb | 20 | ||||
-rwxr-xr-x | test/rails/railsparameter.rb | 2 | ||||
-rwxr-xr-x | test/ral/providers/cron/crontab.rb | 5 | ||||
-rwxr-xr-x | test/ral/providers/host/parsed.rb | 9 |
11 files changed, 100 insertions, 81 deletions
diff --git a/test/data/providers/host/parsed/valid_hosts b/test/data/providers/host/parsed/valid_hosts new file mode 100644 index 000000000..24636295d --- /dev/null +++ b/test/data/providers/host/parsed/valid_hosts @@ -0,0 +1,19 @@ +# Some leading comment, that should be ignored +# The next line is empty so it should be ignored + +::1 localhost + +# We now try another delimiter: Several tabs +127.0.0.1 localhost + +# No test trailing spaces +10.0.0.1 host1 + +# Ok its time to test aliases +2001:252:0:1::2008:8 ipv6host alias1 +192.168.0.1 ipv4host alias2 alias3 + +# Testing inlinecomments now +192.168.0.2 host3 # This is host3 +192.168.0.3 host4 alias10 # This is host4 +192.168.0.4 host5 alias11 alias12 # This is host5 diff --git a/test/language/functions.rb b/test/language/functions.rb index 1d4ed8241..081063e2b 100755 --- a/test/language/functions.rb +++ b/test/language/functions.rb @@ -451,7 +451,7 @@ class TestLangFunctions < Test::Unit::TestCase scope.function_include("nosuchclass") end - parser.newclass("myclass") + scope.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "myclass", {}) scope.compiler.expects(:evaluate_classes).with(%w{myclass otherclass}, scope, false).returns(%w{myclass otherclass}) diff --git a/test/language/parser.rb b/test/language/parser.rb index 8cda8eeb2..93d4ae693 100755 --- a/test/language/parser.rb +++ b/test/language/parser.rb @@ -39,9 +39,8 @@ class TestParser < Test::Unit::TestCase failers { |file| parser = mkparser Puppet.debug("parsing failer #{file}") if __FILE__ == $0 - assert_raise(Puppet::ParseError, "Did not fail while parsing #{file}") { - parser.file = file - ast = parser.parse + assert_raise(Puppet::ParseError, Puppet::Error, "Did not fail while parsing #{file}") { + Puppet[:manifest] = file config = mkcompiler(parser) config.compile #ast.hostclass("").evaluate config.topscope @@ -288,7 +287,7 @@ class TestParser < Test::Unit::TestCase ret = parser.parse } - ret.hostclass("").code.each do |obj| + ret.code.each do |obj| assert_instance_of(AST::Collection, obj) end end @@ -362,12 +361,12 @@ file { "/tmp/yayness": assert_raise(Puppet::ParseError) { - parser.parse %{define mydef($schedule) {}} + parser.known_resource_types.import_ast(parser.parse(%{define mydef($schedule) {}}), '') } assert_nothing_raised { - parser.parse %{define adef($schedule = false) {}} - parser.parse %{define mydef($schedule = daily) {}} + parser.known_resource_types.import_ast(parser.parse(%{define adef($schedule = false) {}}), '') + parser.known_resource_types.import_ast(parser.parse(%{define mydef($schedule = daily) {}}), '') } end @@ -379,12 +378,12 @@ file { "/tmp/yayness": str1 = %{if true { #{exec.call("true")} }} ret = nil assert_nothing_raised { - ret = parser.parse(str1).hostclass("").code[0] + ret = parser.parse(str1).code[0] } assert_instance_of(Puppet::Parser::AST::IfStatement, ret) parser = mkparser str2 = %{if true { #{exec.call("true")} } else { #{exec.call("false")} }} - ret = parser.parse(str2).hostclass("").code[0] + ret = parser.parse(str2).code[0] assert_instance_of(Puppet::Parser::AST::IfStatement, ret) assert_instance_of(Puppet::Parser::AST::Else, ret.else) end @@ -393,23 +392,23 @@ file { "/tmp/yayness": parser = mkparser assert_nothing_raised { - parser.parse %{class myclass { class other {} }} + parser.known_resource_types.import_ast(parser.parse(%{class myclass { class other {} }}), '') } assert(parser.hostclass("myclass"), "Could not find myclass") assert(parser.hostclass("myclass::other"), "Could not find myclass::other") assert_nothing_raised { - parser.parse "class base {} + parser.known_resource_types.import_ast(parser.parse("class base {} class container { class deep::sub inherits base {} - }" + }"), '') } sub = parser.hostclass("container::deep::sub") assert(sub, "Could not find sub") # Now try it with a parent class being a fq class assert_nothing_raised { - parser.parse "class container::one inherits container::deep::sub {}" + parser.known_resource_types.import_ast(parser.parse("class container::one inherits container::deep::sub {}"), '') } sub = parser.hostclass("container::one") assert(sub, "Could not find one") @@ -417,7 +416,7 @@ file { "/tmp/yayness": # Finally, try including a qualified class assert_nothing_raised("Could not include fully qualified class") { - parser.parse "include container::deep::sub" + parser.known_resource_types.import_ast(parser.parse("include container::deep::sub"), '') } end @@ -426,20 +425,11 @@ file { "/tmp/yayness": # Make sure we put the top-level code into a class called "" in # the "" namespace - assert_nothing_raised do - out = parser.parse "" - - assert_instance_of(Puppet::Resource::TypeCollection, out) - assert_nil(parser.hostclass(""), "Got a 'main' class when we had no code") - end - - # Now try something a touch more complicated parser.initvars assert_nothing_raised do - out = parser.parse "Exec { path => '/usr/bin:/usr/sbin' }" - assert_instance_of(Puppet::Resource::TypeCollection, out) - assert_equal("", parser.hostclass("").name) - assert_equal("", parser.hostclass("").namespace) + parser.known_resource_types.import_ast(parser.parse("Exec { path => '/usr/bin:/usr/sbin' }"), '') + assert_equal("", parser.known_resource_types.hostclass("").name) + assert_equal("", parser.known_resource_types.hostclass("").namespace) end end @@ -482,22 +472,26 @@ file { "/tmp/yayness": ret = nil assert_nothing_raised do - ret = parser.parse("#{at}file { '/tmp/testing': owner => root }") + parser.known_resource_types.import_ast(parser.parse("#{at}file { '/tmp/testing': owner => root }"), '') + ret = parser.known_resource_types end assert_instance_of(AST::ASTArray, ret.hostclass("").code) resdef = ret.hostclass("").code[0] assert_instance_of(AST::Resource, resdef) - assert_equal("/tmp/testing", resdef.title.value) + assert_instance_of(AST::ASTArray, resdef.instances) + assert_equal(1, resdef.instances.children.length) + assert_equal("/tmp/testing", resdef.instances[0].title.value) # We always get an astarray back, so... check.call(resdef, "simple resource") # Now let's try it with multiple resources in the same spec assert_nothing_raised do - ret = parser.parse("#{at}file { ['/tmp/1', '/tmp/2']: owner => root }") + parser.known_resource_types.import_ast(parser.parse("#{at}file { ['/tmp/1', '/tmp/2']: owner => root }"), '') + ret = parser.known_resource_types end - ret.hostclass("").code.each do |res| + ret.hostclass("").code[0].each do |res| assert_instance_of(AST::Resource, res) check.call(res, "multiresource") end @@ -506,9 +500,9 @@ file { "/tmp/yayness": ensure if Puppet.features.rails? Puppet[:storeconfigs] = false - Puppet::Resource::Catalog.cache_class = catalog_cache_class - Puppet::Node::Facts.cache_class = facts_cache_class - Puppet::Node.cache_class = node_cache_class + Puppet::Resource::Catalog.indirection.cache_class = catalog_cache_class + Puppet::Node::Facts.indirection.cache_class = facts_cache_class + Puppet::Node.indirection.cache_class = node_cache_class end end @@ -537,7 +531,7 @@ file { "/tmp/yayness": ret = parser.parse("File #{arrow}") end - coll = ret.hostclass("").code[0] + coll = ret.code[0] assert_instance_of(AST::Collection, coll) assert_equal(form, coll.form) end @@ -545,9 +539,9 @@ file { "/tmp/yayness": ensure if Puppet.features.rails? Puppet[:storeconfigs] = false - Puppet::Resource::Catalog.cache_class = catalog_cache_class - Puppet::Node::Facts.cache_class = facts_cache_class - Puppet::Node.cache_class = node_cache_class + Puppet::Resource::Catalog.indirection.cache_class = catalog_cache_class + Puppet::Node::Facts.indirection.cache_class = facts_cache_class + Puppet::Node.indirection.cache_class = node_cache_class end end @@ -560,7 +554,7 @@ file { "/tmp/yayness": res = nil assert_nothing_raised do - res = parser.parse(str).hostclass("").code[0] + res = parser.parse(str).code[0] end assert_instance_of(AST::Collection, res) @@ -583,7 +577,7 @@ file { "/tmp/yayness": res = nil assert_nothing_raised do - res = parser.parse(str).hostclass("").code[0] + res = parser.parse(str).code[0] end assert_instance_of(AST::Collection, res) @@ -607,7 +601,7 @@ file { "/tmp/yayness": res = nil assert_nothing_raised("Could not parse '#{test}'") do - res = parser.parse(str).hostclass("").code[0] + res = parser.parse(str).code[0] end assert_instance_of(AST::Collection, res) @@ -624,15 +618,11 @@ file { "/tmp/yayness": def test_fully_qualified_definitions parser = mkparser + types = parser.known_resource_types assert_nothing_raised("Could not parse fully-qualified definition") { - parser.parse %{define one::two { }} + types.import_ast(parser.parse(%{define one::two { }}), '') } assert(parser.definition("one::two"), "Could not find one::two with no namespace") - - # Now try using the definition - assert_nothing_raised("Could not parse fully-qualified definition usage") { - parser.parse %{one::two { yayness: }} - } end # #524 @@ -691,7 +681,7 @@ file { "/tmp/yayness": result = parser.parse %{$variable = undef} } - main = result.hostclass("").code + main = result.code children = main.children assert_instance_of(AST::VarDef, main.children[0]) assert_instance_of(AST::Undef, main.children[0].value) @@ -704,7 +694,8 @@ file { "/tmp/yayness": str = "file { '/tmp/yay': ensure => file }\nclass yay {}\nnode foo {}\ndefine bar {}\n" result = nil assert_nothing_raised("Could not parse") do - result = parser.parse(str) + parser.known_resource_types.import_ast(parser.parse(str), '') + result = parser.known_resource_types end assert_instance_of(Puppet::Resource::TypeCollection, result, "Did not get a ASTSet back from parsing") @@ -734,12 +725,14 @@ file { "/tmp/yayness": result = nil assert_nothing_raised do - result = parser.newclass "Yayness" + parser.known_resource_types.import_ast(parser.parse("class yayness { }"), '') + result = parser.known_resource_types.hostclass('yayness') end assert_equal(result, parser.find_hostclass("", "yayNess")) assert_nothing_raised do - result = parser.newdefine "FunTest" + parser.known_resource_types.import_ast(parser.parse("define funtest { }"), '') + result = parser.known_resource_types.definition('funtest') end assert_equal(result, parser.find_definition("", "fUntEst"), "#{"fUntEst"} was not matched") end diff --git a/test/language/scope.rb b/test/language/scope.rb index cb5558aec..15c321166 100755 --- a/test/language/scope.rb +++ b/test/language/scope.rb @@ -163,7 +163,7 @@ class TestScope < Test::Unit::TestCase config = mkcompiler # Create a default source - parser.newclass("") + parser.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "") config.topscope.source = parser.known_resource_types.hostclass("") # And a scope resource @@ -175,12 +175,12 @@ class TestScope < Test::Unit::TestCase ) # Create a top-level define - parser.newdefine "one", :arguments => [%w{arg}], + parser.known_resource_types.add Puppet::Resource::Type.new(:definition, "one", :arguments => [%w{arg}], :code => AST::ASTArray.new( :children => [ resourcedef("file", "/tmp", {"owner" => varref("arg")}) ] - ) + )) # create a resource that calls our third define obj = resourcedef("one", "boo", {"arg" => "parentfoo"}) @@ -233,9 +233,9 @@ Host <<||>>" } ensure Puppet[:storeconfigs] = false - Puppet::Resource::Catalog.cache_class = catalog_cache_class - Puppet::Node::Facts.cache_class = facts_cache_class - Puppet::Node.cache_class = node_cache_class + Puppet::Resource::Catalog.indirection.cache_class = catalog_cache_class + Puppet::Node::Facts.indirection.cache_class = facts_cache_class + Puppet::Node.indirection.cache_class = node_cache_class end else $stderr.puts "No ActiveRecord -- skipping collection tests" diff --git a/test/language/snippets.rb b/test/language/snippets.rb index 51c5e23fe..e5b513a46 100755 --- a/test/language/snippets.rb +++ b/test/language/snippets.rb @@ -501,7 +501,7 @@ class TestSnippets < Test::Unit::TestCase catalog = nil assert_nothing_raised("Could not compile catalog") { - catalog = Puppet::Resource::Catalog.find(node) + catalog = Puppet::Resource::Catalog.indirection.find(node) } assert_nothing_raised("Could not convert catalog") { diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb index 0b3a89a72..a60092cf7 100755 --- a/test/lib/puppettest.rb +++ b/test/lib/puppettest.rb @@ -185,7 +185,7 @@ module PuppetTest #if rake? or ! Puppet[:debug] #if defined?($puppet_debug) or ! rake? Puppet[:color] = false if textmate? - Puppet::Util::Log.newdestination(@logs) + Puppet::Util::Log.newdestination(Puppet::Test::LogCollector.new(@logs)) if defined? $console Puppet.info @method_name Puppet::Util::Log.newdestination(:console) @@ -305,7 +305,7 @@ module PuppetTest def logstore @logs = [] - Puppet::Util::Log.newdestination(@logs) + Puppet::Util::Log.newdestination(Puppet::Test::LogCollector.new(@logs)) end end diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb index bd04c1ec5..411bad37a 100644 --- a/test/lib/puppettest/parsertesting.rb +++ b/test/lib/puppettest/parsertesting.rb @@ -94,16 +94,15 @@ module PuppetTest::ParserTesting def resourcedef(type, title, params) title = stringobj(title) unless title.is_a?(AST) + instance = AST::ResourceInstance.new(:title => title, :parameters => resourceparams(params)) assert_nothing_raised("Could not create #{type} #{title}") { return AST::Resource.new( :file => __FILE__, :line => __LINE__, - :title => title, :type => type, - - :parameters => resourceinst(params) + :instances => AST::ASTArray.new(:children => [instance]) ) } end @@ -122,9 +121,7 @@ module PuppetTest::ParserTesting :file => __FILE__, :line => __LINE__, :object => resourceref(type, title), - - :type => type, - :parameters => resourceinst(params) + :parameters => resourceparams(params) ) } end @@ -197,13 +194,13 @@ module PuppetTest::ParserTesting } end - def resourceinst(hash) + def resourceparams(hash) assert_nothing_raised("Could not create resource instance") { params = hash.collect { |param, value| resourceparam(param, value) } - return AST::ResourceInstance.new( + return AST::ASTArray.new( :file => tempfile, diff --git a/test/network/handler/master.rb b/test/network/handler/master.rb index 81869ac06..f4bad7037 100755 --- a/test/network/handler/master.rb +++ b/test/network/handler/master.rb @@ -13,7 +13,7 @@ class TestMaster < Test::Unit::TestCase @master = Puppet::Network::Handler.master.new(:Manifest => tempfile) @catalog = stub 'catalog', :extract => "" - Puppet::Resource::Catalog.stubs(:find).returns(@catalog) + Puppet::Resource::Catalog.indirection.stubs(:find).returns(@catalog) end def teardown @@ -32,15 +32,17 @@ class TestMaster < Test::Unit::TestCase def test_hostname_is_used_if_client_is_missing @master.expects(:decode_facts).returns("hostname" => "yay") - Puppet::Node::Facts.expects(:new).with { |name, facts| name == "yay" }.returns(stub('facts', :save => nil)) + facts = Puppet::Node::Facts.new("the_facts") + Puppet::Node::Facts.indirection.stubs(:save).with(facts) + Puppet::Node::Facts.expects(:new).with { |name, facts| name == "yay" }.returns(facts) @master.getconfig("facts") end def test_facts_are_saved - facts = mock('facts') + facts = Puppet::Node::Facts.new("the_facts") Puppet::Node::Facts.expects(:new).returns(facts) - facts.expects(:save) + Puppet::Node::Facts.indirection.expects(:save).with(facts) @master.stubs(:decode_facts) @@ -48,12 +50,13 @@ class TestMaster < Test::Unit::TestCase end def test_catalog_is_used_for_compiling - facts = stub('facts', :save => nil) + facts = Puppet::Node::Facts.new("the_facts") + Puppet::Node::Facts.indirection.stubs(:save).with(facts) Puppet::Node::Facts.stubs(:new).returns(facts) @master.stubs(:decode_facts) - Puppet::Resource::Catalog.expects(:find).with("foo.com").returns(@catalog) + Puppet::Resource::Catalog.indirection.expects(:find).with("foo.com").returns(@catalog) @master.getconfig("facts", "yaml", "foo.com") end @@ -61,14 +64,15 @@ end class TestMasterFormats < Test::Unit::TestCase def setup - @facts = stub('facts', :save => nil) + @facts = Puppet::Node::Facts.new("the_facts") Puppet::Node::Facts.stubs(:new).returns(@facts) + Puppet::Node::Facts.indirection.stubs(:save) @master = Puppet::Network::Handler.master.new(:Code => "") @master.stubs(:decode_facts) @catalog = stub 'catalog', :extract => "" - Puppet::Resource::Catalog.stubs(:find).returns(@catalog) + Puppet::Resource::Catalog.indirection.stubs(:find).returns(@catalog) end def test_marshal_can_be_used diff --git a/test/rails/railsparameter.rb b/test/rails/railsparameter.rb index 9f6fc1c1e..77ce33912 100755 --- a/test/rails/railsparameter.rb +++ b/test/rails/railsparameter.rb @@ -22,7 +22,7 @@ class TestRailsParameter < Test::Unit::TestCase # Now create a source parser = mkparser - source = parser.newclass "myclass" + source = parser.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "myclass") host = Puppet::Rails::Host.new(:name => "myhost") diff --git a/test/ral/providers/cron/crontab.rb b/test/ral/providers/cron/crontab.rb index 0c87a5bba..be2af1e16 100755 --- a/test/ral/providers/cron/crontab.rb +++ b/test/ral/providers/cron/crontab.rb @@ -97,7 +97,10 @@ class TestCronParsedProvider < Test::Unit::TestCase # Then do them all at once. records = [] text = "" - sample_records.each do |name, options| + # Sort sample_records so that the :empty entry does not come last + # (if it does, the test will fail because the empty last line will + # be ignored) + sample_records.sort { |a, b| a.first.to_s <=> b.first.to_s }.each do |name, options| records << options[:record] text += options[:text] + "\n" end diff --git a/test/ral/providers/host/parsed.rb b/test/ral/providers/host/parsed.rb index c2367d566..955edd5d3 100755 --- a/test/ral/providers/host/parsed.rb +++ b/test/ral/providers/host/parsed.rb @@ -67,7 +67,8 @@ class TestParsedHostProvider < Test::Unit::TestCase # Make sure we convert both directlys correctly using a simple host. def test_basic_isomorphism - hash = {:record_type => :parsed, :name => "myhost", :ip => "192.168.43.56", :host_aliases => %w{another host}} + hash = {:record_type => :parsed, :name => "myhost", :ip => "192.168.43.56", :host_aliases => %w{another host}, + :comment => ''} str = nil assert_nothing_raised do @@ -105,11 +106,13 @@ class TestParsedHostProvider < Test::Unit::TestCase [ {:record_type => :comment, :line => "# comment one"}, {:record_type => :blank, :line => ""}, - {:record_type => :parsed, :name => "myhost", :ip => "192.168.43.56", :host_aliases => %w{another host}}, + {:record_type => :parsed, :name => "myhost", :ip => "192.168.43.56", :host_aliases => %w{another host}, + :comment => ''}, {:record_type => :blank, :line => " "}, {:record_type => :comment, :line => "# another comment"}, - {:record_type => :parsed, :name => "anotherhost", :ip => "192.168.43.57", :host_aliases => []} + {:record_type => :parsed, :name => "anotherhost", :ip => "192.168.43.57", :host_aliases => [], + :comment => ''} ], instances) newtext = nil |