/
test_in_object_space.rb
66 lines (54 loc) · 1.42 KB
/
test_in_object_space.rb
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
60
61
62
63
64
65
66
require_relative '../helper'
require 'fluent/test/driver/input'
require 'fluent/plugin/in_object_space'
require 'timeout'
class ObjectSpaceInputTest < Test::Unit::TestCase
def waiting(seconds, instance)
begin
Timeout.timeout(seconds) do
yield
end
rescue Timeout::Error
STDERR.print(*instance.log.out.logs)
raise
end
end
class FailObject
end
def setup
Fluent::Test.setup
# Overriding this behavior in the global scope will have an unexpected influence on other tests.
# So this should be overridden here and be removed in `teardown`.
def FailObject.class
raise "FailObject error for tests in ObjectSpaceInputTest."
end
end
def teardown
FailObject.singleton_class.remove_method(:class)
end
TESTCONFIG = %[
emit_interval 0.2
tag t1
top 2
]
def create_driver(conf=TESTCONFIG)
Fluent::Test::Driver::Input.new(Fluent::Plugin::ObjectSpaceInput).configure(conf)
end
def test_configure
d = create_driver
assert_equal 0.2, d.instance.emit_interval
assert_equal "t1", d.instance.tag
assert_equal 2, d.instance.top
end
def test_emit
d = create_driver
d.run(expect_emits: 3)
emits = d.events
assert{ emits.length > 0 }
emits.each { |tag, time, record|
assert_equal d.instance.tag, tag
assert_equal d.instance.top, record.keys.size
assert(time.is_a?(Fluent::EventTime))
}
end
end