ref: refs/heads/master
commit d0f34830463e535c55247b6e3cc84dade3f16874
Author: Duncan Mac-Vicar P
Date: Thu Aug 13 10:42:43 2009 +0200
fix tests
---
plugins/status/lib/status.rb | 2 +-
.../test/functional/status_controller_test.rb | 31 ++++++++++++++++++++
plugins/status/test/unit/status_test.rb | 13 ++++----
3 files changed, 39 insertions(+), 7 deletions(-)
diff --git a/plugins/status/lib/status.rb b/plugins/status/lib/status.rb
index ee8f3ce..321b129 100644
--- a/plugins/status/lib/status.rb
+++ b/plugins/status/lib/status.rb
@@ -175,7 +175,7 @@ class Status
end
#setting the limits
- result.each do |key, value|
+ result.each do |key, value|
path = rrdfile[datapath.length+1..rrdfile.length-1].chomp('.rrd')
path +="/" + key if key!="value" #do not take care about the value flag
path = path.tr('-','_')
diff --git a/plugins/status/test/functional/status_controller_test.rb b/plugins/status/test/functional/status_controller_test.rb
index cc45c3e..77ac519 100644
--- a/plugins/status/test/functional/status_controller_test.rb
+++ b/plugins/status/test/functional/status_controller_test.rb
@@ -12,6 +12,37 @@ class StatusControllerTest < ActionController::TestCase
@model_class = Status
Status.any_instance.stubs(:check_collectd).returns(true)
+ Status.any_instance.stubs(:datapath).returns("/var/lib/collectd/test")
+
+ expected_response = {"tx"=>
+ {"T_1248093000"=>"1.5542857143e+01",
+ "T_1248092930"=>"2.8285714286e+00",
+ "T_1248092370"=>"2.1435714286e+01",
+ "T_1248092580"=>"4.3878571429e+01",
+ "T_1248092790"=>"4.0714285714e+00",
+ "T_1248093070"=>"2.7071428571e+00",
+ "T_1248092440"=>"4.0992857143e+01",
+ "T_1248092650"=>"9.7942857143e+01",
+ "T_1248092860"=>"2.4142857143e+00",
+ "T_1248092300"=>"4.0500000000e+00",
+ "T_1248092510"=>"3.4264285714e+01",
+ "T_1248092720"=>"2.9928571429e+00"},
+ "rx"=>
+ {"T_1248093000"=>"3.1314285714e+01",
+ "T_1248092930"=>"2.5092857143e+01",
+ "T_1248092370"=>"4.7314285714e+01",
+ "T_1248092580"=>"7.7485714286e+01",
+ "T_1248092790"=>"2.2585714286e+01",
+ "T_1248093070"=>"2.3064285714e+01",
+ "T_1248092440"=>"5.7578571429e+01",
+ "T_1248092650"=>"1.1698571429e+02",
+ "T_1248092860"=>"2.4292857143e+01",
+ "T_1248092300"=>"2.4628571429e+01",
+ "T_1248092510"=>"4.9271428571e+01",
+ "T_1248092720"=>"2.3042857143e+01"}}
+
+ Status.any_instance.stubs(:fetch_metric).returns(expected_response)
+
Status.stubs(:find).returns([Status.new, Status.new])
@controller = StatusController.new
diff --git a/plugins/status/test/unit/status_test.rb b/plugins/status/test/unit/status_test.rb
index 98c134c..307d544 100644
--- a/plugins/status/test/unit/status_test.rb
+++ b/plugins/status/test/unit/status_test.rb
@@ -8,6 +8,7 @@ class StatusTest < ActiveSupport::TestCase
def setup
# http://railsforum.com/viewtopic.php?id=1719
Scr.instance.stubs(:execute).with(['/usr/sbin/rccollectd', 'status']).returns({:exit => 0})
+ Status.any_instance.stubs(:datapath).returns("/var/lib/collectd/test")
end
def test_set_datapath
@@ -38,12 +39,12 @@ class StatusTest < ActiveSupport::TestCase
# simulate environment
status.stubs(:metric_types).returns(['cpu', 'memory'])
- status.stubs(:metric_files).with('cpu').returns(['/var/lib/collectd/cpu/cpuheat.rrd'])
- status.stubs(:metric_files).with('memory').returns(['/var/lib/collectd/memory/memory.rrd'])
+ status.stubs(:metric_files).with('cpu').returns(['/var/lib/collectd/test/cpu/cpuheat.rrd'])
+ status.stubs(:metric_files).with('memory').returns(['/var/lib/collectd/test/memory/memory.rrd'])
status.datapath = "/var/lib/collectd"
- fake_metrics = {"memory"=>{:rrds=>["/var/lib/collectd/memory/memory.rrd"]},
- "cpu"=>{:rrds=>["/var/lib/collectd/cpu/cpuheat.rrd"]}}
+ fake_metrics = {"memory"=>{:rrds=>["/var/lib/collectd/test/memory/memory.rrd"]},
+ "cpu"=>{:rrds=>["/var/lib/collectd/test/cpu/cpuheat.rrd"]}}
assert_equal fake_metrics, status.available_metrics
end
@@ -80,7 +81,7 @@ class StatusTest < ActiveSupport::TestCase
EOF
# stub the command output
- status.stubs(:run_rrdtool).with("/test/memory-free.rrd", start, stop).returns(rrd_output)
+ status.stubs(:run_rrdtool).with("/var/lib/collectd/test/memory-free.rrd", start, stop).returns(rrd_output)
status.datapath = "/test"
@@ -111,6 +112,6 @@ EOF
"T_1248092510"=>"4.9271428571e+01",
"T_1248092720"=>"2.3042857143e+01"}}
- assert_equal expected_response, status.fetch_metric("/test/memory-free.rrd", start, stop)
+ assert_equal expected_response, status.fetch_metric("/var/lib/collectd/test/memory-free.rrd", start, stop)
end
end
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org