Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump Elasticsearch.Xunit #322

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.6" />
<PackageReference Include="Elastic.Elasticsearch.Ephemeral" Version="0.4.0" />
<PackageReference Include="Elastic.Elasticsearch.Ephemeral" Version="0.4.3" />
<PackageReference Include="NEST" Version="7.8.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="Elastic.Apm" Version="1.22.0" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
<PackageReference Include="Elastic.Elasticsearch.Ephemeral" Version="0.4.0" />
<PackageReference Include="Elastic.Elasticsearch.Ephemeral" Version="0.4.3" />
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.0.4" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Elastic.Elasticsearch.Ephemeral" Version="0.4.0" />
<PackageReference Include="Elastic.Elasticsearch.Ephemeral" Version="0.4.3" />
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.0.4" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Elastic.Elasticsearch.Ephemeral;
using Elastic.Elasticsearch.Xunit;
using Elasticsearch.IntegrationDefaults;
using Xunit;

Expand All @@ -8,4 +10,13 @@ namespace Elastic.Serilog.Sinks.IntegrationTests;
public class SerilogCluster : TestClusterBase
{
public SerilogCluster() : base(9205) { }
protected SerilogCluster(int port, ClusterFeatures features) : base(port, features) { }
}

public class SecurityCluster : SerilogCluster
{
public SecurityCluster() : base(9206, ClusterFeatures.XPack | ClusterFeatures.Security | ClusterFeatures.SSL)
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@
using System.Collections.Generic;
using Elastic.Clients.Elasticsearch;
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
using Elasticsearch.IntegrationDefaults;
using Xunit.Abstractions;

namespace Elastic.Serilog.Sinks.IntegrationTests
namespace Elastic.Serilog.Sinks.IntegrationTests;

public abstract class SerilogTestBase<TCluster> : IClusterFixture<TCluster>
where TCluster : TestClusterBase, new()
{
public abstract class SerilogTestBase : IClusterFixture<SerilogCluster>
{
protected ElasticsearchClient Client { get; }
protected ElasticsearchClient Client { get; }

protected SerilogTestBase(SerilogCluster cluster, ITestOutputHelper output, Func<ICollection<Uri>, ICollection<Uri>>? alterNodes = null) =>
Client = cluster.CreateClient(output, alterNodes);
}
protected SerilogTestBase(SerilogCluster cluster, ITestOutputHelper output, Func<ICollection<Uri>, ICollection<Uri>>? alterNodes = null) =>
Client = cluster.CreateClient(output, alterNodes);
}

public abstract class SerilogTestBase : SerilogTestBase<SerilogCluster>
{
protected SerilogTestBase(SerilogCluster cluster, ITestOutputHelper output, Func<ICollection<Uri>, ICollection<Uri>>? alterNodes = null)
: base(cluster, output, alterNodes) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.0.4" />
<PackageReference Include="Elastic.Elasticsearch.Xunit" Version="0.4.0" />
<PackageReference Include="Elastic.Elasticsearch.Xunit" Version="0.4.3" />
<PackageReference Include="Elastic.Ingest.Elasticsearch" Version="0.5.3" />

</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System.Net.Security;
using Elastic.Clients.Elasticsearch;
using Elastic.Elasticsearch.Ephemeral;
using Elastic.Elasticsearch.Xunit;
using Elastic.Transport;
using Xunit;
using Xunit.Abstractions;
using static Elastic.Elasticsearch.Managed.DetectedProxySoftware;

[assembly: TestFramework("Elastic.Elasticsearch.Xunit.Sdk.ElasticTestFramework", "Elastic.Elasticsearch.Xunit")]

Expand All @@ -15,24 +18,19 @@ namespace Elasticsearch.IntegrationDefaults
/// <summary> Declare our cluster that we want to inject into our test classes </summary>
public abstract class TestClusterBase : XunitClusterBase
{
protected TestClusterBase(int port = 9200) : base(new XunitClusterConfiguration("8.4.0")
{
StartingPortNumber = port
}) { }
protected TestClusterBase(int port = 9200, ClusterFeatures features = ClusterFeatures.None)
: base(new XunitClusterConfiguration("8.4.0", features) { StartingPortNumber = port, AutoWireKnownProxies = true }) { }

public ElasticsearchClient CreateClient(ITestOutputHelper output, Func<ICollection<Uri>, ICollection<Uri>>? alterNodes = null) =>
this.GetOrAddClient(_ =>
this.GetOrAddClient(cluster =>
{
var hostName = (System.Diagnostics.Process.GetProcessesByName("mitmproxy").Any()
? "ipv4.fiddler"
: "localhost");
var nodes = NodesUris(hostName);
var isCi = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CI"));
var nodes = NodesUris();
if (alterNodes != null) nodes = alterNodes(nodes);
var connectionPool = new StaticNodePool(nodes);
var isCi = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CI"));
var settings = new ElasticsearchClientSettings(connectionPool)
.Proxy(new Uri("http://ipv4.fiddler:8080"), null!, null!)
.RequestTimeout(TimeSpan.FromSeconds(5))
.ServerCertificateValidationCallback(CertificateValidations.AllowAll)
.OnRequestCompleted(d =>
{
try
Expand All @@ -54,6 +52,12 @@ public ElasticsearchClient CreateClient(ITestOutputHelper output, Func<ICollecti
.EnableDebugMode()
//do not request server stack traces on CI, too noisy
.IncludeServerStackTraceOnError(!isCi);
if (cluster.DetectedProxy != None)
{
var proxyUrl = cluster.DetectedProxy == Fiddler ? "ipv4.fiddler" : "localhost";
settings = settings.Proxy(new Uri($"http://{proxyUrl}:8080"), null!, null!);
}

return new ElasticsearchClient(settings);
});
}
Expand Down