ref: refs/heads/basesystem commit 373005514895fa44cbd2e8f7665423d301a4f462 Author: Bjoern Geuken <bgeuken@suse.de> Date: Mon Aug 31 10:03:29 2009 +0200 status module: fixed tests --- .../status/app/controllers/status_controller.rb | 3 +- .../test/functional/status_controller_test.rb | 61 ++++++++++-------- plugins/status/test/unit/status_test.rb | 67 +++++++++++--------- 3 files changed, 70 insertions(+), 61 deletions(-) diff --git a/plugins/status/app/controllers/status_controller.rb b/plugins/status/app/controllers/status_controller.rb index e5033c2..13db52d 100644 --- a/plugins/status/app/controllers/status_controller.rb +++ b/plugins/status/app/controllers/status_controller.rb @@ -73,7 +73,7 @@ class StatusController < ApplicationController # GET /status/1 # GET /status/1.xml def show - unless true #permission_check("org.opensuse.yast.system.status.read") + unless permission_check("org.opensuse.yast.system.status.read") render ErrorResult.error(403, 1, "no permission") and return else begin @@ -81,7 +81,6 @@ class StatusController < ApplicationController stop = params[:stop].blank? ? Time.now : Time.at(params[:stop].to_i) start = params[:start].blank? ? stop - 300 : Time.at(params[:start].to_i) @status.collect_data(start, stop, params[:data]) - puts @status.data.inspect rescue Exception => e render :text => e.to_s, :status => 400 # bad request end diff --git a/plugins/status/test/functional/status_controller_test.rb b/plugins/status/test/functional/status_controller_test.rb index 77ac519..e75c085 100644 --- a/plugins/status/test/functional/status_controller_test.rb +++ b/plugins/status/test/functional/status_controller_test.rb @@ -15,41 +15,46 @@ class StatusControllerTest < ActionController::TestCase 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"}} + {"1248092580"=>"4.3878571429e+01", + "1248092790"=>"4.0714285714e+00", + "1248092440"=>"4.0992857143e+01", + "1248093000"=>"1.5542857143e+01", + "1248092650"=>"9.7942857143e+01", + "1248092860"=>"2.4142857143e+00", + "1248092300"=>"4.0500000000e+00", + "1248092510"=>"3.4264285714e+01", + "1248093070"=>"2.7071428571e+00", + "1248092720"=>"2.9928571429e+00", + "1248092930"=>"2.8285714286e+00", + "1248092370"=>"2.1435714286e+01"}, + "rx"=> + {"1248092580"=>"7.7485714286e+01", + "1248093140"=>"invalid", + "1248092790"=>"2.2585714286e+01", + "1248092230"=>"invalid", + "1248092440"=>"5.7578571429e+01", + "1248093000"=>"3.1314285714e+01", + "1248092650"=>"1.1698571429e+02", + "1248092860"=>"2.4292857143e+01", + "1248092090"=>"invalid", + "1248092300"=>"2.4628571429e+01", + "1248092510"=>"4.9271428571e+01", + "1248093070"=>"2.3064285714e+01", + "1248092720"=>"2.3042857143e+01", + "1248092930"=>"2.5092857143e+01", + "1248092160"=>"invalid", + "1248092370"=>"4.7314285714e+01"}, + "starttime"=>"1248092090"} Status.any_instance.stubs(:fetch_metric).returns(expected_response) Status.stubs(:find).returns([Status.new, Status.new]) - + @controller = StatusController.new @request = ActionController::TestRequest.new # http://railsforum.com/viewtopic.php?id=1719 @request.session[:account_id] = 1 # defined in fixtures - end + end include PluginBasicTests @@ -61,7 +66,7 @@ class StatusControllerTest < ActionController::TestCase # nothing end - # FIXME + # FIXME def test_access_show_json # ActionView::MissingTemplate: Missing template status/show.erb in view path app/views:. end diff --git a/plugins/status/test/unit/status_test.rb b/plugins/status/test/unit/status_test.rb index 307d544..26c61dd 100644 --- a/plugins/status/test/unit/status_test.rb +++ b/plugins/status/test/unit/status_test.rb @@ -20,7 +20,7 @@ class StatusTest < ActiveSupport::TestCase def test_set_datapath_default Scr.instance.stubs(:execute).with(["/usr/sbin/collectd"]).returns(nil) - + IO.stubs(:popen).with("hostname").returns(String) #FIXME: replace String with IO IO.stubs(:popen).with("domainname").returns(String) # returns(IO.new(2, "r+")) dont work IO.stubs(:popen).with("ls /var/lib/collectd/").returns(String) # because of missing EOF token @@ -41,7 +41,7 @@ class StatusTest < ActiveSupport::TestCase status.stubs(:metric_types).returns(['cpu', 'memory']) 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/test/memory/memory.rrd"]}, "cpu"=>{:rrds=>["/var/lib/collectd/test/cpu/cpuheat.rrd"]}} @@ -56,7 +56,7 @@ class StatusTest < ActiveSupport::TestCase Scr.instance.stubs(:execute).with(["/usr/sbin/collectd"]).returns(nil) stop = Time.now start = Time.now - 300 - + status = Status.new rrd_output = <<EOF @@ -79,39 +79,44 @@ class StatusTest < ActiveSupport::TestCase 1248093070: 2.3064285714e+01 2.7071428571e+00 1248093140: nan nan EOF - + # stub the command output status.stubs(:run_rrdtool).with("/var/lib/collectd/test/memory-free.rrd", start, stop).returns(rrd_output) - + status.datapath = "/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"}, + {"1248092580"=>"4.3878571429e+01", + "1248092790"=>"4.0714285714e+00", + "1248092440"=>"4.0992857143e+01", + "1248093000"=>"1.5542857143e+01", + "1248092650"=>"9.7942857143e+01", + "1248092860"=>"2.4142857143e+00", + "1248092300"=>"4.0500000000e+00", + "1248092510"=>"3.4264285714e+01", + "1248093070"=>"2.7071428571e+00", + "1248092720"=>"2.9928571429e+00", + "1248092930"=>"2.8285714286e+00", + "1248092370"=>"2.1435714286e+01"}, "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"}} - - assert_equal expected_response, status.fetch_metric("/var/lib/collectd/test/memory-free.rrd", start, stop) + {"1248092580"=>"7.7485714286e+01", + "1248093140"=>"invalid", + "1248092790"=>"2.2585714286e+01", + "1248092230"=>"invalid", + "1248092440"=>"5.7578571429e+01", + "1248093000"=>"3.1314285714e+01", + "1248092650"=>"1.1698571429e+02", + "1248092860"=>"2.4292857143e+01", + "1248092090"=>"invalid", + "1248092300"=>"2.4628571429e+01", + "1248092510"=>"4.9271428571e+01", + "1248093070"=>"2.3064285714e+01", + "1248092720"=>"2.3042857143e+01", + "1248092930"=>"2.5092857143e+01", + "1248092160"=>"invalid", + "1248092370"=>"4.7314285714e+01"}, + "starttime"=>"1248092090"} + + 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