diff options
author | Saku Ytti <saku@ytti.fi> | 2018-06-03 15:03:36 +0300 |
---|---|---|
committer | Saku Ytti <saku@ytti.fi> | 2018-06-03 15:03:36 +0300 |
commit | 8d93ecc5230917861d7a5d3495e049f3ddc10161 (patch) | |
tree | 19995764c1dc47c4d8d27784f95db86519ae24cd | |
parent | 2ed6e9165d1b9806996ad70f4ee1fa58c91a8e72 (diff) |
fix tests
-rw-r--r-- | lib/oxidized/node/stats.rb | 12 | ||||
-rw-r--r-- | spec/node_spec.rb | 8 |
2 files changed, 16 insertions, 4 deletions
diff --git a/lib/oxidized/node/stats.rb b/lib/oxidized/node/stats.rb index e37e07a..c20a91a 100644 --- a/lib/oxidized/node/stats.rb +++ b/lib/oxidized/node/stats.rb @@ -23,6 +23,18 @@ module Oxidized status ? @stats[status] : @stats end + def get_counter counter=nil + counter ? @stats[:counter][counter] : @stats[:counter] + end + + def successes + @stats[:counter][:success] + end + + def failures + @stats[:counter].reduce(0) { |m,h| h[0] == :success ? m : m+h[1] } + end + private def initialize diff --git a/spec/node_spec.rb b/spec/node_spec.rb index ba5b515..c7d28af 100644 --- a/spec/node_spec.rb +++ b/spec/node_spec.rb @@ -44,22 +44,22 @@ describe Oxidized::Node do it 'should record the success' do stub_oxidized_ssh - before_successes = @node.stats.get(:success_count) + before_successes = @node.stats.successes j = Oxidized::Job.new @node j.join @node.stats.add j - after_successes = @node.stats.get(:success_count) + after_successes = @node.stats.successes successes = after_successes - before_successes successes.must_equal 1 end it 'should record a failure' do stub_oxidized_ssh_fail - before_fails = @node.stats.get(:failure_count) + before_fails = @node.stats.failures j = Oxidized::Job.new @node j.join @node.stats.add j - after_fails = @node.stats.get(:failure_count) + after_fails = @node.stats.failures fails = after_fails - before_fails fails.must_equal 1 end |