spec/arborist/node_spec.rb in arborist-0.0.1.pre20161005182540 vs spec/arborist/node_spec.rb in arborist-0.1.0

- old
+ new

@@ -154,11 +154,10 @@ node.add_child( child_node ) node.remove_child( child_node ) expect( node ).to_not have_children end - describe "status" do it "starts out in `unknown` status" do expect( node ).to be_unknown end @@ -175,29 +174,29 @@ expect( node ).to be_down end it "transitions from `down` to `acked` status if it's updated with an `ack` property" do node.status = 'down' - node.error = 'Something is wrong | he falls | betraying the trust | "\ + node.errors = 'Something is wrong | he falls | betraying the trust | "\ "there is a disaster in his life.' node.update( ack: {message: "Leitmotiv", sender: 'ged'} ) expect( node ).to be_acked end it "transitions from `acked` to `up` status if its error is cleared" do node.status = 'down' - node.error = 'Something is wrong | he falls | betraying the trust | "\ - "there is a disaster in his life.' + node.errors = { '_' => 'Something is wrong | he falls | betraying the trust | "\ + "there is a disaster in his life.' } node.update( ack: {message: "Leitmotiv", sender: 'ged'} ) node.update( error: nil ) expect( node ).to be_up end it "stays `up` if its error is cleared and stays cleared" do node.status = 'down' - node.error = 'stay up damn you!' + node.errors = { '_' => 'stay up damn you!' } node.update( ack: {message: "Leitmotiv", sender: 'ged'} ) node.update( error: nil ) node.update( error: nil ) expect( node ).to be_up @@ -243,10 +242,44 @@ expect( node ).to_not be_disabled expect( node ).to be_unknown expect( node.ack ).to be_nil end + it "knows if it's status deems it 'reachable'" do + node.update( error: nil ) + expect( node ).to be_reachable + expect( node ).to_not be_unreachable + end + + it "knows if it's status deems it 'unreachable'" do + node.update( error: 'ded' ) + expect( node ).to be_unreachable + expect( node ).to_not be_reachable + end + + it "groups errors from separate monitor by their key" do + expect( node ).to be_unknown + + node.update( _monitor_key: 'MonitorTron2000', error: 'ded' ) + node.update( _monitor_key: 'MonitorTron5000', error: 'moar ded' ) + expect( node ).to be_down + + expect( node.errors.length ).to eq( 2 ) + node.update( _monitor_key: 'MonitorTron5000' ) + + expect( node ).to be_down + expect( node.errors.length ).to eq( 1 ) + + node.update( _monitor_key: 'MonitorTron2000' ) + expect( node ).to be_up + end + + it "sets a default monitor key" do + node.update( error: 'ded' ) + expect( node ).to be_down + expect( node.errors ).to eq({ '_' => 'ded' }) + end end describe "Properties API" do @@ -378,11 +411,11 @@ it "can restore saved state from an older copy of the node" do old_node = Marshal.load( Marshal.dump(node) ) old_node.status = 'down' old_node.status_changed = Time.now - 400 - old_node.error = "Host unreachable" + old_node.errors = "Host unreachable" old_node.update( ack: { 'time' => Time.now - 200, 'message' => "Technician dispatched.", 'sender' => 'darby@example.com' @@ -398,11 +431,11 @@ node.restore( old_node ) expect( node.status ).to eq( old_node.status ) expect( node.status_changed ).to eq( old_node.status_changed ) - expect( node.error ).to eq( old_node.error ) + expect( node.errors ).to eq( old_node.errors ) expect( node.ack ).to eq( old_node.ack ) expect( node.properties ).to include( old_node.properties ) expect( node.last_contacted ).to eq( old_node.last_contacted ) expect( node.dependencies ).to eql( old_node.dependencies ) end @@ -453,11 +486,11 @@ expect( result ).to be_a( Hash ) expect( result ).to include( :identifier, :parent, :description, :tags, :properties, :ack, :status, - :last_contacted, :status_changed, :error, :quieted_reasons, + :last_contacted, :status_changed, :errors, :quieted_reasons, :dependencies ) expect( result[:identifier] ).to eq( 'foo' ) expect( result[:type] ).to eq( 'testnode' ) expect( result[:parent] ).to eq( 'bar' ) @@ -465,11 +498,12 @@ expect( result[:tags] ).to eq( node.tags ) expect( result[:properties] ).to eq( node.properties ) expect( result[:ack] ).to be_nil expect( result[:last_contacted] ).to eq( node.last_contacted.iso8601 ) expect( result[:status_changed] ).to eq( node.status_changed.iso8601 ) - expect( result[:error] ).to be_nil + expect( result[:errors] ).to be_a( Hash ) + expect( result[:errors] ).to be_empty expect( result[:dependencies] ).to be_a( Hash ) expect( result[:quieted_reasons] ).to be_a( Hash ) end @@ -685,9 +719,15 @@ it "can be matched with its type" do expect( node ).to match_criteria( type: 'testnode' ) expect( node ).to_not match_criteria( type: 'service' ) + end + + + it "can be matched with its parent" do + expect( node ).to match_criteria( parent: 'bar' ) + expect( node ).to_not match_criteria( parent: 'hooowat' ) end it "can be matched with a single tag" do expect( node ).to match_criteria( tag: 'hunky' )