From 901ae687eb75885c5b717b03f2d6667f5ed8ffb5 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 15 Aug 2007 16:32:06 -0500 Subject: Requiring mocha in all cases in the test tree --- test/lib/puppettest.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'test/lib') diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb index 8b85966f5..5c385afb1 100755 --- a/test/lib/puppettest.rb +++ b/test/lib/puppettest.rb @@ -4,6 +4,7 @@ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))) require 'puppet' +require 'mocha' require 'test/unit' # Yay; hackish but it works -- cgit From 6467c21e15b8a28e627d1395f76fe8f42ee77d70 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 20 Aug 2007 13:28:40 -0500 Subject: The first pass where at least all of the snippet tests pass. I have unfortunately had to stop being so assiduous in my rewriting of tests, but I am in too much of a time crunch to do this "right". The basic structure is definitely in place, though, and from here it is a question of making the rest of the tests work and hopefully writing some sufficient new tests, rather than making the code itself work. --- test/lib/puppettest/parsertesting.rb | 21 +++++++++++++--- test/lib/puppettest/resourcetesting.rb | 46 +++++++++++++--------------------- 2 files changed, 35 insertions(+), 32 deletions(-) (limited to 'test/lib') diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb index d66367ada..368e112f9 100644 --- a/test/lib/puppettest/parsertesting.rb +++ b/test/lib/puppettest/parsertesting.rb @@ -5,6 +5,8 @@ module PuppetTest::ParserTesting include PuppetTest AST = Puppet::Parser::AST + Config = Puppet::Parser::Configuration + # A fake class that we can use for testing evaluation. class FakeAST attr_writer :evaluate @@ -39,6 +41,19 @@ module PuppetTest::ParserTesting ) end + def mkconfig(parser = nil) + require 'puppet/network/handler/node' + parser ||= mkparser + node = mknode + return Config.new(parser, node) + end + + def mknode(name = nil) + name ||= "nodename" + Puppet::Network::Handler.handler(:node) + Puppet::Network::Handler::Node::SimpleNode.new("nodename") + end + def mkinterp(args = {}) args[:Code] ||= "" unless args.include?(:Manifest) args[:Local] ||= true @@ -50,9 +65,9 @@ module PuppetTest::ParserTesting end def mkscope(hash = {}) - hash[:interp] ||= mkinterp - hash[:source] ||= (hash[:interp].findclass("", "") || - hash[:interp].newclass("")) + hash[:configuration] ||= mkconfig + hash[:parser] ||= mkparser + hash[:source] ||= (hash[:parser].findclass("", "") || hash[:parser].newclass("")) unless hash[:source] raise "Could not find source for scope" diff --git a/test/lib/puppettest/resourcetesting.rb b/test/lib/puppettest/resourcetesting.rb index 8cb59b83d..cbcfb0baf 100644 --- a/test/lib/puppettest/resourcetesting.rb +++ b/test/lib/puppettest/resourcetesting.rb @@ -1,25 +1,25 @@ module PuppetTest::ResourceTesting Parser = Puppet::Parser AST = Puppet::Parser::AST - def mkclassframing(interp = nil) - interp ||= mkinterp + def mkclassframing(parser = nil) + parser ||= mkparser - interp.newdefine("resource", :arguments => [%w{one}, %w{two value}, %w{three}]) - interp.newclass("") - source = interp.newclass("base") - interp.newclass("sub1", :parent => "base") - interp.newclass("sub2", :parent => "base") - interp.newclass("other") + parser.newdefine("resource", :arguments => [%w{one}, %w{two value}, %w{three}]) + parser.newclass("") + source = parser.newclass("base") + parser.newclass("sub1", :parent => "base") + parser.newclass("sub2", :parent => "base") + parser.newclass("other") - scope = Parser::Scope.new(:interp => interp) - scope.source = source + config = mkconfig(:parser => parser) + config.topscope.source = source - return interp, scope, source + return parser, config.topscope, source end - def mkevaltest(interp = nil) - interp ||= mkinterp - @interp.newdefine("evaltest", + def mkevaltest(parser = nil) + parser ||= mkparser + @parser.newdefine("evaltest", :arguments => [%w{one}, ["two", stringobj("755")]], :code => resourcedef("file", "/tmp", "owner" => varref("one"), "mode" => varref("two")) @@ -27,26 +27,14 @@ module PuppetTest::ResourceTesting end def mkresource(args = {}) - - if args[:scope] and ! args[:source] - args[:source] = args[:scope].source - end - - unless args[:scope] - unless defined? @scope - raise "Must set @scope to mkresource" - end - end + args[:source] ||= "source" + args[:scope] ||= "scope" {:type => "resource", :title => "testing", - :source => @source, :scope => @scope}.each do |param, value| + :source => "source", :scope => "scope"}.each do |param, value| args[param] ||= value end - unless args[:source].is_a?(Puppet::Parser::AST::HostClass) - args[:source] = args[:scope].findclass(args[:source]) - end - params = args[:params] || {:one => "yay", :three => "rah"} if args[:params] == :none args.delete(:params) -- cgit From 2a4e1011dbc244754f434f7eb97f3d41463e5cd4 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 20 Aug 2007 19:09:26 -0500 Subject: All language tests now pass. I expect there are other failures elsewhere, but I want to commit this before delving into them. My method for fixing the tests was to do as little as possible, keeping the tests as bad or as good as they were before I started. Mostly this was about changing references to the interpreter into references to the parser (since that is where the new* methods are now for ast containers) and then dealing with the new config object and its relationship to scopes. --- test/lib/puppettest.rb | 1 + test/lib/puppettest/parsertesting.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'test/lib') diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb index 5c385afb1..b56bc563e 100755 --- a/test/lib/puppettest.rb +++ b/test/lib/puppettest.rb @@ -283,6 +283,7 @@ module PuppetTest rescue Timeout::Error # just move on end + mocha_verify if File.stat("/dev/null").mode & 007777 != 0666 File.open("/tmp/nullfailure", "w") { |f| f.puts self.class diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb index 368e112f9..0a695cbaa 100644 --- a/test/lib/puppettest/parsertesting.rb +++ b/test/lib/puppettest/parsertesting.rb @@ -45,7 +45,7 @@ module PuppetTest::ParserTesting require 'puppet/network/handler/node' parser ||= mkparser node = mknode - return Config.new(parser, node) + return Config.new(node, parser) end def mknode(name = nil) @@ -65,14 +65,14 @@ module PuppetTest::ParserTesting end def mkscope(hash = {}) - hash[:configuration] ||= mkconfig hash[:parser] ||= mkparser - hash[:source] ||= (hash[:parser].findclass("", "") || hash[:parser].newclass("")) + config ||= mkconfig(hash[:parser]) + config.topscope.source = (hash[:parser].findclass("", "") || hash[:parser].newclass("")) - unless hash[:source] + unless config.topscope.source raise "Could not find source for scope" end - Puppet::Parser::Scope.new(hash) + config.topscope end def classobj(name, hash = {}) @@ -308,7 +308,7 @@ module PuppetTest::ParserTesting config = nil assert_nothing_raised { - config = interp.run(Facter["hostname"].value, {}) + config = interp.compile(mknode) } comp = nil -- cgit From 4eb87ed7c8829a6fbc558595be9149e9b3cf5b36 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 20 Aug 2007 22:25:00 -0500 Subject: A round of bugfixing. Many more tests now pass -- I think we are largely down to tests that (yay!) fail in trunk. --- test/lib/puppettest/parsertesting.rb | 2 +- test/lib/puppettest/railstesting.rb | 8 +++----- test/lib/puppettest/resourcetesting.rb | 2 +- test/lib/spec/version.rb | 4 ++-- 4 files changed, 7 insertions(+), 9 deletions(-) (limited to 'test/lib') diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb index 0a695cbaa..3e2930728 100644 --- a/test/lib/puppettest/parsertesting.rb +++ b/test/lib/puppettest/parsertesting.rb @@ -51,7 +51,7 @@ module PuppetTest::ParserTesting def mknode(name = nil) name ||= "nodename" Puppet::Network::Handler.handler(:node) - Puppet::Network::Handler::Node::SimpleNode.new("nodename") + Puppet::Network::Handler::Node::SimpleNode.new(name) end def mkinterp(args = {}) diff --git a/test/lib/puppettest/railstesting.rb b/test/lib/puppettest/railstesting.rb index 8b5f074a2..403bdb756 100644 --- a/test/lib/puppettest/railstesting.rb +++ b/test/lib/puppettest/railstesting.rb @@ -40,12 +40,10 @@ module PuppetTest::RailsTesting # Now try storing our crap host = nil + node = mknode(facts["hostname"]) + node.parameters = facts assert_nothing_raised { - host = Puppet::Rails::Host.store( - :resources => resources, - :facts => facts, - :name => facts["hostname"] - ) + host = Puppet::Rails::Host.store(node, resources) } # Now save the whole thing diff --git a/test/lib/puppettest/resourcetesting.rb b/test/lib/puppettest/resourcetesting.rb index cbcfb0baf..e2176d5ef 100644 --- a/test/lib/puppettest/resourcetesting.rb +++ b/test/lib/puppettest/resourcetesting.rb @@ -28,7 +28,7 @@ module PuppetTest::ResourceTesting def mkresource(args = {}) args[:source] ||= "source" - args[:scope] ||= "scope" + args[:scope] ||= stub :tags => [] {:type => "resource", :title => "testing", :source => "source", :scope => "scope"}.each do |param, value| diff --git a/test/lib/spec/version.rb b/test/lib/spec/version.rb index 924d8458a..a0c0fdbbe 100644 --- a/test/lib/spec/version.rb +++ b/test/lib/spec/version.rb @@ -15,7 +15,7 @@ module Spec # RELEASE_CANDIDATE = "RC1" # RANDOM_TOKEN: 0.375509844656552 - REV = "$LastChangedRevision$".match(/LastChangedRevision: (\d+)/)[1] + REV = "LastChangedRevision: 2283".match(/LastChangedRevision: (\d+)/)[1] STRING = [MAJOR, MINOR, TINY].join('.') FULL_VERSION = "#{STRING} (r#{REV})" @@ -27,4 +27,4 @@ module Spec DESCRIPTION = "#{NAME}-#{FULL_VERSION} - BDD for Ruby\n#{URL}" end end -end \ No newline at end of file +end -- cgit