root/test/record_test.rb @ e9c19af4
e9c19af4 | Ohad Levy | require 'test_helper'
|
|
eb305390 | Ohad Levy | require "proxy/dhcp"
|
|
class Proxy::DHCPRecordTest < Test::Unit::TestCase
|
|||
def setup
|
|||
@server = Proxy::DHCP::Server.new("testcase")
|
|||
@subnet = Proxy::DHCP::Subnet.new(@server,"192.168.0.0","255.255.255.0")
|
|||
@ip = "123.321.123.321"
|
|||
@mac = "aa:bb:CC:dd:ee:ff"
|
|||
681b123f | Ohad Levy | @record = Proxy::DHCP::Record.new(:subnet => @subnet, :ip => @ip, :mac => @mac)
|
|
eb305390 | Ohad Levy | end
|
|
def test_record_should_have_a_subnet
|
|||
assert_kind_of Proxy::DHCP::Subnet, @record.subnet
|
|||
end
|
|||
def test_should_return_a_record_kind
|
|||
assert_equal @record.kind, "record"
|
|||
end
|
|||
def test_should_convert_to_string
|
|||
ip = "1.1.1.1"
|
|||
mac = "aa:bb:cc:dd:ea:ff"
|
|||
681b123f | Ohad Levy | assert_equal Proxy::DHCP::Record.new(:subnet => @subnet, :ip => ip, :mac => mac).to_s, "#{ip} / #{mac}"
|
|
eb305390 | Ohad Levy | end
|
|
def test_should_have_a_logger
|
|||
assert_respond_to @record, :logger
|
|||
end
|
|||
def test_should_not_save_invalid_ip_addresses
|
|||
ip = "1..1.1"
|
|||
assert_raise Proxy::Validations::Error do
|
|||
681b123f | Ohad Levy | Proxy::DHCP::Record.new(:subnet => @subnet, :ip => ip, :mac => @mac)
|
|
eb305390 | Ohad Levy | end
|
|
end
|
|||
def test_mac_should_be_saved_lower_case
|
|||
mac = "AA:BB:CC:DD:EE:aF"
|
|||
ip = "192.168.0.12"
|
|||
681b123f | Ohad Levy | assert_equal Proxy::DHCP::Record.new(:subnet => @subnet, :ip => ip, :mac => mac).mac, mac.downcase
|
|
eb305390 | Ohad Levy | end
|
|
def test_should_not_save_invalid_mac
|
|||
mac = "XYZxxVVcc123"
|
|||
assert_raise Proxy::Validations::Error do
|
|||
681b123f | Ohad Levy | Proxy::DHCP::Record.new(:subnet => @subnet, :ip => @ip, :mac => mac)
|
|
eb305390 | Ohad Levy | end
|
|
end
|
|||
def test_should_not_save_invalid_subnets
|
|||
subnet = nil
|
|||
assert_raise Proxy::Validations::Error do
|
|||
681b123f | Ohad Levy | Proxy::DHCP::Record.new(:subnet => subnet, :ip => @ip, :mac => @mac)
|
|
eb305390 | Ohad Levy | end
|
|
end
|
|||
def test_options_should_be_a_hash
|
|||
assert_kind_of Hash, @record.options
|
|||
end
|
|||
end
|