summaryrefslogtreecommitdiff
path: root/t/test-multi-ping.rb
blob: e75947c4129c38619482f36ea9e76c7ab06a6099 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/ruby1.8 -I./lib/ -I../lib/



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



#
# Unit test for our multi-ping tool.
#
class TestMultiPing < Test::Unit::TestCase

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

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


  #
  # Ensure we can instantiate the object
  #
  def test_init


    #
    #  Calling without a hostname is a mistake.
    #
    assert_raise ArgumentError do
      obj = Custodian::Util::Ping.new()
    end

    #
    #  Calling with a hostname should be fine mistake.
    #
      obj = Custodian::Util::Ping.new( "some.host.anme" )
    end
  end


  #
  #  Test address-family detection
  #
  def test_families

    #
    #  Hash of hostnames and version of address.
    #
    to_test = {
      "ipv6.steve.org.uk" => 6,
      "ipv6.google.com"   => 6,

      "ipv4.steve.org.uk" => 4,
      "google.com"        => 4,
    }


    to_test.each do |name,version|

      a = Custodian::Util::Ping.new( name )

      if ( version == 6 )
        assert_equal( a.is_ipv6?, true, "#{name} is IPv6" )
        assert_equal( a.is_ipv4?, false, "#{name} is not IPv4" )
      end

      if ( version == 4 )
        assert_equal( a.is_ipv6?, false, "#{name} is not IPv6" )
        assert_equal( a.is_ipv4?, true, "#{name} is IPv4" )
      end
    end
  end



  #
  #  Test that bogus hosts are not reported as either IPv4 or IPv6
  #
  def test_bogus

    %w( tessf.dfsdf.sdf.sdfsdf fdsfkljflj3.fdsfds.f3.dfs ).each do |name|
      helper = Custodian::Util::Ping.new( name )

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


end