Changeset 229

Show
Ignore:
Timestamp:
08/31/08 21:44:10 (4 months ago)
Author:
pwh
Message:
  • l2_interfaces_test.rb: Added address formatting and connector_present?
    tests.
  • l2_interfaces.yml: Added additional example interfaces.
  • l2_interface.rb: Allow the values '0' and '1' for connector_present, as
    well as 'false'/'true' and :false/:true.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nethorus/app/models/l2_interface.rb

    r175 r229  
    128128  def connector_present? 
    129129 
    130     if self.connector_present == "true" 
     130    if self.connector_present == "true" || self.connector_present == :true || self.connector_present == "1" 
    131131      return :true 
    132     elsif self.connector_present == "false" 
     132    elsif self.connector_present == "false" || self.connector_present == :false || self.connector_present == "0" 
    133133      return :false 
    134134    else 
  • nethorus/test/fixtures/l2_interfaces.yml

    r111 r229  
    11test_l2interface_1: 
    2   device_id:        1 
    3   ifindex:          1 
    4   address:          1234567890AB 
    5   ifdescr_short:    Short Description 
    6   ifdescr_long:     Long Description 
    7   iftype:           coffee 
    8   ifmtu:            576 
    9   ifspeed:          38400 
    10   created_at:       2008-01-01 00:00:00 
    11   updated_at:       2008-01-01 00:00:00 
     2  id:                1 
     3  device_id:         1 
     4  ifindex:           1 
     5  address:           1234567890AB 
     6  ifdescr_short:     Short Description 
     7  ifdescr_long:      Long Description 
     8  iftype:            coffee 
     9  ifmtu:             576 
     10  ifspeed:           38400 
     11  created_at:        2008-01-01 00:00:00 
     12  updated_at:        2008-01-01 00:00:00 
     13 
     14l2interface_with_connector_present: 
     15  id:                2 
     16  device_id:         1 
     17  ifindex:           2 
     18  address:           234567890ABC 
     19  ifdescr_short:     Short Description 
     20  ifdescr_long:      Long Description 
     21  iftype:            coffee 
     22  ifmtu:             576 
     23  ifspeed:           38400 
     24  connector_present: 1 
     25  created_at:        2008-01-01 00:00:00 
     26  updated_at:        2008-01-01 00:00:00 
     27 
     28l2interface_without_connector_present: 
     29  id:                3 
     30  device_id:         1 
     31  ifindex:           3 
     32  address:           34567890ABCD 
     33  ifdescr_short:     Short Description 
     34  ifdescr_long:      Long Description 
     35  iftype:            coffee 
     36  ifmtu:             576 
     37  ifspeed:           38400 
     38  connector_present: 0 
     39  created_at:        2008-01-01 00:00:00 
     40  updated_at:        2008-01-01 00:00:00 
     41 
     42l2interface_with_connector_present_unset: 
     43  id:                4 
     44  device_id:         1 
     45  ifindex:           4 
     46  address:           4567890ABCDE 
     47  ifdescr_short:     Short Description 
     48  ifdescr_long:      Long Description 
     49  iftype:            coffee 
     50  ifmtu:             576 
     51  ifspeed:           38400 
     52  created_at:        2008-01-01 00:00:00 
     53  updated_at:        2008-01-01 00:00:00 
     54 
     55l2_interface_without_any_l3_interfaces: 
     56  id:                5 
     57  device_id:         1 
     58  ifindex:           5 
     59  address:           567890ABCDEF 
     60  ifdescr_short:     Short Description 
     61  ifdescr_long:      Long Description 
     62  iftype:            coffee 
     63  ifmtu:             576 
     64  ifspeed:           38400 
     65  created_at:        2008-01-01 00:00:00 
     66  updated_at:        2008-01-01 00:00:00 
  • nethorus/test/unit/l2_interfaces_test.rb

    r125 r229  
    3030class L2InterfacesTest < ActiveSupport::TestCase 
    3131 
    32   fixtures :devices 
     32  fixtures :devices, :l2_interfaces 
    3333 
    3434 
     
    135135 
    136136 
     137  # Test that a simple colon-separated L2 address is correctly reformatted 
     138  # where some octets do not start with 0 
     139   
     140  def test_l2interface_address_formatting_simple_colon 
     141 
     142    l2interface = @device.l2_interfaces.new 
     143    l2interface.address = "A1:2:C3:4:E5:6" 
     144    l2interface.valid? 
     145     
     146    assert(l2interface.address == "A102C304E506", "A supplied address of A1:2:C3:4:E5:6 should be reformatted as A102C304E506") 
     147 
     148  end 
     149 
     150 
    137151  # Test that l2_addresses are invalid if they are not composed of exactly 
    138152  # 12 hexadecimal digits 
     
    200214  end 
    201215 
     216 
     217  # Test the connector_present? method 
     218   
     219  def test_connector_present 
     220   
     221    l2interface_with_connector_present = l2_interfaces(:l2interface_with_connector_present) 
     222    assert(l2interface_with_connector_present.connector_present? == :true) 
     223 
     224    l2interface_without_connector_present = l2_interfaces(:l2interface_without_connector_present) 
     225    assert(l2interface_without_connector_present.connector_present? == :false) 
     226 
     227    l2interface_without_connector_present = l2_interfaces(:l2interface_with_connector_present_unset) 
     228    assert(l2interface_without_connector_present.connector_present? == nil) 
     229   
     230  end 
     231 
    202232end