Skip to content

Commit d4acecb

Browse files
committed
fixed global integration test setup by ignoreing ranges on project mock type if we are running tests below 5.2.0, ignored properties where they made sense
1 parent 5f3fb87 commit d4acecb

File tree

16 files changed

+60
-16
lines changed

16 files changed

+60
-16
lines changed

src/Tests/Framework/EndpointTests/Bootstrappers/Seeder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ public static IAnalysis ProjectAnalysisSettings(AnalysisDescriptor analysis)
159159
.Tokenizer("standard")
160160
)
161161
);
162-
if (new SemVer.Range(">=5.2.0").IsSatisfied(TestClient.Configuration.ElasticsearchVersion))
162+
//normalizers are a new feature since 5.2.0
163+
if (TestClient.VersionUnderTestSatisfiedBy(">=5.2.0"))
163164
analysis.Normalizers(analyzers => analyzers
164165
.Custom("my_normalizer", n => n
165166
.Filters("lowercase", "asciifolding")

src/Tests/Framework/TestClient.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ private static ITestConfiguration LoadConfiguration()
5555
private static ConnectionSettings DefaultSettings(ConnectionSettings settings) => settings
5656
.DefaultIndex("default-index")
5757
.PrettyJson()
58-
.InferMappingFor<Project>(map => map
59-
.IndexName("project")
60-
.IdProperty(p => p.Name)
61-
)
58+
.InferMappingFor<Project>(ProjectMapping)
6259
.InferMappingFor<CommitActivity>(map => map
6360
.IndexName("project")
6461
.TypeName("commits")
@@ -79,6 +76,18 @@ private static ConnectionSettings DefaultSettings(ConnectionSettings settings) =
7976

8077
.OnRequestDataCreated(data=> data.Headers.Add("TestMethod", ExpensiveTestNameForIntegrationTests()));
8178

79+
private static IClrTypeMapping<Project> ProjectMapping(ClrTypeMappingDescriptor<Project> m)
80+
{
81+
m.IndexName("project").IdProperty(p => p.Name);
82+
//*_range type only available since 5.2.0
83+
if (VersionUnderTestSatisfiedBy("<5.2.0"))
84+
m.Ignore(p => p.Ranges);
85+
return m;
86+
}
87+
88+
public static bool VersionUnderTestSatisfiedBy(string versionRange) =>
89+
new SemVer.Range(versionRange).IsSatisfied(TestClient.Configuration.ElasticsearchVersion);
90+
8291
public static string PercolatorType => Configuration.ElasticsearchVersion <= new ElasticsearchVersion("5.0.0-alpha1") ? ".percolator" : "query";
8392

8493

src/Tests/Indices/MappingManagement/GetMapping/GetMappingApiTest.cs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
namespace Tests.Indices.MappingManagement.GetMapping
1313
{
14-
public class GetMappingApiTests : ApiIntegrationTestBase<ReadOnlyCluster, IGetMappingResponse, IGetMappingRequest, GetMappingDescriptor<Project>, GetMappingRequest>
14+
public class GetMappingApiTests : ApiIntegrationTestBase<ReadOnlyCluster, IGetMappingResponse, IGetMappingRequest, GetMappingDescriptor<Project>,
15+
GetMappingRequest>
1516
{
1617
public GetMappingApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
1718

@@ -43,7 +44,9 @@ protected override void ExpectResponse(IGetMappingResponse response)
4344
response.Accept(visitor);
4445

4546
visitor.CountsShouldContainKeyAndCountBe("type", 1);
46-
visitor.CountsShouldContainKeyAndCountBe("object", 5);
47+
//ranges property is ignored on versions before 5.2.0
48+
var supportsRanges = TestClient.VersionUnderTestSatisfiedBy(">=5.2.0");
49+
visitor.CountsShouldContainKeyAndCountBe("object", supportsRanges ? 5 : 4);
4750
visitor.CountsShouldContainKeyAndCountBe("date", 4);
4851
visitor.CountsShouldContainKeyAndCountBe("text", 11);
4952
visitor.CountsShouldContainKeyAndCountBe("keyword", 9);
@@ -52,19 +55,25 @@ protected override void ExpectResponse(IGetMappingResponse response)
5255
visitor.CountsShouldContainKeyAndCountBe("geo_point", 2);
5356
visitor.CountsShouldContainKeyAndCountBe("completion", 2);
5457
visitor.CountsShouldContainKeyAndCountBe("nested", 1);
55-
visitor.CountsShouldContainKeyAndCountBe("date_range", 1);
56-
visitor.CountsShouldContainKeyAndCountBe("float_range", 1);
57-
visitor.CountsShouldContainKeyAndCountBe("integer_range", 1);
58-
visitor.CountsShouldContainKeyAndCountBe("double_range", 1);
59-
visitor.CountsShouldContainKeyAndCountBe("long_range", 1);
58+
if (supportsRanges)
59+
{
60+
visitor.CountsShouldContainKeyAndCountBe("date_range", 1);
61+
visitor.CountsShouldContainKeyAndCountBe("float_range", 1);
62+
visitor.CountsShouldContainKeyAndCountBe("integer_range", 1);
63+
visitor.CountsShouldContainKeyAndCountBe("double_range", 1);
64+
visitor.CountsShouldContainKeyAndCountBe("long_range", 1);
65+
}
6066
}
6167
}
6268

63-
public class GetMappingNonExistentIndexApiTests : ApiIntegrationTestBase<ReadOnlyCluster, IGetMappingResponse, IGetMappingRequest, GetMappingDescriptor<Project>, GetMappingRequest>
69+
public class GetMappingNonExistentIndexApiTests : ApiIntegrationTestBase<ReadOnlyCluster, IGetMappingResponse, IGetMappingRequest,
70+
GetMappingDescriptor<Project>, GetMappingRequest>
6471
{
6572
private string _nonExistentIndex = "non-existent-index";
6673

67-
public GetMappingNonExistentIndexApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
74+
public GetMappingNonExistentIndexApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage)
75+
{
76+
}
6877

6978
protected override LazyResponses ClientUsage() => Calls(
7079
fluent: (client, f) => client.GetMapping<Project>(f),
@@ -122,11 +131,14 @@ public void CountsShouldContainKeyAndCountBe(string key, int count)
122131
}
123132

124133
#pragma warning disable 618
134+
125135
public void Visit(IStringProperty mapping)
126136
{
127137
Increment("string");
128138
}
139+
129140
#pragma warning restore 618
141+
130142
public void Visit(IDateProperty mapping)
131143
{
132144
Increment("date");

src/Tests/Indices/MappingManagement/PutMapping/PutMappingApiTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace Tests.Indices.MappingManagement.PutMapping
1111
{
12+
[SkipVersion("<5.2.0", "This uses the range types introduced in 5.2.0")]
1213
public class PutMappingApiTests
1314
: ApiIntegrationAgainstNewIndexTestBase
1415
<WritableCluster, IPutMappingResponse, IPutMappingRequest, PutMappingDescriptor<Project>, PutMappingRequest<Project>>

src/Tests/Mapping/Types/Core/Keyword/KeywordPropertyTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Tests.Mapping.Types.Core.Keyword
1010
{
11+
[SkipVersion("<5.2.0", "This uses the normalizer feature introduced in 5.2.0")]
1112
public class KeywordPropertyTests : PropertyTestsBase
1213
{
1314
public KeywordPropertyTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { }

src/Tests/Mapping/Types/Core/Range/DateRange/DateRangeAttributeTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Reflection;
22
using Nest;
3+
using Tests.Framework;
34

45
namespace Tests.Mapping.Types.Core.Range.DateRange
56
{
@@ -9,6 +10,7 @@ public class DateRangeTest
910
public Nest.DateRange Range { get; set; }
1011
}
1112

13+
[SkipVersion("<5.2.0", "dedicated range types is a new 5.2.0 feature")]
1214
public class DateRangeAttributeTests : AttributeTestsBase<DateRangeTest>
1315
{
1416
protected override object ExpectJson => new

src/Tests/Mapping/Types/Core/Range/DateRange/DateRangePropertyTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
22
using Nest;
3+
using Tests.Framework;
34
using Tests.Framework.Integration;
45
using Tests.Framework.MockData;
56

67
namespace Tests.Mapping.Types.Core.Range.DateRange
78
{
9+
[SkipVersion("<5.2.0", "dedicated range types is a new 5.2.0 feature")]
810
public class DateRangePropertyTests : PropertyTestsBase
911
{
1012
private DateTime _nullValue = new DateTime(2000, 1, 1, 1, 1, 1, 1, DateTimeKind.Utc);

src/Tests/Mapping/Types/Core/Range/DoubleRange/DoubleRangeAttributeTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Nest;
2+
using Tests.Framework;
23

34
namespace Tests.Mapping.Types.Core.Range.DoubleRange
45
{
@@ -8,6 +9,7 @@ public class DoubleRangeTest
89
public Nest.DoubleRange Range { get; set; }
910
}
1011

12+
[SkipVersion("<5.2.0", "dedicated range types is a new 5.2.0 feature")]
1113
public class DoubleRangeAttributeTests : AttributeTestsBase<DoubleRangeTest>
1214
{
1315
protected override object ExpectJson => new

src/Tests/Mapping/Types/Core/Range/DoubleRange/DoubleRangePropertyTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
22
using Nest;
3+
using Tests.Framework;
34
using Tests.Framework.Integration;
45
using Tests.Framework.MockData;
56

67
namespace Tests.Mapping.Types.Core.Range.DoubleRange
78
{
9+
[SkipVersion("<5.2.0", "dedicated range types is a new 5.2.0 feature")]
810
public class DoubleRangePropertyTests : PropertyTestsBase
911
{
1012
public DoubleRangePropertyTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { }

src/Tests/Mapping/Types/Core/Range/FloatRange/FloatRangeAttributeTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Nest;
2+
using Tests.Framework;
23

34
namespace Tests.Mapping.Types.Core.Range.FloatRange
45
{
@@ -8,6 +9,7 @@ public class FloatRangeTest
89
public Nest.FloatRange Range { get; set; }
910
}
1011

12+
[SkipVersion("<5.2.0", "dedicated range types is a new 5.2.0 feature")]
1113
public class FloatRangeAttributeTests : AttributeTestsBase<FloatRangeTest>
1214
{
1315
protected override object ExpectJson => new

0 commit comments

Comments
 (0)