File: ns_test.rb

package info (click to toggle)
ruby-net-dns 0.9.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 452 kB
  • sloc: ruby: 3,944; makefile: 6
file content (80 lines) | stat: -rw-r--r-- 2,474 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
require 'test_helper'
require 'net/dns/rr'

class RRNSTest < Minitest::Test
  def setup
    @rr_name    = "google.com."
    @rr_type    = "NS"
    @rr_cls     = "IN"
    @rr_ttl     = 10_800
    @rr_nsdname = "ns1.google.com."

    @rr_output  = "google.com.             10800   IN      NS      ns1.google.com."

    @rr         = Net::DNS::RR::NS.new(name: "google.com.", nsdname: "ns1.google.com.", ttl: @rr_ttl)
  end

  def test_initialize_from_hash
    @record = Net::DNS::RR::NS.new(name: "google.com.", nsdname: "ns1.google.com.")
    assert_equal @rr_output,  @record.inspect
    assert_equal @rr_name,    @record.name
    assert_equal @rr_type,    @record.type
    assert_equal @rr_cls,     @record.cls
    assert_equal @rr_ttl,     @record.ttl
    assert_equal @rr_nsdname, @record.nsdname
  end

  def test_initialize_from_string
    @record = Net::DNS::RR::NS.new("google.com. 10800 IN NS ns1.google.com.")
    assert_equal @rr_output,  @record.inspect
    assert_equal @rr_name,    @record.name
    assert_equal @rr_type,    @record.type
    assert_equal @rr_cls,     @record.cls
    assert_equal @rr_ttl,     @record.ttl
    assert_equal @rr_nsdname, @record.nsdname
  end

  def test_parse
    data = "\006google\003com\000\000\002\000\001\000\000*0\000\020\003ns1\006google\003com\000"
    @record = Net::DNS::RR.parse(data)
    assert_equal @rr_output,  @record.inspect
    assert_equal @rr_name,    @record.name
    assert_equal @rr_type,    @record.type
    assert_equal @rr_cls,     @record.cls
    assert_equal @rr_ttl,     @record.ttl
    assert_equal @rr_nsdname, @record.nsdname
  end

  InvalidArguments = [
    { name: "google.com", nsdname: "255.256" },
    { name: "google.com" },
    Object.new,
    Array.new(7),
    "10800 IN A",
  ].freeze

  InvalidArguments.each_with_index do |arguments, index|
    define_method "test_initialize_should_raise_with_invalid_arguments_#{index}" do
      assert_raises(ArgumentError) { Net::DNS::RR::NS.new(arguments) }
    end
  end

  def test_value
    assert_equal  "ns1.google.com.", @rr.value
  end

  def test_inspect
    assert_equal  "google.com.             10800   IN      NS      ns1.google.com.",
                  @rr.inspect
  end

  def test_to_s
    assert_equal  "google.com.             10800   IN      NS      ns1.google.com.",
                  @rr.to_s
  end

  def test_to_a
    assert_equal  ["google.com.", 10_800, "IN", "NS", "ns1.google.com."],
                  @rr.to_a
  end
end