@@ -9,6 +9,18 @@ def create_driver(conf='')
9
9
Fluent ::Test ::Driver ::Filter . new ( Fluent ::Plugin ::ElasticsearchTimestampCheckFilter ) . configure ( conf )
10
10
end
11
11
12
+ def test_configure
13
+ assert_raise ( Fluent ::ConfigError ) do
14
+ create_driver ( %[subsecond_precision -3] )
15
+ end
16
+ assert_raise ( Fluent ::ConfigError ) do
17
+ create_driver ( %[subsecond_precision 0] )
18
+ end
19
+ assert_nothing_raised do
20
+ create_driver ( %[subsecond_precision 1] )
21
+ end
22
+ end
23
+
12
24
def test_added_timestamp
13
25
d = create_driver
14
26
d . run ( default_tag : 'test' ) do
@@ -51,7 +63,29 @@ def test_timestamp_with_digit(data)
51
63
num = timestamp . to_f
52
64
formatted_time = Time . at (
53
65
num / ( 10 ** ( ( Math . log10 ( num ) . to_i + 1 ) - 10 ) )
54
- ) . strftime ( '%Y-%m-%dT%H:%M:%S.%L%z' )
66
+ ) . strftime ( '%Y-%m-%dT%H:%M:%S.%3N%z' )
67
+ assert_true ( filtered . key? ( "@timestamp" ) )
68
+ assert_true ( filtered . key? ( "fluent_converted_timestamp" ) )
69
+ assert_equal ( formatted_time , filtered [ "fluent_converted_timestamp" ] )
70
+ end
71
+
72
+ data ( '@timestamp' => '@timestamp' ,
73
+ 'timestamp' => 'timestamp' ,
74
+ 'time' => 'time' ,
75
+ 'syslog_timestamp' => 'syslog_timestamp' )
76
+ def test_timestamp_with_digit_and_nano_precision ( data )
77
+ timekey = data
78
+ precision = 9
79
+ d = create_driver ( %[subsecond_precision #{ precision } ] )
80
+ timestamp = '1505800348899'
81
+ d . run ( default_tag : 'test' ) do
82
+ d . feed ( { 'test' => 'notime' } . merge ( timekey => timestamp ) )
83
+ end
84
+ filtered = d . filtered . map { |e | e . last } . first
85
+ num = timestamp . to_f
86
+ formatted_time = Time . at (
87
+ num / ( 10 ** ( ( Math . log10 ( num ) . to_i + 1 ) - 10 ) )
88
+ ) . strftime ( "%Y-%m-%dT%H:%M:%S.%#{ precision } N%z" )
55
89
assert_true ( filtered . key? ( "@timestamp" ) )
56
90
assert_true ( filtered . key? ( "fluent_converted_timestamp" ) )
57
91
assert_equal ( formatted_time , filtered [ "fluent_converted_timestamp" ] )
0 commit comments