Skip to content

Commit 1a5312e

Browse files
committed
showcase #2328 intended behavior
1 parent 5030c4c commit 1a5312e

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Elasticsearch.Net;
5+
using FluentAssertions;
6+
using Nest;
7+
using Tests.Framework;
8+
using Tests.Framework.Integration;
9+
using Tests.Framework.MockData;
10+
using Xunit;
11+
12+
namespace Tests.Search.Search
13+
{
14+
public class InvalidSearchApiTests : SearchApiTests
15+
{
16+
public InvalidSearchApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
17+
18+
protected override bool ExpectIsValid => false;
19+
20+
protected override int ExpectStatusCode => 500;
21+
22+
protected override object ExpectJson => new
23+
{
24+
from = 10,
25+
size = 20,
26+
aggs = new
27+
{
28+
startDates = new
29+
{
30+
date_range = new
31+
{
32+
ranges = new[]
33+
{
34+
new { from = "-1m" }
35+
}
36+
}
37+
}
38+
}
39+
};
40+
41+
protected override Func<SearchDescriptor<Project>, ISearchRequest> Fluent => s => s
42+
.From(10)
43+
.Size(20)
44+
.Aggregations(a => a
45+
.DateRange("startDates", t => t
46+
.Ranges(ranges => ranges.From("-1m"))
47+
)
48+
);
49+
50+
protected override SearchRequest<Project> Initializer => new SearchRequest<Project>()
51+
{
52+
From = 10,
53+
Size = 20,
54+
Aggregations = new DateRangeAggregation("startDates")
55+
{
56+
Ranges = new List<DateRangeExpression>
57+
{
58+
new DateRangeExpression { From = "-1m" }
59+
}
60+
}
61+
};
62+
63+
/// </summary>
64+
/// <param name="response"></param>
65+
protected override void ExpectResponse(ISearchResponse<Project> response)
66+
{
67+
response.IsValid.Should().BeFalse();
68+
var serverError = response.ServerError;
69+
serverError.Should().NotBeNull();
70+
serverError.Status.Should().Be(500);
71+
serverError.Error.Reason.Should().Be("all shards failed");
72+
serverError.Error.RootCause.First().Reason.Should().Contain("[startDates]");
73+
74+
}
75+
}
76+
}

src/Tests/Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@
602602
<Compile Include="Reproduce\GithubIssue2173.cs" />
603603
<Compile Include="Reproduce\DateSerialization.cs" />
604604
<Compile Include="Search\Search\Rescoring\RescoreUsageTests.cs" />
605+
<Compile Include="Search\Search\InvalidSearchApiTests.cs" />
605606
<Compile Include="XPack\Security\ClearCachedRealms\ClearCachedRealmsApiTests.cs" />
606607
<Compile Include="XPack\Security\ClearCachedRealms\ClearCachedRealmsUrlTests.cs" />
607608
<Compile Include="XPack\Security\Role\ClearCachedRoles\ClearCachedRolesApiTests.cs" />

0 commit comments

Comments
 (0)