summaryrefslogtreecommitdiffstats
path: root/genome-bootstrap/test/test_genome-bootstrap.rb
blob: 616d6a4e8a9959f462a7fd7f2dccc3675da2330c (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
# Copyright (C) 2008 Red Hat, Inc

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# a long with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

require 'genome-bootstrap/ddns'
require 'rubygems'
require 'mocha'

class TestDDNS < Test::Unit::TestCase
  def setup
    @test_main_page = File.read(File.dirname(__FILE__) + "/data/test_main_page.html")
  end

  def mkddns(hostname)
    RedHatDDNS::DDNS.new("fakeuser", "fakepass", hostname)
  end

  def test_exact_match_exists
    ddns = mkddns("bleanhar-jboss-mysql")
    ddns.expects(:main_page).yields(@test_main_page)
    ddns.expects(:request_new_hash).never
    assert_equal("bleanhar-jboss-mysql24c50", ddns.ddns_hash)
  end

  def test_hostnames_in_reverse_alphabetical_order
    ddns = mkddns("qax")
    ddns.expects(:main_page).yields(@test_main_page)
    ddns.expects(:request_new_hash).never
    assert_equal("qax2881b", ddns.ddns_hash)
  end

  def test_exact_match_doesnt_exist_but_a_superset_does
    ddns = mkddns("bleanhar-jboss")
    ddns.stubs(:main_page).yields(@test_main_page)
    ddns.expects(:request_new_hash).times(3) # This is the default number of tries

    assert_raise RuntimeError do
      ddns.ddns_hash
    end
  end
end