diff options
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/unit/other/pgraph.rb | 36 | ||||
-rwxr-xr-x | spec/unit/parser/compile.rb | 15 | ||||
-rwxr-xr-x | spec/unit/ral/types/mount.rb | 2 | ||||
-rwxr-xr-x | spec/unit/ral/types/nagios.rb | 55 | ||||
-rwxr-xr-x | spec/unit/relationship.rb | 2 | ||||
-rwxr-xr-x | spec/unit/simple_graph.rb | 40 | ||||
-rwxr-xr-x | spec/unit/util/nagios_maker.rb | 128 |
7 files changed, 239 insertions, 39 deletions
diff --git a/spec/unit/other/pgraph.rb b/spec/unit/other/pgraph.rb index 41835ebc7..252a807ec 100755 --- a/spec/unit/other/pgraph.rb +++ b/spec/unit/other/pgraph.rb @@ -144,10 +144,6 @@ describe Puppet::PGraph, " when splicing the relationship graph" do splice end - it "should not create a cyclic graph" do - @depgraph.should_not be_cyclic - end - # This is the real heart of splicing -- replacing all containers in # our relationship and exploding their relationships so that each # relationship to a container gets copied to all of its children. @@ -211,35 +207,3 @@ describe Puppet::PGraph, " when splicing the relationship graph" do end end end - -describe Puppet::PGraph, " when sorting the graph" do - before do - @graph = Puppet::PGraph.new - end - - def add_edges(hash) - hash.each do |a,b| - @graph.add_edge!(a, b) - end - end - - it "should fail on two-vertex loops" do - add_edges :a => :b, :b => :a - proc { @graph.topsort }.should raise_error(Puppet::Error) - end - - it "should fail on multi-vertex loops" do - add_edges :a => :b, :b => :c, :c => :a - proc { @graph.topsort }.should raise_error(Puppet::Error) - end - - it "should fail when a larger tree contains a small cycle" do - add_edges :a => :b, :b => :a, :c => :a, :d => :c - proc { @graph.topsort }.should raise_error(Puppet::Error) - end - - it "should succeed on trees with no cycles" do - add_edges :a => :b, :b => :e, :c => :a, :d => :c - proc { @graph.topsort }.should_not raise_error - end -end diff --git a/spec/unit/parser/compile.rb b/spec/unit/parser/compile.rb index 2ae99b5fd..092bece0c 100755 --- a/spec/unit/parser/compile.rb +++ b/spec/unit/parser/compile.rb @@ -106,7 +106,7 @@ describe Puppet::Parser::Compile, " when evaluating found classes" do @class = stub 'class', :classname => "my::class" @scope.stubs(:findclass).with("myclass").returns(@class) - @resource = mock 'resource' + @resource = stub 'resource', :ref => 'Class[myclass]' end it "should create a resource for each found class" do @@ -156,6 +156,19 @@ describe Puppet::Parser::Compile, " when evaluating found classes" do @compile.evaluate_classes(%w{myclass}, @scope, false) end + it "should skip classes that have already been evaluated" do + @compile.catalog.stubs(:tag) + + @compile.expects(:class_scope).with(@class).returns("something") + + @compile.expects(:store_resource).never + + @resource.expects(:evaluate).never + + Puppet::Parser::Resource.expects(:new).never + @compile.evaluate_classes(%w{myclass}, @scope, false) + end + it "should return the list of found classes" do @compile.catalog.stubs(:tag) diff --git a/spec/unit/ral/types/mount.rb b/spec/unit/ral/types/mount.rb index 0c4b94177..7d01022b5 100755 --- a/spec/unit/ral/types/mount.rb +++ b/spec/unit/ral/types/mount.rb @@ -9,7 +9,7 @@ describe Puppet::Type::Mount do Puppet::Type::Mount.provider_feature(:refreshable).methods.should == [:remount] end - it "should have no default value" do + it "should have no default value for :ensure" do mount = Puppet::Type::Mount.create(:name => "yay") mount.should(:ensure).should be_nil end diff --git a/spec/unit/ral/types/nagios.rb b/spec/unit/ral/types/nagios.rb new file mode 100755 index 000000000..8aca7d401 --- /dev/null +++ b/spec/unit/ral/types/nagios.rb @@ -0,0 +1,55 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +require 'puppet/external/nagios' + +Nagios::Base.eachtype do |name, nagios_type| + puppet_type = Puppet::Type.type("nagios_" + name.to_s) + + describe puppet_type do + it "should be defined as a Puppet resource type" do + puppet_type.should_not be_nil + end + + it "should have documentation" do + puppet_type.instance_variable_get("@doc").should_not == "" + end + + it "should have %s as its namevar" % nagios_type.namevar do + puppet_type.namevar.should == nagios_type.namevar + end + + it "should have documentation for its %s parameter" % nagios_type.namevar do + puppet_type.attrclass(nagios_type.namevar).instance_variable_get("@doc").should_not be_nil + end + + it "should have an ensure property" do + puppet_type.should be_validproperty(:ensure) + end + + it "should have a target property" do + puppet_type.should be_validproperty(:target) + end + + it "should have documentation for its target property" do + puppet_type.attrclass(:target).instance_variable_get("@doc").should_not be_nil + end + + nagios_type.parameters.reject { |param| param == nagios_type.namevar or param.to_s =~ /^[0-9]/ }.each do |param| + it "should have a %s property" % param do + puppet_type.should be_validproperty(param) + end + + it "should have documentation for its %s property" % param do + puppet_type.attrclass(param).instance_variable_get("@doc").should_not be_nil + end + end + + nagios_type.parameters.find_all { |param| param.to_s =~ /^[0-9]/ }.each do |param| + it "should have not have a %s property" % param do + puppet_type.should_not be_validproperty(:param) + end + end + end +end diff --git a/spec/unit/relationship.rb b/spec/unit/relationship.rb index 5d90a9349..5f96cdf8c 100755 --- a/spec/unit/relationship.rb +++ b/spec/unit/relationship.rb @@ -24,7 +24,7 @@ describe Puppet::Relationship do end it "should provide a :ref method that describes the edge" do - @edge = Puppet::Relationship.new(stub("a", :ref => "a"), stub("b", :ref => "b")) + @edge = Puppet::Relationship.new("a", "b") @edge.ref.should == "a => b" end end diff --git a/spec/unit/simple_graph.rb b/spec/unit/simple_graph.rb index 88873663c..061a07458 100755 --- a/spec/unit/simple_graph.rb +++ b/spec/unit/simple_graph.rb @@ -219,6 +219,9 @@ describe Puppet::SimpleGraph, " when reversing graphs" do end it "should add all vertices to the reversed graph" do + @graph.add_edge!(:one, :two) + @graph.vertex?(:one).should be_true + @graph.vertex?(:two).should be_true end it "should retain labels on edges" do @@ -227,3 +230,40 @@ describe Puppet::SimpleGraph, " when reversing graphs" do edge.label.should == {:stuff => :awesome} end end + +describe Puppet::SimpleGraph, " when sorting the graph" do + before do + @graph = Puppet::SimpleGraph.new + end + + def add_edges(hash) + hash.each do |a,b| + @graph.add_edge!(a, b) + end + end + + it "should sort the graph topologically" do + add_edges :a => :b, :b => :c + @graph.topsort.should == [:a, :b, :c] + end + + it "should fail on two-vertex loops" do + add_edges :a => :b, :b => :a + proc { @graph.topsort }.should raise_error(Puppet::Error) + end + + it "should fail on multi-vertex loops" do + add_edges :a => :b, :b => :c, :c => :a + proc { @graph.topsort }.should raise_error(Puppet::Error) + end + + it "should fail when a larger tree contains a small cycle" do + add_edges :a => :b, :b => :a, :c => :a, :d => :c + proc { @graph.topsort }.should raise_error(Puppet::Error) + end + + it "should succeed on trees with no cycles" do + add_edges :a => :b, :b => :e, :c => :a, :d => :c + proc { @graph.topsort }.should_not raise_error + end +end diff --git a/spec/unit/util/nagios_maker.rb b/spec/unit/util/nagios_maker.rb new file mode 100755 index 000000000..b75439400 --- /dev/null +++ b/spec/unit/util/nagios_maker.rb @@ -0,0 +1,128 @@ +#!/usr/bin/env ruby +# +# Created by Luke Kanies on 2007-11-18. +# Copyright (c) 2007. All rights reserved. + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'puppet/util/nagios_maker' + +describe Puppet::Util::NagiosMaker do + before do + @module = Puppet::Util::NagiosMaker + + @nagtype = stub 'nagios type', :parameters => [], :namevar => :name + Nagios::Base.stubs(:type).with(:test).returns(@nagtype) + end + + it "should be able to create a new nagios type" do + @module.should respond_to(:create_nagios_type) + end + + it "should fail if it cannot find the named Naginator type" do + Nagios::Base.stubs(:type).returns(nil) + + lambda { @module.create_nagios_type(:no_such_type) }.should raise_error(Puppet::DevError) + end + + it "should create a new RAL type with the provided name prefixed with 'nagios_'" do + type = stub 'type', :newparam => nil, :newproperty => nil, :ensurable => nil, :provide => nil, :desc => nil + + Puppet::Type.expects(:newtype).with(:nagios_test).returns(type) + @module.create_nagios_type(:test) + end + + it "should mark the created type as ensurable" do + type = stub 'type', :newparam => nil, :newproperty => nil, :provide => nil, :desc => nil + + type.expects(:ensurable) + + Puppet::Type.expects(:newtype).with(:nagios_test).returns(type) + @module.create_nagios_type(:test) + end + + it "should create a namevar parameter for the nagios type's name parameter" do + type = stub 'type', :newproperty => nil, :ensurable => nil, :provide => nil, :desc => nil + + type.expects(:newparam).with(:name, :namevar => true) + + Puppet::Type.expects(:newtype).with(:nagios_test).returns(type) + @module.create_nagios_type(:test) + end + + it "should create a property for all non-namevar parameters" do + type = stub 'type', :newparam => nil, :ensurable => nil, :provide => nil, :desc => nil + + @nagtype.stubs(:parameters).returns([:one, :two]) + + type.expects(:newproperty).with(:one) + type.expects(:newproperty).with(:two) + type.expects(:newproperty).with(:target) + + Puppet::Type.expects(:newtype).with(:nagios_test).returns(type) + @module.create_nagios_type(:test) + end + + it "should skip parameters that start with integers" do + type = stub 'type', :newparam => nil, :ensurable => nil, :provide => nil, :desc => nil + + @nagtype.stubs(:parameters).returns(["2dcoords".to_sym, :other]) + + type.expects(:newproperty).with(:other) + type.expects(:newproperty).with(:target) + + Puppet::Type.expects(:newtype).with(:nagios_test).returns(type) + @module.create_nagios_type(:test) + end + + it "should deduplicate the parameter list" do + type = stub 'type', :newparam => nil, :ensurable => nil, :provide => nil, :desc => nil + + @nagtype.stubs(:parameters).returns([:one, :one]) + + type.expects(:newproperty).with(:one) + type.expects(:newproperty).with(:target) + + Puppet::Type.expects(:newtype).with(:nagios_test).returns(type) + @module.create_nagios_type(:test) + end + + it "should create a target property" do + type = stub 'type', :newparam => nil, :ensurable => nil, :provide => nil, :desc => nil + + type.expects(:newproperty).with(:target) + + Puppet::Type.expects(:newtype).with(:nagios_test).returns(type) + @module.create_nagios_type(:test) + end +end + +describe Puppet::Util::NagiosMaker, " when creating the naginator provider" do + before do + @module = Puppet::Util::NagiosMaker + + @nagtype = stub 'nagios type', :parameters => [], :namevar => :name + Nagios::Base.stubs(:type).with(:test).returns(@nagtype) + + @type = stub 'type', :newparam => nil, :ensurable => nil, :newproperty => nil, :desc => nil + Puppet::Type.stubs(:newtype).with(:nagios_test).returns(@type) + end + + it "should add a naginator provider" do + @type.expects(:provide).with { |name, options| name == :naginator } + + @module.create_nagios_type(:test) + end + + it "should set Puppet::Provider::Naginator as the parent class of the provider" do + @type.expects(:provide).with { |name, options| options[:parent] == Puppet::Provider::Naginator } + + @module.create_nagios_type(:test) + end + + it "should use /etc/nagios/$name.cfg as the default target" do + @type.expects(:provide).with { |name, options| options[:default_target] == "/etc/nagios/nagios_test.cfg" } + + @module.create_nagios_type(:test) + end +end |