summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/simple_graph.rb12
-rwxr-xr-xspec/unit/simple_graph.rb25
2 files changed, 37 insertions, 0 deletions
diff --git a/lib/puppet/simple_graph.rb b/lib/puppet/simple_graph.rb
index 48f393f77..c926258ca 100644
--- a/lib/puppet/simple_graph.rb
+++ b/lib/puppet/simple_graph.rb
@@ -315,4 +315,16 @@ class Puppet::SimpleGraph
system( "dot -T#{fmt} #{src} -o #{dot}" )
dot
end
+
+ # Produce the graph files if requested.
+ def write_graph(name)
+ return unless Puppet[:graph]
+
+ Puppet.settings.use(:graphing)
+
+ file = File.join(Puppet[:graphdir], "%s.dot" % name.to_s)
+ File.open(file, "w") { |f|
+ f.puts to_dot("name" => name.to_s.capitalize)
+ }
+ end
end
diff --git a/spec/unit/simple_graph.rb b/spec/unit/simple_graph.rb
index e1e42e40f..322a527f1 100755
--- a/spec/unit/simple_graph.rb
+++ b/spec/unit/simple_graph.rb
@@ -278,3 +278,28 @@ describe Puppet::SimpleGraph, " when sorting the graph" do
proc { @graph.topsort }.should_not raise_error
end
end
+
+describe Puppet::SimpleGraph, " when writing dot files" do
+ before do
+ @graph = Puppet::SimpleGraph.new
+ @name = :test
+ @file = File.join(Puppet[:graphdir], @name.to_s + ".dot")
+ end
+
+ it "should only write when graphing is enabled" do
+ File.expects(:open).with(@file).never
+ Puppet[:graph] = false
+ @graph.write_graph(@name)
+ end
+
+ it "should write a dot file based on the passed name" do
+ File.expects(:open).with(@file, "w").yields(stub("file", :puts => nil))
+ @graph.expects(:to_dot).with("name" => @name.to_s.capitalize)
+ Puppet[:graph] = true
+ @graph.write_graph(@name)
+ end
+
+ after do
+ Puppet.settings.clear
+ end
+end