diff options
| author | Luke Kanies <luke@madstop.com> | 2008-11-06 11:55:34 -0600 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-11-06 11:55:34 -0600 |
| commit | e92c1cc724c489d9328567dfa082221a67184c92 (patch) | |
| tree | 9ab1eeb6a0c49384550e8fd0ace1db3b2c0ae63d | |
| parent | 0149e2e125fc09bb5a8c1ff206cd46e06c0593cd (diff) | |
Moving Catalog#write_graph to SimpleGraph, where it belongs.
Signed-off-by: Luke Kanies <luke@madstop.com>
| -rw-r--r-- | lib/puppet/simple_graph.rb | 12 | ||||
| -rwxr-xr-x | spec/unit/simple_graph.rb | 25 |
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 |
