Sha256: 6e05e70317a85a1b7dccb39db00873cffcdaae14eb62c4f3d0c3273601ad8474

Contents?: true

Size: 1.9 KB

Versions: 5

Compression:

Stored size: 1.9 KB

Contents

require 'test_helper'
require 'net/dns/rr'

class RRTypesTest < Test::Unit::TestCase

  def setup
  end
    
  def test_default
    # Default type should be ANY => 255
    instance = Net::DNS::RR::Types.new(nil)
    assert_equal("1", instance.to_str)
    assert_equal("A", instance.to_s)
    
    # Let's change default behaviour
    Net::DNS::RR::Types.default = "A"
    instance = Net::DNS::RR::Types.new(nil)
    assert_equal("1", instance.to_str)
    assert_equal("A", instance.to_s)

    Net::DNS::RR::Types.default = "ANY"
    instance = Net::DNS::RR::Types.new(nil)
    assert_equal("255", instance.to_str)
    assert_equal("ANY", instance.to_s)
  end

  def test_types
    Net::DNS::RR::Types::TYPES.each do |key, num|
      instance_from_string = Net::DNS::RR::Types.new(key)
      instance_from_num = Net::DNS::RR::Types.new(num)
      assert_equal(key, instance_from_string.to_s)
      assert_equal(num.to_s, instance_from_string.to_str)
      assert_equal(key, instance_from_num.to_s)
      assert_equal(num.to_s, instance_from_num.to_str)
    end
    assert_raises(ArgumentError) do
      Net::DNS::RR::Types.new(Hash.new)
    end
  end

  def test_regexp
    pattern = Net::DNS::RR::Types.regexp
    assert_instance_of String, pattern
    Net::DNS::RR::Types::TYPES.each do |key, num|
      assert_match /\|?#{key}\|?/, pattern
    end
  end
  
  def test_valid?
    assert_equal(true,  Net::DNS::RR::Types.valid?("A"))
    assert_equal(true,  Net::DNS::RR::Types.valid?(1))
    assert_equal(false, Net::DNS::RR::Types.valid?("Q"))
    assert_equal(false, Net::DNS::RR::Types.valid?(256))
    assert_raises(ArgumentError) do
      Net::DNS::RR::Types.valid? Hash.new
    end
  end

  def test_to_str
    assert_equal("A", Net::DNS::RR::Types.to_str(1))
    assert_raises(ArgumentError) do
      Net::DNS::RR::Types.to_str(256)
    end
    assert_raises(ArgumentError) do
      Net::DNS::RR::Types.to_str("string")
    end
  end

end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
net-dns2-0.8.2 test/rr/types_test.rb
net-dns2-0.8.1 test/rr/types_test.rb
net-dns-0.8.0 test/rr/types_test.rb
net-dns-0.7.1 test/rr/types_test.rb
net-dns-0.7.0 test/rr/types_test.rb