File: question_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 (81 lines) | stat: -rw-r--r-- 2,975 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
81
require 'test_helper'
require 'net/dns/question'

class QuestionTest < Minitest::Test
  def setup
    @domain = 'example.com.'
    @type   = 'MX'
    @cls  = 'HS'
    @data = "\006google\003com\000\000\001\000\001"

    @default = Net::DNS::Question.new(@domain)
    @string  = Net::DNS::Question.new(@domain, @type, @cls)
    @binary  = Net::DNS::Question.parse(@data)
    @binary2 = Net::DNS::Question.parse(@string.data)
  end

  def test_simple
    assert_equal(@default.qName, @domain)
    assert_equal(@default.qType.to_s, "A")
    assert_equal(@default.qClass.to_s, "IN")

    assert_equal(@string.qName, @domain)
    assert_equal(@string.qType.to_s, "MX")
    assert_equal(@string.qClass.to_s, "HS")

    assert_equal(@binary.qName, "google.com.")
    assert_equal(@binary.qType.to_s, "A")
    assert_equal(@binary.qClass.to_s, "IN")

    assert_equal(@binary2.qName, @domain)
    assert_equal(@binary2.qType.to_s, "MX")
    assert_equal(@binary2.qClass.to_s, "HS")
  end

  def test_raise
    # assert_raises(Net::DNS::Question::NameInvalid) do
    #   Net::DNS::Question.new(1)
    # end
    assert_raises(Net::DNS::Question::NameInvalid) do
      Net::DNS::Question.new("test{")
    end
    assert_raises(ArgumentError) do
      Net::DNS::Question.parse([])
    end
    assert_raises(ArgumentError) do
      Net::DNS::Question.parse("test")
    end
  end

  def test_inspect
    assert_equal  "google.com.                  IN      A       ",
                  Net::DNS::Question.new("google.com.").inspect
    assert_equal  "google.com.                  IN      A       ",
                  Net::DNS::Question.new("google.com.", Net::DNS::A).inspect
    assert_equal  "google.com.                  IN      NS      ",
                  Net::DNS::Question.new("google.com.", Net::DNS::NS).inspect
    assert_equal  "google.com.                  IN      NS      ",
                  Net::DNS::Question.new("google.com.", Net::DNS::NS).inspect
  end

  def test_inspect_with_name_longer_than_29_chrs
    assert_equal  "supercalifragilistichespiralidoso.com IN      A       ",
                  Net::DNS::Question.new("supercalifragilistichespiralidoso.com").inspect
  end

  def test_to_s
    assert_equal  "google.com.                  IN      A       ",
                  Net::DNS::Question.new("google.com.").to_s
    assert_equal  "google.com.                  IN      A       ",
                  Net::DNS::Question.new("google.com.", Net::DNS::A).to_s
    assert_equal  "google.com.                  IN      NS      ",
                  Net::DNS::Question.new("google.com.", Net::DNS::NS).to_s
    assert_equal  "google.com.                  IN      NS      ",
                  Net::DNS::Question.new("google.com.", Net::DNS::NS).to_s
  end

  def test_to_s_with_name_longer_than_29_chrs
    assert_equal  "supercalifragilistichespiralidoso.com IN      A       ",
                  Net::DNS::Question.new("supercalifragilistichespiralidoso.com").to_s
  end
end