Skip to content

Commit c0a3a11

Browse files
committed
test
1 parent 4f70ff8 commit c0a3a11

File tree

2 files changed

+272
-215
lines changed

2 files changed

+272
-215
lines changed

test/fluent/plugin/test_in_otlp.rb

Lines changed: 142 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@
66
require "fluent/test/driver/input"
77

88
class Fluent::Plugin::OtlpInputTest < Test::Unit::TestCase
9-
def config
10-
<<~"CONFIG"
11-
tag otlp.test
12-
<http>
13-
bind 127.0.0.1
14-
port #{@port}
15-
</http>
16-
CONFIG
17-
end
18-
199
def setup
2010
Fluent::Test.setup
2111

@@ -37,126 +27,176 @@ def create_driver(conf = config)
3727
end
3828

3929
def test_configure
40-
d = create_driver
30+
d = create_driver(%[
31+
tag otlp.test
32+
<http>
33+
bind 127.0.0.1
34+
port #{@port}
35+
</http>
36+
])
4137
assert_equal "otlp.test", d.instance.tag
4238
assert_equal "127.0.0.1", d.instance.http_config.bind
4339
assert_equal @port, d.instance.http_config.port
40+
41+
d = create_driver(%[
42+
tag otlp.test
43+
<grpc>
44+
bind 127.0.0.1
45+
port #{@port}
46+
</grpc>
47+
])
48+
assert_equal "127.0.0.1", d.instance.grpc_config.bind
49+
assert_equal @port, d.instance.grpc_config.port
50+
51+
d = create_driver(%[
52+
tag otlp.test
53+
<http>
54+
bind 127.0.0.1
55+
port #{@port}
56+
</http>
57+
<grpc>
58+
bind 127.0.0.1
59+
port #{@port}
60+
</grpc>
61+
])
62+
assert_equal "127.0.0.1", d.instance.http_config.bind
63+
assert_equal @port, d.instance.http_config.port
64+
assert_equal "127.0.0.1", d.instance.grpc_config.bind
65+
assert_equal @port, d.instance.grpc_config.port
66+
67+
assert_raise(Fluent::ConfigError) do
68+
create_driver(%[
69+
tag otlp.test
70+
])
71+
end
4472
end
4573

46-
data("metrics" => {
47-
request_path: "/v1/metrics",
48-
request_data: TestData::JSON::METRICS,
49-
record_type: "otlp_metrics",
50-
record_data: TestData::JSON::METRICS
51-
},
52-
"traces" => {
53-
request_path: "/v1/traces",
54-
request_data: TestData::JSON::TRACES,
55-
record_type: "otlp_traces",
56-
record_data: TestData::JSON::TRACES
57-
},
58-
"logs" => {
59-
request_path: "/v1/logs",
60-
request_data: TestData::JSON::LOGS,
61-
record_type: "otlp_logs",
62-
record_data: TestData::JSON::LOGS
63-
})
64-
def test_receive_json(data)
65-
d = create_driver
66-
res = d.run(expect_records: 1) do
67-
post_json(data[:request_path], data[:request_data])
74+
sub_test_case "HTTP" do
75+
def config
76+
<<~"CONFIG"
77+
tag otlp.test
78+
<http>
79+
bind 127.0.0.1
80+
port #{@port}
81+
</http>
82+
CONFIG
6883
end
6984

70-
expected_events = [["otlp.test", @event_time, { type: data[:record_type], message: data[:record_data] }]]
71-
assert_equal(200, res.status)
72-
assert_equal(expected_events, d.events)
73-
end
85+
data("metrics" => {
86+
request_path: "/v1/metrics",
87+
request_data: TestData::JSON::METRICS,
88+
record_type: "otlp_metrics",
89+
record_data: TestData::JSON::METRICS
90+
},
91+
"traces" => {
92+
request_path: "/v1/traces",
93+
request_data: TestData::JSON::TRACES,
94+
record_type: "otlp_traces",
95+
record_data: TestData::JSON::TRACES
96+
},
97+
"logs" => {
98+
request_path: "/v1/logs",
99+
request_data: TestData::JSON::LOGS,
100+
record_type: "otlp_logs",
101+
record_data: TestData::JSON::LOGS
102+
})
103+
def test_receive_json(data)
104+
d = create_driver
105+
res = d.run(expect_records: 1) do
106+
post_json(data[:request_path], data[:request_data])
107+
end
74108

75-
def test_receive_compressed_json
76-
d = create_driver
77-
res = d.run(expect_records: 1) do
78-
post_json("/v1/logs", compress(TestData::JSON::LOGS), headers: { "Content-Encoding" => "gzip" })
109+
expected_events = [["otlp.test", @event_time, { type: data[:record_type], message: data[:record_data] }]]
110+
assert_equal(200, res.status)
111+
assert_equal(expected_events, d.events)
79112
end
80113

81-
expected_events = [["otlp.test", @event_time, { type: "otlp_logs", message: TestData::JSON::LOGS }]]
82-
assert_equal(200, res.status)
83-
assert_equal(expected_events, d.events)
84-
end
114+
def test_receive_compressed_json
115+
d = create_driver
116+
res = d.run(expect_records: 1) do
117+
post_json("/v1/logs", compress(TestData::JSON::LOGS), headers: { "Content-Encoding" => "gzip" })
118+
end
85119

86-
def test_invalid_json
87-
d = create_driver
88-
res = d.run(expect_records: 0) do
89-
post_json("/v1/logs", TestData::JSON::INVALID)
120+
expected_events = [["otlp.test", @event_time, { type: "otlp_logs", message: TestData::JSON::LOGS }]]
121+
assert_equal(200, res.status)
122+
assert_equal(expected_events, d.events)
90123
end
91124

92-
assert_equal(400, res.status)
93-
end
125+
def test_invalid_json
126+
d = create_driver
127+
res = d.run(expect_records: 0) do
128+
post_json("/v1/logs", TestData::JSON::INVALID)
129+
end
94130

95-
data("metrics" => {
96-
request_path: "/v1/metrics",
97-
request_data: TestData::ProtocolBuffers::METRICS,
98-
record_type: "otlp_metrics",
99-
record_data: TestData::JSON::METRICS
100-
},
101-
"traces" => {
102-
request_path: "/v1/traces",
103-
request_data: TestData::ProtocolBuffers::TRACES,
104-
record_type: "otlp_traces",
105-
record_data: TestData::JSON::TRACES
106-
},
107-
"logs" => {
108-
request_path: "/v1/logs",
109-
request_data: TestData::ProtocolBuffers::LOGS,
110-
record_type: "otlp_logs",
111-
record_data: TestData::JSON::LOGS
112-
})
113-
def test_receive_protocol_buffers(data)
114-
d = create_driver
115-
res = d.run(expect_records: 1) do
116-
post_protobuf(data[:request_path], data[:request_data])
131+
assert_equal(400, res.status)
117132
end
118133

119-
expected_events = [["otlp.test", @event_time, { type: data[:record_type], message: data[:record_data] }]]
120-
assert_equal(200, res.status)
121-
assert_equal(expected_events, d.events)
122-
end
134+
data("metrics" => {
135+
request_path: "/v1/metrics",
136+
request_data: TestData::ProtocolBuffers::METRICS,
137+
record_type: "otlp_metrics",
138+
record_data: TestData::JSON::METRICS
139+
},
140+
"traces" => {
141+
request_path: "/v1/traces",
142+
request_data: TestData::ProtocolBuffers::TRACES,
143+
record_type: "otlp_traces",
144+
record_data: TestData::JSON::TRACES
145+
},
146+
"logs" => {
147+
request_path: "/v1/logs",
148+
request_data: TestData::ProtocolBuffers::LOGS,
149+
record_type: "otlp_logs",
150+
record_data: TestData::JSON::LOGS
151+
})
152+
def test_receive_protocol_buffers(data)
153+
d = create_driver
154+
res = d.run(expect_records: 1) do
155+
post_protobuf(data[:request_path], data[:request_data])
156+
end
123157

124-
def test_receive_compressed_protocol_buffers
125-
d = create_driver
126-
res = d.run(expect_records: 1) do
127-
post_protobuf("/v1/logs", compress(TestData::ProtocolBuffers::LOGS), headers: { "Content-Encoding" => "gzip" })
158+
expected_events = [["otlp.test", @event_time, { type: data[:record_type], message: data[:record_data] }]]
159+
assert_equal(200, res.status)
160+
assert_equal(expected_events, d.events)
128161
end
129162

130-
expected_events = [["otlp.test", @event_time, { type: "otlp_logs", message: TestData::JSON::LOGS }]]
131-
assert_equal(200, res.status)
132-
assert_equal(expected_events, d.events)
133-
end
163+
def test_receive_compressed_protocol_buffers
164+
d = create_driver
165+
res = d.run(expect_records: 1) do
166+
post_protobuf("/v1/logs", compress(TestData::ProtocolBuffers::LOGS), headers: { "Content-Encoding" => "gzip" })
167+
end
134168

135-
def test_invalid_protocol_buffers
136-
d = create_driver
137-
res = d.run(expect_records: 0) do
138-
post_json("/v1/logs", TestData::ProtocolBuffers::INVALID)
169+
expected_events = [["otlp.test", @event_time, { type: "otlp_logs", message: TestData::JSON::LOGS }]]
170+
assert_equal(200, res.status)
171+
assert_equal(expected_events, d.events)
139172
end
140173

141-
assert_equal(400, res.status)
142-
end
174+
def test_invalid_protocol_buffers
175+
d = create_driver
176+
res = d.run(expect_records: 0) do
177+
post_json("/v1/logs", TestData::ProtocolBuffers::INVALID)
178+
end
143179

144-
def test_invalid_content_type
145-
d = create_driver
146-
res = d.run(expect_records: 0) do
147-
post("/v1/logs", TestData::JSON::LOGS, headers: { "Content-Type" => "text/plain" })
180+
assert_equal(400, res.status)
148181
end
149182

150-
assert_equal(415, res.status)
151-
end
183+
def test_invalid_content_type
184+
d = create_driver
185+
res = d.run(expect_records: 0) do
186+
post("/v1/logs", TestData::JSON::LOGS, headers: { "Content-Type" => "text/plain" })
187+
end
152188

153-
def test_invalid_content_encoding
154-
d = create_driver
155-
res = d.run(expect_records: 0) do
156-
post_json("/v1/logs", TestData::JSON::LOGS, headers: { "Content-Encoding" => "deflate" })
189+
assert_equal(415, res.status)
157190
end
158191

159-
assert_equal(400, res.status)
192+
def test_invalid_content_encoding
193+
d = create_driver
194+
res = d.run(expect_records: 0) do
195+
post_json("/v1/logs", TestData::JSON::LOGS, headers: { "Content-Encoding" => "deflate" })
196+
end
197+
198+
assert_equal(400, res.status)
199+
end
160200
end
161201

162202
sub_test_case "HTTPS" do

0 commit comments

Comments
 (0)