summaryrefslogtreecommitdiff
path: root/t/test-custodian-util-ping.rb
blob: 99b61c154b575ef5070ec55543a4b9a92e1c822d (plain)
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
#!/usr/bin/ruby -I./lib/ -I../lib/


require 'custodian/util/ping'
require 'test/unit'



#
# Unit test for our ping utility class.
#
#
class TestPingUtil < Test::Unit::TestCase

  #
  # Create the test suite environment: NOP.
  #
  def setup
  end

  #
  # Destroy the test suite environment: NOP.
  #
  def teardown
  end


  #
  # Test we can construct new objects.
  #
  def test_init

    #
    # Normal construction works.
    #
    assert_nothing_raised do
        Custodian::Util::Ping.new('foo')
    end

    #
    # A hostname must be supplied
    #
    assert_raise ArgumentError do
        Custodian::Util::Ping.new(nil)
    end


    #
    # A hostname is a string, not an array, hash, or similar.
    #
    assert_raise ArgumentError do
      Custodian::Util::Ping.new({})
    end
    assert_raise ArgumentError do
      Custodian::Util::Ping.new([])
    end


  end


  #
  #  Test lookup of hosts that don't work
  #
  def test_lookup_fail
    %w( tessf.dfsdf.sdf.sdfsdf fdsfkljflj3.fdsfds.f3.dfs ).each do |name|
      assert_nothing_raised do
        helper = Custodian::Util::Ping.new(name)

        assert(!helper.is_ipv4?)
        assert(!helper.is_ipv6?)
      end
    end

  end


end