Skip to content

Commit 006b096

Browse files
committed
Fix CodeQL
1 parent 1abb9bd commit 006b096

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

tests-integration/Elastic.Documentation.Api.IntegrationTests/OtlpProxyIntegrationTests.cs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ public async Task OtlpProxyTracesEndpointForwardsToCorrectUrl()
2626
.Where(call => call.Method.Name == "SendAsync")
2727
.WithReturnType<Task<HttpResponseMessage>>()
2828
.Invokes((HttpRequestMessage req, CancellationToken ct) => capturedRequest = req)
29-
.Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("{}") }));
29+
.Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
30+
{
31+
Content = new StringContent("{}")
32+
}));
3033

3134
using var factory = ApiWebApplicationFactory.WithMockedServices(services =>
3235
{
@@ -49,10 +52,11 @@ public async Task OtlpProxyTracesEndpointForwardsToCorrectUrl()
4952
}]
5053
}
5154
""";
52-
var content = new StringContent(otlpPayload, Encoding.UTF8, "application/json");
55+
56+
using var content = new StringContent(otlpPayload, Encoding.UTF8, "application/json");
5357

5458
// Act
55-
var response = await client.PostAsync("/docs/_api/v1/o/t", content, TestContext.Current.CancellationToken);
59+
using var response = await client.PostAsync("/docs/_api/v1/o/t", content, TestContext.Current.CancellationToken);
5660

5761
// Assert - verify the request was forwarded to the correct URL
5862
if (!response.IsSuccessStatusCode)
@@ -81,7 +85,10 @@ public async Task OtlpProxyLogsEndpointForwardsToCorrectUrl()
8185
.Where(call => call.Method.Name == "SendAsync")
8286
.WithReturnType<Task<HttpResponseMessage>>()
8387
.Invokes((HttpRequestMessage req, CancellationToken ct) => capturedRequest = req)
84-
.Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("{}") }));
88+
.Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
89+
{
90+
Content = new StringContent("{}")
91+
}));
8592

8693
using var factory = ApiWebApplicationFactory.WithMockedServices(services =>
8794
{
@@ -106,10 +113,11 @@ public async Task OtlpProxyLogsEndpointForwardsToCorrectUrl()
106113
}]
107114
}
108115
""";
109-
var content = new StringContent(otlpPayload, Encoding.UTF8, "application/json");
116+
117+
using var content = new StringContent(otlpPayload, Encoding.UTF8, "application/json");
110118

111119
// Act
112-
var response = await client.PostAsync("/docs/_api/v1/o/l", content, TestContext.Current.CancellationToken);
120+
using var response = await client.PostAsync("/docs/_api/v1/o/l", content, TestContext.Current.CancellationToken);
113121

114122
// Assert - verify the enum ToStringFast() generates "logs" (lowercase)
115123
response.StatusCode.Should().Be(HttpStatusCode.OK);
@@ -128,7 +136,10 @@ public async Task OtlpProxyMetricsEndpointForwardsToCorrectUrl()
128136
.Where(call => call.Method.Name == "SendAsync")
129137
.WithReturnType<Task<HttpResponseMessage>>()
130138
.Invokes((HttpRequestMessage req, CancellationToken ct) => capturedRequest = req)
131-
.Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("{}") }));
139+
.Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
140+
{
141+
Content = new StringContent("{}")
142+
}));
132143

133144
using var factory = ApiWebApplicationFactory.WithMockedServices(services =>
134145
{
@@ -149,10 +160,11 @@ public async Task OtlpProxyMetricsEndpointForwardsToCorrectUrl()
149160
}]
150161
}
151162
""";
152-
var content = new StringContent(otlpPayload, Encoding.UTF8, "application/json");
163+
164+
using var content = new StringContent(otlpPayload, Encoding.UTF8, "application/json");
153165

154166
// Act
155-
var response = await client.PostAsync("/docs/_api/v1/o/m", content, TestContext.Current.CancellationToken);
167+
using var response = await client.PostAsync("/docs/_api/v1/o/m", content, TestContext.Current.CancellationToken);
156168

157169
// Assert - verify the enum ToStringFast() generates "metrics" (lowercase)
158170
response.StatusCode.Should().Be(HttpStatusCode.OK);
@@ -181,10 +193,10 @@ public async Task OtlpProxyReturnsCollectorErrorStatusCode()
181193
});
182194

183195
var client = factory.CreateClient();
184-
var content = new StringContent("{}", Encoding.UTF8, "application/json");
196+
using var content = new StringContent("{}", Encoding.UTF8, "application/json");
185197

186198
// Act
187-
var response = await client.PostAsync("/docs/_api/v1/o/t", content, TestContext.Current.CancellationToken);
199+
using var response = await client.PostAsync("/docs/_api/v1/o/t", content, TestContext.Current.CancellationToken);
188200

189201
// Assert - verify error responses are properly forwarded
190202
response.StatusCode.Should().Be(HttpStatusCode.ServiceUnavailable);
@@ -198,10 +210,10 @@ public async Task OtlpProxyInvalidSignalTypeReturns404()
198210
// Arrange
199211
using var factory = new ApiWebApplicationFactory();
200212
using var client = factory.CreateClient();
201-
var content = new StringContent("{}", Encoding.UTF8, "application/json");
213+
using var content = new StringContent("{}", Encoding.UTF8, "application/json");
202214

203215
// Act - use invalid signal type
204-
var response = await client.PostAsync("/docs/_api/v1/o/invalid", content, TestContext.Current.CancellationToken);
216+
using var response = await client.PostAsync("/docs/_api/v1/o/invalid", content, TestContext.Current.CancellationToken);
205217

206218
// Assert - route doesn't exist
207219
response.StatusCode.Should().Be(HttpStatusCode.NotFound);

0 commit comments

Comments
 (0)