spec/arborist/monitor_spec.rb in arborist-0.0.1.pre20161005182540 vs spec/arborist/monitor_spec.rb in arborist-0.1.0
- old
+ new
@@ -30,89 +30,165 @@
'branch' => branch_node.to_h,
'leaf' => leaf_node.to_h
}}
- it "can be created with just a description" do
- mon = described_class.new( "the description" )
+ it "can be created with just a description and key" do
+ mon = described_class.new( "the description", :key )
expect( mon ).to be_a( described_class )
expect( mon.description ).to eq( "the description" )
+ expect( mon.key ).to eq( :key )
expect( mon.include_down? ).to be_falsey
expect( mon.interval ).to eq( Arborist::Monitor::DEFAULT_INTERVAL )
expect( mon.splay ).to eq( 0 )
expect( mon.positive_criteria ).to be_empty
expect( mon.negative_criteria ).to be_empty
expect( mon.node_properties ).to be_empty
end
+ it "can be created with just a description and key set in the block" do
+ mon = described_class.new do
+ description "the description"
+ key :key
+ end
+
+ expect( mon ).to be_a( described_class )
+ expect( mon.description ).to eq( "the description" )
+ expect( mon.key ).to eq( :key )
+ expect( mon.include_down? ).to be_falsey
+ expect( mon.interval ).to eq( Arborist::Monitor::DEFAULT_INTERVAL )
+ expect( mon.splay ).to eq( 0 )
+ expect( mon.positive_criteria ).to be_empty
+ expect( mon.negative_criteria ).to be_empty
+ expect( mon.node_properties ).to be_empty
+ end
+
+
+ it "can be created with description set in the constructor and key in the block" do
+ mon = described_class.new( "the description" ) do
+ key :key
+ end
+
+ expect( mon ).to be_a( described_class )
+ expect( mon.description ).to eq( "the description" )
+ expect( mon.key ).to eq( :key )
+ expect( mon.include_down? ).to be_falsey
+ expect( mon.interval ).to eq( Arborist::Monitor::DEFAULT_INTERVAL )
+ expect( mon.splay ).to eq( 0 )
+ expect( mon.positive_criteria ).to be_empty
+ expect( mon.negative_criteria ).to be_empty
+ expect( mon.node_properties ).to be_empty
+ end
+
+
+ it "can be created with a DSL function" do
+ mon = Arborist::Monitor( "the description", :the_key )
+
+ expect( mon ).to be_a( described_class )
+ expect( mon.description ).to eq( "the description" )
+ expect( mon.key ).to eq( :the_key )
+ expect( mon.include_down? ).to be_falsey
+ expect( mon.interval ).to eq( Arborist::Monitor::DEFAULT_INTERVAL )
+ expect( mon.splay ).to eq( 0 )
+ expect( mon.positive_criteria ).to be_empty
+ expect( mon.negative_criteria ).to be_empty
+ expect( mon.node_properties ).to be_empty
+ end
+
+
+ it "raises a ConfigError if constructed without a description" do
+ expect {
+ described_class.new do
+ key :key
+ end
+ }.to raise_error( Arborist::ConfigError, /no description/i )
+ end
+
+
+ it "raises a ConfigError if constructed without a key" do
+ expect {
+ described_class.new( "the description" )
+ }.to raise_error( Arborist::ConfigError, /no key/i )
+ end
+
+
it "yields itself to the provided block for the DSL" do
block_self = nil
- mon = described_class.new( "testing monitor" ) do
+ mon = described_class.new( "testing monitor", :testing ) do
block_self = self
end
expect( block_self ).to be( mon )
end
it "can specify an interval" do
- mon = described_class.new( "testing monitor" ) do
+ mon = described_class.new( "testing monitor", :testing ) do
every 30
end
expect( mon.interval ).to eq( 30 )
end
it "can specify a splay" do
- mon = described_class.new( "testing monitor" ) do
+ mon = described_class.new( "testing monitor", :testing ) do
splay 15
end
expect( mon.splay ).to eq( 15 )
end
it "can specify criteria for matching nodes to monitor" do
- mon = described_class.new( "testing monitor" ) do
+ mon = described_class.new( "testing monitor", :testing ) do
match type: 'host'
end
expect( mon.positive_criteria ).to include( type: 'host' )
end
it "can specify criteria for matching nodes not to monitor" do
- mon = described_class.new( "testing monitor" ) do
+ mon = described_class.new( "testing monitor", :testing ) do
exclude tag: 'laptop'
end
expect( mon.negative_criteria ).to include( tag: 'laptop' )
end
+ it "automatically includes 'down' nodes if the matcher specifies an unreachable state" do
+ mon = described_class.new( "testing monitor", :testing ) do
+ match status: 'down'
+ end
+
+ expect( mon.include_down? ).to be_truthy
+ end
+
+
it "can specify that it will include hosts marked as 'down'" do
- mon = described_class.new( "testing monitor" ) do
+ mon = described_class.new( "testing monitor", :testing ) do
include_down true
end
expect( mon.include_down? ).to be_truthy
end
it "can specify one or more properties to include in the input to the monitor" do
- mon = described_class.new( "testing monitor" ) do
+ mon = described_class.new( "testing monitor", :testing ) do
use :address, :tags
end
expect( mon.node_properties ).to include( :address, :tags )
end
it "can specify a command to exec to do the monitor's work" do
- mon = described_class.new( "the description" ) do
+ mon = described_class.new( "the description", :testing ) do
exec 'cat'
end
output = mon.run( testing_nodes )
expect( output ).to be_a( Hash )
@@ -121,11 +197,11 @@
it "can specify a block to call to do the monitor's work" do
block_was_run = false
- mon = described_class.new( "the description" )
+ mon = described_class.new( "the description", :testing )
mon.exec do |nodes|
block_was_run = true
end
mon.run( testing_nodes )
@@ -143,21 +219,21 @@
self.was_run = true
end
end
- mon = described_class.new( "the description" )
+ mon = described_class.new( "the description", :testing )
mon.exec( mod )
mon.run( testing_nodes )
expect( mod.was_run ).to be_truthy
end
it "can provide a function for building arguments for its command" do
- mon = described_class.new( "the description" ) do
+ mon = described_class.new( "the description", :testing ) do
exec 'the_command'
handle_results {|*| }
exec_input {|*| }
@@ -180,11 +256,11 @@
mon.run( testing_nodes )
end
it "handles system call errors while running the monitor command" do
- mon = described_class.new( "the description" ) do
+ mon = described_class.new( "the description", :testing ) do
exec 'the_command'
handle_results {|*| }
exec_input {|*| }
@@ -203,11 +279,11 @@
}.to_not raise_error
end
it "can provide a function for providing input to its command" do
- mon = described_class.new( "the description" ) do
+ mon = described_class.new( "the description", :testing ) do
exec 'cat'
exec_input do |nodes, writer|
writer.puts( nodes.keys )
@@ -222,11 +298,11 @@
expect( results ).to eq( testing_nodes.keys )
end
it "can provide a function for parsing its command's output" do
- mon = described_class.new( "the description" ) do
+ mon = described_class.new( "the description", :testing ) do
exec 'cat'
exec_arguments {|*| }
exec_input do |nodes, writer|
@@ -257,10 +333,10 @@
end
end
end
- mon = described_class.new( "the description" ) do
+ mon = described_class.new( "the description", :testing ) do
exec 'cat'
exec_callbacks( the_module )
end
results = mon.run( testing_nodes )