<commit_before>require 'helper'

class TestRemoteAddr < Test::Unit::TestCase

  context "ntail" do
    
    setup do
      @remote_addr = "192.168.127.12"
      @log_line = random_log_line(:remote_addr => @remote_addr)
    end

    should "convert the request's remote address into a host string" do
      # directly via the helper function
      to_host_s = NginxTail::LogLine.to_host_s(@remote_addr)
      assert_equal "www.example.com", to_host_s
      # parsed from a raw log line
      assert_equal "www.example.com", @log_line.to_host_s    
    end
    
    should "convert the request's remote address into a country string" do
      # directly via the helper function
      to_country_s = NginxTail::LogLine.to_country_s(@remote_addr)
      assert_equal "United States", to_country_s
      # parsed from a raw log line
      assert_equal "United States", @log_line.to_country_s
    end
    
    should "convert the request's remote address into a city string" do
      # directly via the helper function
      to_city_s = NginxTail::LogLine.to_city_s(@remote_addr)
      assert_equal "Marina Del Rey", to_city_s
      # parsed from a raw log line
      assert_equal "Marina Del Rey", @log_line.to_city_s
    end
    
  end

end<commit_msg>skip unit tests if GeoIP databases aren't installed<commit_after>require 'helper'

class TestRemoteAddr < Test::Unit::TestCase

  context "ntail" do
    
    setup do
      @remote_addr = "192.168.127.12"
      @log_line = random_log_line(:remote_addr => @remote_addr)
    end

    should "convert the request's remote address into a host string" do
      # directly via the helper function
      to_host_s = NginxTail::LogLine.to_host_s(@remote_addr)
      assert_equal "www.example.com", to_host_s
      # parsed from a raw log line
      assert_equal "www.example.com", @log_line.to_host_s    
    end
    
    should "convert the request's remote address into a country string" do
      return unless File.exists?('/usr/share/GeoIP/GeoIP.dat')
      # directly via the helper function
      to_country_s = NginxTail::LogLine.to_country_s(@remote_addr)
      assert_equal "United States", to_country_s
      # parsed from a raw log line
      assert_equal "United States", @log_line.to_country_s
    end
    
    should "convert the request's remote address into a city string" do
      return unless File.exists?('/usr/share/GeoIP/GeoIPCity.dat')
      # directly via the helper function
      to_city_s = NginxTail::LogLine.to_city_s(@remote_addr)
      assert_equal "<NAME>", to_city_s
      # parsed from a raw log line
      assert_equal "<NAME>", @log_line.to_city_s
    end
    
  end

end
{'fraction_non_alphanumeric': 0.07898715041572184, 'fraction_numerical': 0.008314436885865457, 'mean_word_length': 3.0723076923076924, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6935704', 'n_tokens_mistral': 864, 'n_tokens_neox': 824, 'n_words': 242}