From ee60209b3ccf1f7a52058f18709d73db4d002369 Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Wed, 24 Apr 2013 16:26:02 +0200 Subject: [PATCH] checks: @perfdatas should user symbols as keys. +test --- lib/nsca/check.rb | 9 +++------ test/test_nsca.rb | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/nsca/check.rb b/lib/nsca/check.rb index 569d950..ef35c94 100644 --- a/lib/nsca/check.rb +++ b/lib/nsca/check.rb @@ -107,7 +107,7 @@ module NSCA end def push *perfdatas - perfdatas.each {|perfdata| @perfdatas[perfdata.label] = perfdata } + perfdatas.each {|perfdata| @perfdatas[perfdata.label.to_sym] = perfdata } @perfdatas end @@ -122,6 +122,7 @@ module NSCA def []= perfdata_label, value return push value if value.is_a? PerformanceData::Base + perfdata_label = perfdata_label.to_sym @perfdatas[perfdata_label] = perfdata_for( perfdata_label).new value end @@ -146,11 +147,7 @@ module NSCA def determine_return_code self.class.perfdatas.map do |label, pdc| pd = @perfdatas[label] - if pd - pd.return_code - else - -1 - end + pd ? pd.return_code : -1 end.max end diff --git a/test/test_nsca.rb b/test/test_nsca.rb index 18f987f..bc6c24a 100644 --- a/test/test_nsca.rb +++ b/test/test_nsca.rb @@ -227,4 +227,18 @@ class TestNSCA::Check < Test::Unit::TestCase assert_equal ce1_data, ce2_data end end + + context 'Perfdatas in Checks' do + should 'be saved as symbol-key' do + PH = NSCA::PerformanceData.new 'simplename', :ms + CH = NSCA::Check.new 'a check with perfdata', 'hostname', [PH] + assert_equal PH, CH.perfdatas[:'simplename'] + ch = CH.new + assert_equal nil, ch['simplename'] + assert_equal nil, ch[:simplename] + a = 0 + ch.measure( 'simplename') { 0.upto( 10000) { a += 1 } } + assert_equal ch['simplename'], ch[:simplename] + end + end end