Mailinglist Archive: yast-commit (1914 mails)

< Previous Next >
[yast-commit] <rest-service> basesystem : tests for interfaces
  • From: Michal Zugec <mzugec@xxxxxxx>
  • Date: Fri, 4 Sep 2009 10:33:09 +0200
  • Message-id: <E1Mlezz-0004Bc-Ls@xxxxxxxxxxxxxxxx>
ref: refs/heads/basesystem
commit bc186c4f6d652ac5996716b41fd279ed1c2ba84d
Author: Michal Zugec <mzugec@xxxxxxx>
Date: Fri Sep 4 10:33:09 2009 +0200

tests for interfaces
---
.../test/functional/interfaces_controller_test.rb | 38 ++++++++++++++++++++
plugins/network/test/unit/interface_test.rb | 30 +++++++++++++++
2 files changed, 68 insertions(+), 0 deletions(-)

diff --git a/plugins/network/test/functional/interfaces_controller_test.rb
b/plugins/network/test/functional/interfaces_controller_test.rb
new file mode 100644
index 0000000..c2043cf
--- /dev/null
+++ b/plugins/network/test/functional/interfaces_controller_test.rb
@@ -0,0 +1,38 @@
+require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
+require 'test/unit'
+require 'interface'
+require 'rubygems'
+require 'mocha'
+require File.expand_path( File.join("test","plugin_basic_tests"),
RailsParent.parent )
+
+class InterfacesControllerTest < ActionController::TestCase
+
+ def setup
+ @model_class = Interface
+
Interface.stubs(:find).with('eth0').returns(Interface.new({"bootproto"=>"dhcp"}))
+
Interface.stubs(:find).with('eth1').returns(Interface.new({"bootproto"=>"static",
"ipaddr"=>"1.2.3.4/24"}))
+ @controller = Network::InterfacesController.new
+ @request = ActionController::TestRequest.new
+ # http://railsforum.com/viewtopic.php?id=1719
+ @request.session[:account_id] = 1 # defined in fixtures
+ end
+
+ def test_content1_of_xml
+ get :show, :format => 'xml', :id => 'eth0'
+ h=Hash.from_xml @response.body
+ assert_equal 'dhcp', h['interface']['bootproto']
+ assert_nil h['interface']['ipaddr']
+ end
+
+ def test_content2_of_xml
+ get :show, :format => 'xml', :id => 'eth1'
+ h=Hash.from_xml @response.body
+ assert_equal 'static', h['interface']['bootproto']
+ assert_equal '1.2.3.4/24', h['interface']['ipaddr']
+ end
+
+# some cases fail because PluginBasicTests expects a singular controller (same
as routing test)
+# include PluginBasicTests
+
+end
+
diff --git a/plugins/network/test/unit/interface_test.rb
b/plugins/network/test/unit/interface_test.rb
new file mode 100644
index 0000000..6aed700
--- /dev/null
+++ b/plugins/network/test/unit/interface_test.rb
@@ -0,0 +1,30 @@
+require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
+
+class InterfaceTest < ActiveSupport::TestCase
+
+ RESPONSE_FULL = {
+ 'interfaces'=>{
+ 'eth0'=>{'bootproto'=>'dhcp'},
+ 'eth1'=>{'bootproto'=>'static',
'ipaddr'=>'1.2.3.4/24'}},
+ 'routes'=>{'default'=>{'via'=>'10.20.7.254'}},
+ 'dns'=>{'dnsservers'=>'10.20.0.15 10.20.0.8',
'dnsdomains'=>'suse.cz suse.de'},
+ 'hostname'=>{'name'=>'linux', 'domain'=>'suse.cz'}
+ }
+
+ def setup
+ YastService.stubs(:Call).with("YaPI::NETWORK::Read").returns(RESPONSE_FULL)
+ end
+
+ def test_getter1
+ iface=Interface.find('eth0')
+ assert_equal 'dhcp', iface.bootproto
+ end
+
+ def test_getter2
+ iface=Interface.find('eth1')
+ assert_equal 'static', iface.bootproto
+ assert_equal '1.2.3.4/24', iface.ipaddr
+ end
+
+end
+
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages