test/test_manager.rb in oas-log-collector-0.1.4 vs test/test_manager.rb in oas-log-collector-0.1.5
- old
+ new
@@ -1,48 +1,56 @@
require 'helper'
require 'oas/log_collector/manager'
class TestManager < MiniTest::Unit::TestCase
def setup
- OAS::LogCollector.options.merge!({
+ @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"
})
- @result = ["adstream.log.223456789.bz2", "adstream.log.123456789.bz2", "adstream.log.323456789.bz2"]
- @manager = OAS::LogCollector::Manager.new
- @source = Minitest::Mock.new
- @source.expect :host, 'localhost'
+ @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
- @source.expect :copy, nil, [@result, "/tmp/logs"]
+ files = Hash.new
+ @result.each { |p| files[p] = build_destination_path(p) }
+ @source.expect :download, nil, [files]
@manager.collect(@source)
@source.verify
- assert_equal "323456789", @manager.get_last_run('localhost')
+ 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('localhost', '123456789')
+ @manager.set_last_run(@hostname, @timestamp)
OAS::LogCollector.options.merge!({
:files_to_copy => 1,
})
-
- @source.expect :copy, nil, [["adstream.log.223456789.bz2"], "/tmp/logs"]
+ 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('localhost', '223456789')
+ @manager.set_last_run(@hostname, @timestamp + 60)
- @source.expect :copy, nil, [["adstream.log.323456789.bz2"], "/tmp/logs"]
+ 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
\ No newline at end of file