summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-11-26 09:55:04 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-11-26 09:55:04 +0000
commitccd7b581bf990df618d410441c1f8d349aa225d9 (patch)
tree768e134483b5ed8f82adc69eebba7e8a7146b55e /test
parentc301b1b8f7fb417cf61b6ad4975eaa3714100306 (diff)
downloadpuppet-ccd7b581bf990df618d410441c1f8d349aa225d9.tar.gz
puppet-ccd7b581bf990df618d410441c1f8d349aa225d9.tar.xz
puppet-ccd7b581bf990df618d410441c1f8d349aa225d9.zip
Intermediate commit -- I am ready to start pushing the graph stuff into the types and transactions, which will break everything for a little while.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1894 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
-rwxr-xr-xtest/lib/puppettest.rb6
-rw-r--r--test/lib/puppettest/graph.rb40
-rw-r--r--test/other/pgraph.rb77
-rw-r--r--test/other/relationship.rb48
-rwxr-xr-xtest/other/transactions.rb2
-rwxr-xr-xtest/types/component.rb49
-rwxr-xr-xtest/util/graph.rb34
7 files changed, 224 insertions, 32 deletions
diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb
index 05d59a3a7..6e3d8cd4c 100755
--- a/test/lib/puppettest.rb
+++ b/test/lib/puppettest.rb
@@ -11,9 +11,11 @@ module PuppetTest
# the parent of that dir.
def basedir(*list)
unless defined? @@basedir
- case $0
- when /rake_test_loader/
+ case
+ when $0 =~ /rake_test_loader/
@@basedir = File.dirname(Dir.getwd)
+ when ENV['BASEDIR']
+ @@basedir = ENV['BASEDIR']
else
dir = nil
app = $0.sub /^\.\//, ""
diff --git a/test/lib/puppettest/graph.rb b/test/lib/puppettest/graph.rb
new file mode 100644
index 000000000..a6d0069cc
--- /dev/null
+++ b/test/lib/puppettest/graph.rb
@@ -0,0 +1,40 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke A. Kanies on 2006-11-24.
+# Copyright (c) 2006. All rights reserved.
+
+require 'puppet/util/graph'
+
+class Container
+ include Puppet::Util::Graph
+ include Enumerable
+ attr_accessor :name
+ def each
+ @children.each do |c| yield c end
+ end
+
+ def initialize(name, ary)
+ @name = name
+ @children = ary
+ end
+
+ def push(*ary)
+ ary.each { |c| @children.push(c)}
+ end
+
+ def to_s
+ @name
+ end
+end
+
+module PuppetTest::Graph
+ def build_tree
+ one = Container.new("one", %w{a b})
+ two = Container.new("two", ["c", "d"])
+ middle = Container.new("middle", ["e", "f", two])
+ top = Container.new("top", ["g", "h", middle, one])
+ return one, two, middle, top
+ end
+end
+
+# $Id$ \ No newline at end of file
diff --git a/test/other/pgraph.rb b/test/other/pgraph.rb
new file mode 100644
index 000000000..c3baa7722
--- /dev/null
+++ b/test/other/pgraph.rb
@@ -0,0 +1,77 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2006-11-16.
+# Copyright (c) 2006. All rights reserved.
+
+$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
+
+require 'puppettest'
+require 'puppettest/graph'
+
+class TestPGraph < Test::Unit::TestCase
+ include PuppetTest
+ include PuppetTest::Graph
+
+ def test_collect_targets
+ graph = Puppet::PGraph.new
+
+ event = Puppet::Event.new(:source => "a", :event => :yay)
+ none = Puppet::Event.new(:source => "a", :event => :NONE)
+
+ graph.add_edge!("a", "b", :event => :yay)
+
+ # Try it for the trivial case of one target and a matching event
+ assert_equal(["b"], graph.collect_targets([event]))
+
+ # Make sure we get nothing with a different event
+ assert_equal([], graph.collect_targets([none]))
+
+ # Set up multiple targets and make sure we get them all back
+ graph.add_edge!("a", "c", :event => :yay)
+ assert_equal(["b", "c"].sort, graph.collect_targets([event]).sort)
+ assert_equal([], graph.collect_targets([none]))
+ end
+
+ def test_dependencies
+ graph = Puppet::PGraph.new
+
+ graph.add_edge!("a", "b")
+ graph.add_edge!("a", "c")
+ graph.add_edge!("b", "d")
+
+ assert_equal(%w{b c d}.sort, graph.dependencies("a").sort)
+ assert_equal(%w{d}.sort, graph.dependencies("b").sort)
+ assert_equal([].sort, graph.dependencies("c").sort)
+ end
+
+ # Test that we can take a containment graph and rearrange it by dependencies
+ def test_splice
+ one, two, middle, top = build_tree
+ contgraph = top.to_graph
+
+ # Now make a dependency graph
+ deps = Puppet::PGraph.new
+
+ contgraph.vertices.each do |v|
+ deps.add_vertex(v)
+ end
+
+ {one => two, "f" => "c", "h" => middle}.each do |source, target|
+ deps.add_edge!(source, target)
+ end
+
+ deps.to_jpg("deps-before")
+
+ deps.splice!(contgraph, Container)
+
+ assert(! deps.cyclic?, "Created a cyclic graph")
+
+ nons = deps.vertices.find_all { |v| ! v.is_a?(String) }
+ assert(nons.empty?,
+ "still contain non-strings %s" % nons.inspect)
+
+ deps.to_jpg("deps-after")
+ end
+end
+
+# $Id$ \ No newline at end of file
diff --git a/test/other/relationship.rb b/test/other/relationship.rb
new file mode 100644
index 000000000..c6f8eb763
--- /dev/null
+++ b/test/other/relationship.rb
@@ -0,0 +1,48 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke A. Kanies on 2006-11-24.
+# Copyright (c) 2006. All rights reserved.
+
+$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
+
+require 'puppettest'
+require 'puppet/relationship'
+
+class TestRelationship < Test::Unit::TestCase
+ include PuppetTest
+
+ def test_initialize
+ rel = Puppet::Relationship
+
+ [["source", "target", "label"],
+ ["source", "target", {:event => :nothing}]
+ ].each do |ary|
+ # Make sure the label is required
+ assert_raise(Puppet::DevError) do
+ rel.new(*ary)
+ end
+ end
+ end
+
+ def test_attributes
+ rel = Puppet::Relationship
+
+ i = nil
+ assert_nothing_raised do
+ i = rel.new "source", "target", :event => :yay, :callback => :boo
+ end
+
+ assert_equal(:yay, i.event, "event was not retrieved")
+ assert_equal(:boo, i.callback, "callback was not retrieved")
+
+ # Now try it with nil values
+ assert_nothing_raised("failed to create with no event or callback") {
+ i = rel.new "source", "target"
+ }
+
+ assert_nil(i.event, "event was not nil")
+ assert_nil(i.callback, "callback was not nil")
+ end
+end
+
+# $Id$ \ No newline at end of file
diff --git a/test/other/transactions.rb b/test/other/transactions.rb
index ee4b901cb..985e9a0c5 100755
--- a/test/other/transactions.rb
+++ b/test/other/transactions.rb
@@ -461,3 +461,5 @@ class TestTransactions < Test::Unit::TestCase
end
end
end
+
+# $Id$ \ No newline at end of file
diff --git a/test/types/component.rb b/test/types/component.rb
index 78f184eed..28d6748a0 100755
--- a/test/types/component.rb
+++ b/test/types/component.rb
@@ -12,6 +12,8 @@ class TestComponent < Test::Unit::TestCase
def setup
super
@@used = {}
+ @type = Puppet::Type::Component
+ @file = Puppet::Type.type(:file)
end
def randnum(limit)
@@ -103,6 +105,53 @@ class TestComponent < Test::Unit::TestCase
}
}
end
+
+ def treefile(name)
+ @file.create :path => "/tmp/#{name}", :mode => 0755
+ end
+
+ def treecomp(name)
+ @type.create :name => name, :type => "yay"
+ end
+
+ def treenode(name, *children)
+ comp = treecomp name
+ children.each do |c|
+ if c.is_a?(String)
+ comp.push treefile(c)
+ else
+ comp.push c
+ end
+ end
+ return comp
+ end
+
+ def mktree
+ one = treenode("one", "a", "b")
+ two = treenode("two", "c", "d")
+ middle = treenode("middle", "e", "f", two)
+ top = treenode("top", "g", "h", middle, one)
+
+ return one, two, middle, top
+ end
+
+ def test_to_graph
+ one, two, middle, top = mktree
+
+ graph = nil
+ assert_nothing_raised do
+ graph = top.to_graph
+ end
+
+ assert(graph.is_a?(Puppet::PGraph), "result is not a pgraph")
+
+ [one, two, middle, top].each do |comp|
+ comp.each do |child|
+ assert(graph.edge?(comp, child),
+ "Did not create edge from %s => %s" % [comp.name, child.name])
+ end
+ end
+ end
def test_correctsorting
tmpfile = tempfile()
diff --git a/test/util/graph.rb b/test/util/graph.rb
index 0a331f0e9..1df294c77 100755
--- a/test/util/graph.rb
+++ b/test/util/graph.rb
@@ -6,32 +6,12 @@
$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
require 'puppettest'
+require 'puppettest/graph'
require 'puppet/util/graph'
class TestUtilGraph < Test::Unit::TestCase
include PuppetTest
-
- class Container
- include Puppet::Util::Graph
- include Enumerable
- attr_accessor :name
- def each
- @children.each do |c| yield c end
- end
-
- def initialize(name, ary)
- @name = name
- @children = ary
- end
-
- def push(*ary)
- ary.each { |c| @children.push(c)}
- end
-
- def to_s
- @name
- end
- end
+ include PuppetTest::Graph
def test_to_graph
children = %w{a b c d}
@@ -54,13 +34,7 @@ class TestUtilGraph < Test::Unit::TestCase
end
def test_recursive_to_graph
- one = Container.new("one", %w{a b})
-
- two = Container.new("two", ["c", "d"])
-
- middle = Container.new("middle", ["e", "f", two])
-
- top = Container.new("top", ["g", "h", middle, one])
+ one, two, middle, top = build_tree
graph = nil
assert_nothing_raised do
@@ -77,7 +51,7 @@ class TestUtilGraph < Test::Unit::TestCase
end
end
- top.to_jpg(graph)
+ graph.to_jpg("graph")
# Now make sure we correctly retrieve the leaves from each container
{top => %w{a b c d e f g h},