Skip to content

Commit bca9cbe

Browse files
authored
Move to Nullean.Xunit.Partitions (#63)
* extract more generic xunit project from Elastic.Elasticsearch.Xunit * small cleanups * Move to Nullean.Xunit.Partitions * Move to Nullean.Xunit.Partitions * update to latest nullean.xunit.partitions
1 parent 45c9637 commit bca9cbe

19 files changed

+243
-580
lines changed

Diff for: examples/Elastic.Xunit.ExampleComplex/Setup.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ public class MyRunOptions : ElasticXunitRunOptions
1919
{
2020
public MyRunOptions()
2121
{
22-
ClusterFilter = "";
23-
RunUnitTests = false;
22+
RunUnitTests = true;
2423
RunIntegrationTests = true;
2524
IntegrationTestsMayUseAlreadyRunningNode = true;
2625
Version = TestVersion;
2726
}
2827

29-
public static ElasticVersion TestVersion { get; } = "8.0.0-SNAPSHOT";
28+
public static ElasticVersion TestVersion { get; } = "latest-8";
3029
}
3130
}

Diff for: examples/Elastic.Xunit.ExampleComplex/TestWithoutClusterFixture.cs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
namespace Elastic.Xunit.ExampleComplex
1010
{
11-
[IntegrationTestCluster(typeof(TestCluster))]
1211
[SkipVersion("<6.3.0", "")]
1312
public class TestWithoutClusterFixture
1413
{

Diff for: examples/Elastic.Xunit.ExampleComplex/Tests.cs

+67-23
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5+
using Elastic.Elasticsearch.Managed;
56
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
67
using Elasticsearch.Net;
78
using FluentAssertions;
9+
using Xunit;
810

911
namespace Elastic.Xunit.ExampleComplex
1012
{
1113
public class MyTestClass : ClusterTestClassBase<TestCluster>
1214
{
13-
public MyTestClass(TestCluster cluster) : base(cluster)
14-
{
15-
}
15+
public MyTestClass(TestCluster cluster) : base(cluster) { }
1616

1717
[I]
1818
public void SomeTest()
@@ -22,34 +22,70 @@ public void SomeTest()
2222
info.IsValid.Should().BeTrue();
2323

2424
Client.CreateIndex("INASda");
25+
Client.LowLevel.Search<StringResponse>(PostData.Serializable(new {query = new {query_string = 1}}));
26+
}
27+
}
2528

29+
public class Tests1 : ClusterTestClassBase<TestCluster>
30+
{
31+
public Tests1(TestCluster cluster) : base(cluster) { }
2632

27-
Client.LowLevel.Search<StringResponse>(PostData.Serializable(new {query = new {query_string = 1}}));
33+
[U] public void Unit1Test() => (1 + 1).Should().Be(2);
34+
[U] public void Unit1Test1() => (1 + 1).Should().Be(2);
35+
[U] public void Unit1Test2() => (1 + 1).Should().Be(2);
36+
[U] public void Unit1Test3() => (1 + 1).Should().Be(2);
37+
[U] public void Unit1Test4() => (1 + 1).Should().Be(2);
38+
[U] public void Unit1Test5() => (1 + 1).Should().Be(2);
39+
[U] public void Unit1Test6() => (1 + 1).Should().Be(2);
40+
}
41+
42+
public class Tests3
43+
{
44+
[U] public void Unit3Test() => (1 + 1).Should().Be(2);
45+
[U] public void Unit3Test1() => (1 + 1).Should().Be(2);
46+
[U] public void Unit3Test2() => (1 + 1).Should().Be(2);
47+
[U] public void Unit3Test3() => (1 + 1).Should().Be(2);
48+
[U] public void Unit3Test4() => (1 + 1).Should().Be(2);
49+
[U] public void Unit3Test5() => (1 + 1).Should().Be(2);
50+
[U] public void Unit3Test6() => (1 + 1).Should().Be(2);
51+
}
52+
53+
public class Tests2 : ClusterTestClassBase<TestCluster>
54+
{
55+
public Tests2(TestCluster cluster) : base(cluster) { }
56+
57+
[U] public void Unit2Test() => (1 + 1).Should().Be(2);
58+
[U] public void Unit2Test1() => (1 + 1).Should().Be(2);
59+
[U] public void Unit2Test2() => (1 + 1).Should().Be(2);
60+
[U] public void Unit2Test3() => (1 + 1).Should().Be(2);
61+
[U] public void Unit2Test4() => (1 + 1).Should().Be(2);
62+
[U] public void Unit2Test5() => (1 + 1).Should().Be(2);
63+
[U] public void Unit2Test6() => (1 + 1).Should().Be(2);
64+
}
65+
66+
public class MyGenericTestClass : ClusterTestClassBase<TestGenericCluster>
67+
{
68+
public MyGenericTestClass(TestGenericCluster cluster) : base(cluster) { }
69+
70+
[I] public void SomeTest()
71+
{
72+
var info = Client.RootNodeInfo();
73+
74+
info.IsValid.Should().BeTrue();
2875
}
76+
[U] public void MyGenericUnitTest() => (1 + 1).Should().Be(2);
77+
[U] public void MyGenericUnitTest1() => (1 + 1).Should().Be(2);
78+
[U] public void MyGenericUnitTest2() => (1 + 1).Should().Be(2);
79+
[U] public void MyGenericUnitTest3() => (1 + 1).Should().Be(2);
80+
[U] public void MyGenericUnitTest4() => (1 + 1).Should().Be(2);
81+
[U] public void MyGenericUnitTest5() => (1 + 1).Should().Be(2);
82+
[U] public void MyGenericUnitTest6() => (1 + 1).Should().Be(2);
2983
}
30-
//
31-
// public class MyGenericTestClass : ClusterTestClassBase<TestGenericCluster>
32-
// {
33-
// public MyGenericTestClass(TestGenericCluster cluster) : base(cluster) { }
34-
//
35-
// [I] public void SomeTest()
36-
// {
37-
// var info = this.Client.RootNodeInfo();
38-
//
39-
// info.IsValid.Should().BeTrue();
40-
// }
41-
// [U] public void UnitTest()
42-
// {
43-
// (1 + 1).Should().Be(2);
44-
// }
45-
// }
4684

4785
[SkipVersion("<6.2.0", "")]
4886
public class SkipTestClass : ClusterTestClassBase<TestGenericCluster>
4987
{
50-
public SkipTestClass(TestGenericCluster cluster) : base(cluster)
51-
{
52-
}
88+
public SkipTestClass(TestGenericCluster cluster) : base(cluster) { }
5389

5490
[I]
5591
public void SomeTest()
@@ -62,4 +98,12 @@ public void SomeTest()
6298
[U]
6399
public void UnitTest() => (1 + 1).Should().Be(2);
64100
}
101+
102+
public class DirectInterfaceTests : IClusterFixture<TestGenericCluster>
103+
{
104+
public DirectInterfaceTests(TestGenericCluster cluster) { }
105+
106+
[U]
107+
public void DirectUnitTest() => (1 + 1).Should().Be(2);
108+
}
65109
}

Diff for: examples/Elastic.Xunit.ExampleMinimal/ExampleTest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class MyTestCluster : XunitClusterBase
2121
/// We pass our configuration instance to the base class.
2222
/// We only configure it to run version 6.2.3 here but lots of additional options are available.
2323
/// </summary>
24-
public MyTestCluster() : base(new XunitClusterConfiguration("8.0.0-SNAPSHOT") { })
24+
public MyTestCluster() : base(new XunitClusterConfiguration("latest-8") { })
2525
{
2626
}
2727
}

Diff for: examples/ScratchPad/Program.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public static class Program
2424

2525
public static int Main()
2626
{
27-
//ResolveVersions();
28-
ManualConfigRun();
27+
ResolveVersions();
28+
//ManualConfigRun();
2929
//ValidateCombinations.Run();
3030
return 0;
3131
}
@@ -87,8 +87,8 @@ private static void ResolveVersions()
8787
{
8888
var versions = new[]
8989
{
90-
"8.0.0-SNAPSHOT", "7.0.0-beta1", "6.6.1", "latest-7", "latest", "7.0.0", "7.4.0-SNAPSHOT",
91-
"957e3089:7.2.0", "latest-6"
90+
"latest-8", "7.0.0-beta1", "6.6.1", "latest-7", "latest", "7.0.0", "7.4.0-SNAPSHOT",
91+
"957e3089:7.2.0"
9292
};
9393
//versions = new[] {"latest-7"};
9494
var products = new Product[]

Diff for: src/Elastic.Elasticsearch.Xunit/Elastic.Elasticsearch.Xunit.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
<PropertyGroup>
33
<TargetFrameworks>netstandard2.0;netstandard2.1;net462</TargetFrameworks>
44
<IsPackable>True</IsPackable>
5+
<IsTestProject>False</IsTestProject>
56
<Description>Provides an Xunit test framework allowing you to run integration tests against local ephemeral Elasticsearch clusters</Description>
67
<PackageTags>elastic,elasticsearch,xunit,cluster,integration,test,ephemeral</PackageTags>
78
</PropertyGroup>
89
<ItemGroup>
10+
<PackageReference Include="Nullean.Xunit.Partitions" Version="0.5.0" />
911
<PackageReference Include="xunit" Version="2.4.1" />
1012
</ItemGroup>
1113
<ItemGroup>

Diff for: src/Elastic.Elasticsearch.Xunit/ElasticXunitConfigurationAttribute.cs

+14-25
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,20 @@
33
// See the LICENSE file in the project root for more information
44

55
using System;
6+
using Nullean.Xunit.Partitions;
67

7-
namespace Elastic.Elasticsearch.Xunit
8-
{
9-
/// <summary>
10-
/// An assembly attribute that specifies the <see cref="ElasticXunitRunOptions" />
11-
/// for Xunit tests within the assembly.
12-
/// </summary>
13-
[AttributeUsage(AttributeTargets.Assembly)]
14-
public class ElasticXunitConfigurationAttribute : Attribute
15-
{
16-
/// <summary>
17-
/// Creates a new instance of <see cref="ElasticXunitConfigurationAttribute" />
18-
/// </summary>
19-
/// <param name="type">
20-
/// A type deriving from <see cref="ElasticXunitRunOptions" /> that specifies the run options
21-
/// </param>
22-
public ElasticXunitConfigurationAttribute(Type type)
23-
{
24-
var options = Activator.CreateInstance(type) as ElasticXunitRunOptions;
25-
Options = options ?? new ElasticXunitRunOptions();
26-
}
8+
namespace Elastic.Elasticsearch.Xunit;
279

28-
/// <summary>
29-
/// The run options
30-
/// </summary>
31-
public ElasticXunitRunOptions Options { get; }
32-
}
10+
/// <summary>
11+
/// An assembly attribute that specifies the <see cref="ElasticXunitRunOptions" />
12+
/// for Xunit tests within the assembly.
13+
/// </summary>
14+
[AttributeUsage(AttributeTargets.Assembly)]
15+
public class ElasticXunitConfigurationAttribute : PartitionOptionsAttribute
16+
{
17+
/// <summary>Creates a new instance of <see cref="ElasticXunitConfigurationAttribute" />.</summary>
18+
/// <param name="type">
19+
/// A type deriving from <see cref="ElasticXunitRunOptions" /> that specifies the run options
20+
/// </param>
21+
public ElasticXunitConfigurationAttribute(Type type) : base(type) { }
3322
}

Diff for: src/Elastic.Elasticsearch.Xunit/ElasticXunitRunOptions.cs

+68-20
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33
// See the LICENSE file in the project root for more information
44

55
using System;
6-
using System.Collections.Concurrent;
7-
using System.Collections.Generic;
8-
using System.Diagnostics;
6+
using System.Linq;
7+
using System.Runtime.Serialization;
98
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
109
using Elastic.Stack.ArtifactsApi;
10+
using Nullean.Xunit.Partitions;
11+
using Xunit.Abstractions;
12+
using static System.StringSplitOptions;
1113

1214
namespace Elastic.Elasticsearch.Xunit
1315
{
1416
/// <summary>
1517
/// The Xunit test runner options
1618
/// </summary>
17-
public class ElasticXunitRunOptions
19+
public class ElasticXunitRunOptions : PartitionOptions
1820
{
1921
/// <summary>
2022
/// Informs the runner whether we expect to run integration tests. Defaults to <c>true</c>
@@ -35,39 +37,85 @@ public class ElasticXunitRunOptions
3537
public bool RunUnitTests { get; set; }
3638

3739
/// <summary>
38-
/// A global test filter that can be used to only run certain tests.
40+
/// A global cluster filter that can be used to only run certain cluster's tests.
3941
/// Accepts a comma separated list of filters
4042
/// </summary>
41-
public string TestFilter { get; set; }
43+
[Obsolete("Use PartitionFilterRegex instead", false)]
44+
[IgnoreDataMember]
45+
public string ClusterFilter
46+
{
47+
get => PartitionFilterRegex;
48+
set
49+
{
50+
if (string.IsNullOrWhiteSpace(value)) PartitionFilterRegex = value;
51+
else
52+
{
53+
//attempt at being backwards compatible with old way of filtering
54+
var re = string.Join("|", value.Split(new[] { ','}, RemoveEmptyEntries).Select(s => s.Trim()));
55+
PartitionFilterRegex = re;
56+
}
57+
}
58+
}
4259

4360
/// <summary>
44-
/// A global cluster filter that can be used to only run certain cluster's tests.
61+
/// A global test filter that can be used to only run certain cluster's tests.
4562
/// Accepts a comma separated list of filters
4663
/// </summary>
47-
public string ClusterFilter { get; set; }
64+
[Obsolete("Use ParitionFilterRegex instead", false)]
65+
[IgnoreDataMember]
66+
public string TestFilter
67+
{
68+
get => TestFilterRegex;
69+
set
70+
{
71+
if (string.IsNullOrWhiteSpace(value)) TestFilterRegex = value;
72+
else
73+
{
74+
//attempt at being backwards compatible with old way of filtering
75+
var re = string.Join("|", value.Split(new[] { ','}, RemoveEmptyEntries).Select(s => s.Trim()));
76+
TestFilterRegex = re;
77+
}
78+
}
79+
}
4880

4981
/// <summary>
5082
/// Informs the runner what version of Elasticsearch is under test. Required for
5183
/// <see cref="SkipVersionAttribute" /> to kick in
5284
/// </summary>
5385
public ElasticVersion Version { get; set; }
5486

55-
/// <summary>
56-
/// Called when the tests have finished running successfully
57-
/// </summary>
58-
/// <param name="runnerClusterTotals">Per cluster timings of the total test time, including starting Elasticsearch</param>
59-
/// <param name="runnerFailedCollections">All collection of failed cluster, failed tests tuples</param>
60-
public virtual void OnTestsFinished(Dictionary<string, Stopwatch> runnerClusterTotals,
61-
ConcurrentBag<Tuple<string, string>> runnerFailedCollections)
87+
public override void SetOptions(ITestFrameworkDiscoveryOptions discoveryOptions)
6288
{
89+
base.SetOptions(discoveryOptions);
90+
discoveryOptions.SetValue(nameof(Version), Version);
91+
discoveryOptions.SetValue(nameof(RunIntegrationTests), RunIntegrationTests);
92+
discoveryOptions.SetValue(
93+
nameof(IntegrationTestsMayUseAlreadyRunningNode),
94+
IntegrationTestsMayUseAlreadyRunningNode
95+
);
96+
discoveryOptions.SetValue(nameof(RunUnitTests), RunUnitTests);
97+
#pragma warning disable CS0618 // Type or member is obsolete
98+
discoveryOptions.SetValue(nameof(TestFilter), TestFilter);
99+
discoveryOptions.SetValue(nameof(ClusterFilter), ClusterFilter);
100+
#pragma warning restore CS0618 // Type or member is obsolete
63101
}
64102

65-
/// <summary>
66-
/// Called before tests run. An ideal place to perform actions such as writing information to
67-
/// <see cref="Console" />.
68-
/// </summary>
69-
public virtual void OnBeforeTestsRun()
103+
public override void SetOptions(ITestFrameworkExecutionOptions executionOptions)
70104
{
105+
106+
base.SetOptions(executionOptions);
107+
executionOptions.SetValue(nameof(Version), Version);
108+
executionOptions.SetValue(nameof(RunIntegrationTests), RunIntegrationTests);
109+
executionOptions.SetValue(
110+
nameof(IntegrationTestsMayUseAlreadyRunningNode),
111+
IntegrationTestsMayUseAlreadyRunningNode
112+
);
113+
executionOptions.SetValue(nameof(RunUnitTests), RunUnitTests);
114+
#pragma warning disable CS0618 // Type or member is obsolete
115+
executionOptions.SetValue(nameof(TestFilter), TestFilter);
116+
executionOptions.SetValue(nameof(ClusterFilter), ClusterFilter);
117+
#pragma warning restore CS0618 // Type or member is obsolete
118+
71119
}
72120
}
73121
}

0 commit comments

Comments
 (0)