Sha256: a723e6a49d84e51cbd6ede143896a5a5bdf649755aaaf68d40f95615da8a01aa

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 KB

Contents

require 'helper'
require 'oas/log_collector/manager'

class TestManager < MiniTest::Unit::TestCase
  def setup
    @timestamp = DateTime.new(2012,8,1,15,30).to_time.to_i
    @hostname = 'remote1'
    @result   = ["adstream.log.#{@timestamp}.bz2", "adstream.log.#{@timestamp + 60}.bz2", "adstream.log.#{@timestamp + 120}.bz2"]
    @manager  = OAS::LogCollector::Manager.new({
      :source_logs_path => "/tmp",
      :files_to_copy  => 90,
      :days_to_search => 10,
      :logs_path => "/tmp/logs"
    })
    @source   = Minitest::Mock.new
    @source.expect :host, @hostname
    @source.expect :find, @result, ["/tmp", { :mtime => '-10', :type  => 'f', :regex => '.*\.log\.[0-9]+\.bz2' }]

    OAS::LogCollector.redis = REDIS
    OAS::LogCollector.redis {|c| c.flushdb }
  end

  def test_set_last_run_to_the_last_downloaded_file
    files = Hash.new
    @result.each { |p| files[p] = build_destination_path(p) }
    @source.expect :download, nil, [files]
    @manager.collect(@source)
    @source.verify
    assert_equal @timestamp + 120, @manager.get_last_run(@hostname).to_i
  end

  def test_do_not_select_more_files_than_allowed
    @manager.set_last_run(@hostname, @timestamp)

    OAS::LogCollector.options.merge!({
      :files_to_copy => 1,
    })
    path = "adstream.log.#{@timestamp + 60}.bz2"
    @source.expect :download, nil, [Hash[path, build_destination_path(path)]]
    @manager.collect(@source)
    @source.verify
  end

  def test_select_files_with_timestamp_greater_than_last_run
    @manager.set_last_run(@hostname, @timestamp + 60)

    path = "adstream.log.#{@timestamp + 120}.bz2"
    @source.expect :download, nil, [Hash[path, build_destination_path(path)]]
    @manager.collect(@source)
    @source.verify
  end

  def build_destination_path(path)
    File.join("/tmp/logs", @hostname, "2012", "08", "01", File.basename(path))
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
oas-log-collector-0.1.5 test/test_manager.rb