public
Description: ruby binding to maxmind geoip library
Homepage: http://geoip-city.rubyforge.org
Clone URL: git://github.com/ry/geoip-city.git
Search Repo:
geoip-city / test.rb
100644 59 lines (47 sloc) 1.364 kb
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
require 'test/unit'
require File.dirname(__FILE__) + '/geoip_city'
require 'rubygems'
require 'ruby-debug'
Debugger.start
 
class GeoIPTest < Test::Unit::TestCase
  
  def setup
    ## Change me!
    @dbfile = '/opt/GeoIP-1.4.2/share/GeoIP/GeoLiteCity.dat'
  end
  
  
  def test_construction_default
    db = GeoIPCity::Database.new(@dbfile)
    
    assert_raises TypeError do
      db.look_up(nil)
    end
    
    h = db.look_up('24.24.24.24')
    #debugger
    assert_kind_of Hash, h
    assert_equal 'Ithaca', h[:city]
    assert_equal 'United States', h[:country_name]
  end
 
  def test_construction_index
    db = GeoIPCity::Database.new(@dbfile, :index)
    h = db.look_up('24.24.24.24')
    assert_equal 'Ithaca', h[:city]
  end
 
  def test_construction_filesystem
    db = GeoIPCity::Database.new(@dbfile, :filesystem)
    h = db.look_up('24.24.24.24')
    assert_equal 'Ithaca', h[:city]
  end
 
  def test_construction_memory
    db = GeoIPCity::Database.new(@dbfile, :memory)
    h = db.look_up('24.24.24.24')
    assert_equal 'Ithaca', h[:city]
  end
 
  def test_construction_filesystem_check
    db = GeoIPCity::Database.new(@dbfile, :filesystem, true)
    h = db.look_up('24.24.24.24')
    assert_equal 'Ithaca', h[:city]
  end
 
  def test_bad_db_file
    assert_raises Errno::ENOENT do
      GeoIPCity::Database.new('/blah')
    end
  end
  
end