Skip to content

Commit 7f97621

Browse files
committed
add
1 parent 6e4b38f commit 7f97621

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

test/fluent/plugin/test_in_otel.rb

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,21 @@ def test_receive_json(data)
6363
def test_receive_compressed_json
6464
d = create_driver
6565
res = d.run(expect_records: 1) do
66-
post_json("/v1/metrics", compress(TestData::JSON::METRICS), { "Content-Encoding" => "gzip" })
66+
post_json("/v1/logs", compress(TestData::JSON::LOGS), { "Content-Encoding" => "gzip" })
6767
end
6868

6969
assert_equal(200, res.status)
7070
assert_equal("otlp.test", d.events[0][0])
71-
assert_equal({ type: "otlp_metrics", message: TestData::JSON::METRICS }, d.events[0][2])
71+
assert_equal({ type: "otlp_logs", message: TestData::JSON::LOGS }, d.events[0][2])
72+
end
73+
74+
def test_invalid_json
75+
d = create_driver
76+
res = d.run(expect_records: 0) do
77+
post_json("/v1/logs", TestData::JSON::INVALID)
78+
end
79+
80+
assert_equal(400, res.status)
7281
end
7382

7483
data("metrics" => {
@@ -103,12 +112,39 @@ def test_receive_protocol_buffers(data)
103112
def test_receive_compressed_protocol_buffers
104113
d = create_driver
105114
res = d.run(expect_records: 1) do
106-
post_json("/v1/metrics", compress(TestData::ProtocolBuffers::METRICS), { "Content-Encoding" => "gzip" })
115+
post_json("/v1/logs", compress(TestData::ProtocolBuffers::LOGS), { "Content-Encoding" => "gzip" })
107116
end
108117

109118
assert_equal(200, res.status)
110119
assert_equal("otlp.test", d.events[0][0])
111-
assert_equal({ type: "otlp_metrics", message: TestData::JSON::METRICS }, d.events[0][2])
120+
assert_equal({ type: "otlp_logs", message: TestData::JSON::LOGS }, d.events[0][2])
121+
end
122+
123+
def test_invalid_protocol_buffers
124+
d = create_driver
125+
res = d.run(expect_records: 0) do
126+
post_json("/v1/logs", TestData::ProtocolBuffers::INVALID)
127+
end
128+
129+
assert_equal(400, res.status)
130+
end
131+
132+
def test_invalid_content_type
133+
d = create_driver
134+
res = d.run(expect_records: 0) do
135+
post("/v1/logs", TestData::JSON::LOGS, { "Content-Type" => "text/plain" })
136+
end
137+
138+
assert_equal(415, res.status)
139+
end
140+
141+
def test_invalid_content_encoding
142+
d = create_driver
143+
res = d.run(expect_records: 0) do
144+
post_json("/v1/logs", TestData::JSON::LOGS, { "Content-Encoding" => "deflate" })
145+
end
146+
147+
assert_equal(400, res.status)
112148
end
113149

114150
def compress(data)

test/helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ module JSON
2121
METRICS = ::JSON.generate(::JSON.parse(File.read(File.join(__dir__, "./fluent/assets/metrics.json"))))
2222
TRACES = ::JSON.generate(::JSON.parse(File.read(File.join(__dir__, "./fluent/assets/traces.json"))))
2323
LOGS = ::JSON.generate(::JSON.parse(File.read(File.join(__dir__, "./fluent/assets/logs.json"))))
24+
25+
INVALID = '{"resourceMetrics": "invalid"}'
2426
end
2527

2628
module ProtocolBuffers
2729
METRICS = Fluent::Plugin::Otlp::Request::Metrics.new(TestData::JSON::METRICS).encode
2830
TRACES = Fluent::Plugin::Otlp::Request::Traces.new(TestData::JSON::TRACES).encode
2931
LOGS = Fluent::Plugin::Otlp::Request::Logs.new(TestData::JSON::LOGS).encode
32+
33+
INVALID = "invalid"
3034
end
3135
end

0 commit comments

Comments
 (0)