Skip to content

Commit 31addfe

Browse files
committed
add skipversion, eventhough this API existed it was undocumented prior to 5.4
Conflicts: src/Tests/Document/Single/SourceExists/SourceExistsApiTests.cs
1 parent 90b39c4 commit 31addfe

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Elasticsearch.Net;
4+
using FluentAssertions;
5+
using Nest;
6+
using Tests.Framework;
7+
using Tests.Framework.Integration;
8+
using Tests.Framework.ManagedElasticsearch.Clusters;
9+
using Tests.Framework.ManagedElasticsearch.NodeSeeders;
10+
using Tests.Framework.MockData;
11+
using Xunit;
12+
13+
using static Nest.Infer;
14+
15+
namespace Tests.Document.Single.SourceExists
16+
{
17+
[SkipVersion("<5.4.0", "API was documented from 5.4.0 and over")]
18+
public class SourceExistsApiTests : ApiIntegrationTestBase<WritableCluster, IExistsResponse, ISourceExistsRequest, SourceExistsDescriptor<Project>, SourceExistsRequest<Project>>
19+
{
20+
public SourceExistsApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
21+
22+
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
23+
{
24+
foreach (var id in values.Values)
25+
this.Client.Index(Project.Instance, i=>i.Id(id));
26+
}
27+
28+
protected override LazyResponses ClientUsage() => Calls(
29+
fluent: (client, f) => client.SourceExists<Project>(CallIsolatedValue),
30+
fluentAsync: (client, f) => client.SourceExistsAsync<Project>(CallIsolatedValue),
31+
request: (client, r) => client.SourceExists(r),
32+
requestAsync: (client, r) => client.SourceExistsAsync(r)
33+
);
34+
35+
protected override bool ExpectIsValid => true;
36+
protected override int ExpectStatusCode => 200;
37+
protected override HttpMethod HttpMethod => HttpMethod.HEAD;
38+
protected override string UrlPath => $"/project/project/{CallIsolatedValue}/_source";
39+
40+
protected override bool SupportsDeserialization => false;
41+
42+
protected override Func<SourceExistsDescriptor<Project>, ISourceExistsRequest> Fluent => null;
43+
protected override SourceExistsRequest<Project> Initializer => new SourceExistsRequest<Project>(CallIsolatedValue);
44+
}
45+
public class SourceExistsNotFoundApiTests : ApiIntegrationTestBase<WritableCluster, IExistsResponse, ISourceExistsRequest, SourceExistsDescriptor<Project>, SourceExistsRequest<Project>>
46+
{
47+
public SourceExistsNotFoundApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
48+
49+
private static IndexName IndexWithNoSource { get; } = "project-with-no-source";
50+
private static DocumentPath<Project> Doc(string id) => new DocumentPath<Project>(id).Index(IndexWithNoSource);
51+
52+
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
53+
{
54+
var index = client.CreateIndex(IndexWithNoSource, i=>i
55+
.Mappings(m=>m
56+
.Map<Project>(mm=>mm
57+
.SourceField(sf=>sf.Enabled(false))
58+
)
59+
)
60+
);
61+
index.IsValid.Should().BeTrue(index.DebugInformation);
62+
63+
foreach (var id in values.Values)
64+
this.Client.Index(Project.Instance, i=>i.Id(id).Index(IndexWithNoSource));
65+
}
66+
67+
protected override LazyResponses ClientUsage() => Calls(
68+
fluent: (client, f) => client.SourceExists<Project>(Doc(CallIsolatedValue)),
69+
fluentAsync: (client, f) => client.SourceExistsAsync<Project>(Doc(CallIsolatedValue)),
70+
request: (client, r) => client.SourceExists(r),
71+
requestAsync: (client, r) => client.SourceExistsAsync(r)
72+
);
73+
74+
protected override bool ExpectIsValid => false;
75+
protected override int ExpectStatusCode => 404;
76+
protected override HttpMethod HttpMethod => HttpMethod.HEAD;
77+
protected override string UrlPath => $"/{IndexWithNoSource.Name}/project/{CallIsolatedValue}/_source";
78+
79+
protected override bool SupportsDeserialization => false;
80+
81+
protected override Func<SourceExistsDescriptor<Project>, ISourceExistsRequest> Fluent => null;
82+
protected override SourceExistsRequest<Project> Initializer => new SourceExistsRequest<Project>(Doc(CallIsolatedValue));
83+
}
84+
}

0 commit comments

Comments
 (0)