Skip to content

Commit

Permalink
Do not pull in extra dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Abraham Heidebrecht committed Feb 2, 2022
1 parent 6e0ce44 commit 630424c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
43 changes: 29 additions & 14 deletions test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
// </copyright>

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry.Exporter.Jaeger.Implementation;
using OpenTelemetry.Exporter.Jaeger.Implementation.Tests;
using OpenTelemetry.Resources;
using OpenTelemetry.Tests;
using OpenTelemetry.Trace;
using RichardSzalay.MockHttp;
using Thrift.Protocol;
using Xunit;

Expand Down Expand Up @@ -113,20 +113,35 @@ public void ServiceProviderHttpClientFactoryInvoked()
}

[Theory]
[InlineData(JaegerExporterOptions.DefaultJaegerEndpoint)]
[InlineData("http://localhost:1234")]
[InlineData("http://localhost:1234/foo/bar")]
public void HttpClient_Posts_To_Configured_Endpoint(string uri)
[InlineData("/api/traces")]
[InlineData("/foo/bar")]
[InlineData("/")]
public void HttpClient_Posts_To_Configured_Endpoint(string uriPath)
{
// Arrange
var mockHandler = new MockHttpMessageHandler();
mockHandler.Expect(HttpMethod.Post, uri)
.Respond(HttpStatusCode.OK);
ConcurrentDictionary<Guid, string> responses = new ConcurrentDictionary<Guid, string>();
using var testServer = TestHttpServer.RunServer(
context =>
{
context.Response.StatusCode = 200;

using StreamReader readStream = new StreamReader(context.Request.InputStream);

string requestContent = readStream.ReadToEnd();

responses.TryAdd(
Guid.Parse(context.Request.QueryString["requestId"]),
context.Request.Url.LocalPath);

context.Response.OutputStream.Close();
},
out var testServerHost,
out var testServerPort);

var requestId = Guid.NewGuid();
var options = new JaegerExporterOptions
{
Endpoint = new Uri(uri),
HttpClientFactory = () => mockHandler.ToHttpClient(),
Endpoint = new Uri($"http://{testServerHost}:{testServerPort}{uriPath}?requestId={requestId}"),
Protocol = JaegerExportProtocol.HttpBinaryThrift,
ExportProcessorType = ExportProcessorType.Simple,
};
Expand All @@ -139,8 +154,8 @@ public void HttpClient_Posts_To_Configured_Endpoint(string uri)
jaegerExporter.SendCurrentBatch();

// Assert
mockHandler.VerifyNoOutstandingExpectation();
mockHandler.VerifyNoOutstandingRequest();
Assert.True(responses.ContainsKey(requestId));
Assert.Equal(uriPath, responses[requestId]);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<Compile Include="$(RepoRoot)\test\OpenTelemetry.Tests\Shared\TestHttpServer.cs" Link="TestHttpServer.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkPkgVer)" />
<PackageReference Include="Moq" Version="$(MoqPkgVer)" />
Expand All @@ -18,7 +22,6 @@
<DotNetCliToolReference Include="dotnet-xunit" Version="$(DotNetXUnitCliVer)" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="$(MicrosoftExtensionsHostingPkgVer)" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.20" />
<PackageReference Include="RichardSzalay.MockHttp" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 630424c

Please sign in to comment.