Skip to content

Commit 5d578e7

Browse files
committed
add
1 parent 7ce2803 commit 5d578e7

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

test/fluent/plugin/test_in_otel.rb

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ def config
1818

1919
def setup
2020
Fluent::Test.setup
21+
22+
# Enable mock_process_clock for freezing Fluent::EventTime
23+
Timecop.mock_process_clock = true
24+
Timecop.freeze(Time.parse("2025-01-01 00:00:00 UTC"))
25+
@event_time = Fluent::EventTime.now
26+
end
27+
28+
def teardown
29+
Timecop.mock_process_clock = false
30+
Timecop.return
2131
end
2232

2333
def create_driver(conf = config)
@@ -55,9 +65,9 @@ def test_receive_json(data)
5565
post_json(data[:request_path], data[:request_data])
5666
end
5767

68+
expected_events = [["otlp.test", @event_time, { type: data[:record_type], message: data[:record_data] }]]
5869
assert_equal(200, res.status)
59-
assert_equal("otlp.test", d.events[0][0])
60-
assert_equal({ type: data[:record_type], message: data[:record_data] }, d.events[0][2])
70+
assert_equal(expected_events, d.events)
6171
end
6272

6373
def test_receive_compressed_json
@@ -66,9 +76,9 @@ def test_receive_compressed_json
6676
post_json("/v1/logs", compress(TestData::JSON::LOGS), { "Content-Encoding" => "gzip" })
6777
end
6878

79+
expected_events = [["otlp.test", @event_time, { type: "otlp_logs", message: TestData::JSON::LOGS }]]
6980
assert_equal(200, res.status)
70-
assert_equal("otlp.test", d.events[0][0])
71-
assert_equal({ type: "otlp_logs", message: TestData::JSON::LOGS }, d.events[0][2])
81+
assert_equal(expected_events, d.events)
7282
end
7383

7484
def test_invalid_json
@@ -104,9 +114,9 @@ def test_receive_protocol_buffers(data)
104114
post_protobuf(data[:request_path], data[:request_data])
105115
end
106116

117+
expected_events = [["otlp.test", @event_time, { type: data[:record_type], message: data[:record_data] }]]
107118
assert_equal(200, res.status)
108-
assert_equal("otlp.test", d.events[0][0])
109-
assert_equal({ type: data[:record_type], message: data[:record_data] }, d.events[0][2])
119+
assert_equal(expected_events, d.events)
110120
end
111121

112122
def test_receive_compressed_protocol_buffers
@@ -115,9 +125,9 @@ def test_receive_compressed_protocol_buffers
115125
post_json("/v1/logs", compress(TestData::ProtocolBuffers::LOGS), { "Content-Encoding" => "gzip" })
116126
end
117127

128+
expected_events = [["otlp.test", @event_time, { type: "otlp_logs", message: TestData::JSON::LOGS }]]
118129
assert_equal(200, res.status)
119-
assert_equal("otlp.test", d.events[0][0])
120-
assert_equal({ type: "otlp_logs", message: TestData::JSON::LOGS }, d.events[0][2])
130+
assert_equal(expected_events, d.events)
121131
end
122132

123133
def test_invalid_protocol_buffers

0 commit comments

Comments
 (0)