Sha256: 2f07244d1fd3a2bcad6b03a287b6c94a71f65e0e1b20570031a627a9aa2c8e4f

Contents?: true

Size: 1.95 KB

Versions: 2

Compression:

Stored size: 1.95 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_raise(Net::DNS::RR::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_raise(Net::DNS::RR::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_raise(Net::DNS::RR::ArgumentError) do
      Net::DNS::RR::Types.to_str(256)
    end
    assert_raise(Net::DNS::RR::ArgumentError) do
      Net::DNS::RR::Types.to_str("string")
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
net-dns-0.6.1 test/rr/types_test.rb
net-dns-0.6.0 test/rr/types_test.rb