Skip to content

Commit

Permalink
Remove tests for _type validation in mapping APIs as it was removed…
Browse files Browse the repository at this point in the history
… from `OpenSearch`.

Ref: opensearch-project/OpenSearch#2238 opensearch-project/OpenSearch#2480

Signed-off-by: Yury Fridlyand <yuryf@bitquilltech.com>
  • Loading branch information
Yury-Fridlyand committed Jun 9, 2022
1 parent e481bbd commit a021357
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public bool IsValid
{
get
{
if (Error != null || Type.IsNullOrEmpty()) return false;
if (Error != null) return false;

switch (Operation.ToLowerInvariant())
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Tests.Reproduce/GithubIssue2306.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public void DeleteNonExistentDocumentReturnsNotFound()
response.ShouldNotBeValid();
response.Result.Should().Be(Result.NotFound);
response.Index.Should().Be("project");
response.Type.Should().Be("doc");
if (_cluster.ClusterConfiguration.Version < "2.0.0")
response.Type.Should().Be("doc");
response.Id.Should().Be("non-existent-id");
}
}
Expand Down
6 changes: 4 additions & 2 deletions tests/Tests.Reproduce/GithubIssue2871.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,16 @@ public void IsValidFalseAndDeserializedErrorsWhenMultiGetDocHasErrors()
var firstMultiGetHit = response.Hits.First();
firstMultiGetHit.Error.Should().NotBeNull();
firstMultiGetHit.Error.Should().NotBeNull();
firstMultiGetHit.Error.Type.Should().NotBeNullOrEmpty();
if (_cluster.ClusterConfiguration.Version < "2.0.0")
firstMultiGetHit.Error.Type.Should().NotBeNullOrEmpty();
firstMultiGetHit.Error.Reason.Should().NotBeNullOrEmpty();
firstMultiGetHit.Error.RootCause.Should().NotBeNull().And.HaveCount(1);

var lastMultiGetHit = response.Hits.Last();
lastMultiGetHit.Error.Should().NotBeNull();
lastMultiGetHit.Error.Should().NotBeNull();
lastMultiGetHit.Error.Type.Should().NotBeNullOrEmpty();
if (_cluster.ClusterConfiguration.Version < "2.0.0")
lastMultiGetHit.Error.Type.Should().NotBeNullOrEmpty();
lastMultiGetHit.Error.Reason.Should().NotBeNullOrEmpty();
lastMultiGetHit.Error.RootCause.Should().NotBeNull().And.HaveCount(1);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Tests/Document/Multiple/Bulk/BulkApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ protected override void ExpectResponse(BulkResponse response)
foreach (var item in response.Items)
{
item.Index.Should().Be(CallIsolatedValue);
item.Type.Should().Be("_doc");
if (Cluster.ClusterConfiguration.Version < "2.0.0")
item.Type.Should().Be("_doc");
item.Status.Should().BeGreaterThan(100);
item.Version.Should().BeGreaterThan(0);
item.Id.Should().NotBeNullOrWhiteSpace();
Expand Down
16 changes: 12 additions & 4 deletions tests/Tests/Document/Multiple/MultiGet/GetManyApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@ namespace Tests.Document.Multiple.MultiGet
public class GetManyApiTests : IClusterFixture<WritableCluster>
{
private readonly IOpenSearchClient _client;
private readonly WritableCluster _cluster;
private readonly IEnumerable<long> _ids = Developer.Developers.Select(d => d.Id).Take(10);

public GetManyApiTests(WritableCluster cluster) => _client = cluster.Client;
public GetManyApiTests(WritableCluster cluster)
{
_client = cluster.Client;
_cluster = cluster;
}

[I] public void UsesDefaultIndexAndInferredType()
{
Expand All @@ -54,7 +59,8 @@ [I] public void UsesDefaultIndexAndInferredType()
foreach (var hit in response)
{
hit.Index.Should().NotBeNullOrWhiteSpace();
hit.Type.Should().NotBeNullOrWhiteSpace();
if (_cluster.ClusterConfiguration.Version < "2.0.0")
hit.Type.Should().NotBeNullOrWhiteSpace();
hit.Id.Should().NotBeNullOrWhiteSpace();
hit.Found.Should().BeTrue();
}
Expand All @@ -67,7 +73,8 @@ [I] public async Task UsesDefaultIndexAndInferredTypeAsync()
foreach (var hit in response)
{
hit.Index.Should().NotBeNullOrWhiteSpace();
hit.Type.Should().NotBeNullOrWhiteSpace();
if (_cluster.ClusterConfiguration.Version < "2.0.0")
hit.Type.Should().NotBeNullOrWhiteSpace();
hit.Id.Should().NotBeNullOrWhiteSpace();
hit.Found.Should().BeTrue();
}
Expand Down Expand Up @@ -203,7 +210,8 @@ [I] public async Task CanHandleNotFoundResponses()
foreach (var hit in response)
{
hit.Index.Should().NotBeNullOrWhiteSpace();
hit.Type.Should().NotBeNullOrWhiteSpace();
if (_cluster.ClusterConfiguration.Version < "2.0.0")
hit.Type.Should().NotBeNullOrWhiteSpace();
hit.Id.Should().NotBeNullOrWhiteSpace();
hit.Found.Should().BeFalse();
}
Expand Down
12 changes: 8 additions & 4 deletions tests/Tests/Document/Multiple/MultiGet/MultiGetApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ protected override void ExpectResponse(MultiGetResponse response)
foreach (var document in response.Hits)
{
document.Index.Should().NotBeNullOrWhiteSpace();
document.Type.Should().NotBeNullOrWhiteSpace();
if (Cluster.ClusterConfiguration.Version < "2.0.0")
document.Type.Should().NotBeNullOrWhiteSpace();
document.Id.Should().NotBeNullOrWhiteSpace();
document.Found.Should().BeTrue();
}
Expand Down Expand Up @@ -135,7 +136,8 @@ protected override void ExpectResponse(MultiGetResponse response)
foreach (var hit in response.Hits)
{
hit.Index.Should().NotBeNullOrWhiteSpace();
hit.Type.Should().NotBeNullOrWhiteSpace();
if (Cluster.ClusterConfiguration.Version < "2.0.0")
hit.Type.Should().NotBeNullOrWhiteSpace();
hit.Id.Should().NotBeNullOrWhiteSpace();
hit.Found.Should().BeTrue();
}
Expand Down Expand Up @@ -191,7 +193,8 @@ protected override void ExpectResponse(MultiGetResponse response)
foreach (var hit in response.GetMany<Project>(_ids))
{
hit.Index.Should().NotBeNullOrWhiteSpace();
hit.Type.Should().NotBeNullOrWhiteSpace();
if (Cluster.ClusterConfiguration.Version < "2.0.0")
hit.Type.Should().NotBeNullOrWhiteSpace();
hit.Id.Should().NotBeNullOrWhiteSpace();
hit.Found.Should().BeTrue();
hit.Version.Should().Be(1);
Expand Down Expand Up @@ -246,7 +249,8 @@ protected override void ExpectResponse(MultiGetResponse response)
foreach (var hit in response.GetMany<CommitActivity>(_activities.Select(c => c.Id)))
{
hit.Index.Should().NotBeNullOrWhiteSpace();
hit.Type.Should().NotBeNullOrWhiteSpace();
if (Cluster.ClusterConfiguration.Version < "2.0.0")
hit.Type.Should().NotBeNullOrWhiteSpace();
hit.Id.Should().NotBeNullOrWhiteSpace();
hit.Found.Should().BeTrue();
hit.Version.Should().Be(1);
Expand Down
9 changes: 6 additions & 3 deletions tests/Tests/Document/Single/Create/CreateApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ public void CreateWithSameIndexTypeAndId()
createResponse.ApiCall.HttpStatusCode.Should().Be(201);
createResponse.Result.Should().Be(Result.Created);
createResponse.Index.Should().Be(index);
createResponse.Type.Should().Be("_doc");
if (Cluster.ClusterConfiguration.Version < "2.0.0")
createResponse.Type.Should().Be("_doc");
createResponse.Id.Should().Be(project.Name);

createResponse.Shards.Should().NotBeNull();
Expand Down Expand Up @@ -180,7 +181,8 @@ public void Create()
createResponse.ApiCall.HttpStatusCode.Should().Be(201);
createResponse.Result.Should().Be(Result.Created);
createResponse.Index.Should().Be(index);
createResponse.Type.Should().Be("_doc");
if (Cluster.ClusterConfiguration.Version < "2.0.0")
createResponse.Type.Should().Be("_doc");

var bulkResponse = Client.Bulk(b => b
.Index(index)
Expand Down Expand Up @@ -226,7 +228,8 @@ [I] public void Create()
createResponse.ApiCall.HttpStatusCode.Should().Be(201);
createResponse.Index.Should().Be(index);
createResponse.Result.Should().Be(Result.Created);
createResponse.Type.Should().StartWith("_doc");
if (Cluster.ClusterConfiguration.Version < "2.0.0")
createResponse.Type.Should().StartWith("_doc");
}
}
}
3 changes: 2 additions & 1 deletion tests/Tests/Document/Single/Delete/DeleteApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ protected override void ExpectResponse(DeleteResponse response)
response.ShouldNotBeValid();
response.Result.Should().Be(Result.NotFound);
response.Index.Should().Be("project");
response.Type.Should().Be("_doc");
if (Cluster.ClusterConfiguration.Version < "2.0.0")
response.Type.Should().Be("_doc");
response.Id.Should().Be(CallIsolatedValue);
response.Shards.Total.Should().BeGreaterOrEqualTo(1);
response.Shards.Successful.Should().BeGreaterOrEqualTo(1);
Expand Down
6 changes: 4 additions & 2 deletions tests/Tests/Document/Single/DocumentCrudTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,16 @@ protected override async Task GetAfterDeleteIsValid() => await AssertOnGetAfterD
{
r.ShouldNotBeValid();
r.Index.Should().NotBeNullOrEmpty();
r.Type.Should().NotBeNullOrEmpty();
if (Cluster.ClusterConfiguration.Version < "2.0.0")
r.Type.Should().NotBeNullOrEmpty();
r.Id.Should().NotBeNullOrEmpty();
});

protected override void ExpectDeleteNotFoundResponse(DeleteResponse response)
{
response.Index.Should().NotBeNullOrEmpty();
response.Type.Should().NotBeNullOrEmpty();
if (Cluster.ClusterConfiguration.Version < "2.0.0")
response.Type.Should().NotBeNullOrEmpty();
response.Id.Should().NotBeNullOrEmpty();
response.Version.Should().BeGreaterThan(0);
response.SequenceNumber.Should().BeGreaterThan(0);
Expand Down
3 changes: 2 additions & 1 deletion tests/Tests/Document/Single/Get/GetApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ protected override void ExpectResponse(GetResponse<Project> response)
{
response.Found.Should().BeFalse();
response.Index.Should().Be("project");
response.Type.Should().Be("_doc");
if (Cluster.ClusterConfiguration.Version < "2.0.0")
response.Type.Should().Be("_doc");
response.Id.Should().Be(CallIsolatedValue);
}
}
Expand Down
12 changes: 8 additions & 4 deletions tests/Tests/Document/Single/Index/IndexApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ [I] public void OpTypeCreate()
indexResult.ApiCall.HttpStatusCode.Should().Be(201);
indexResult.Result.Should().Be(Result.Created);
indexResult.Index.Should().Be(indexName);
indexResult.Type.Should().Be("_doc");
if (Cluster.ClusterConfiguration.Version < "2.0.0")
indexResult.Type.Should().Be("_doc");
indexResult.Id.Should().Be(project.Name);

indexResult = Client.Index(project, f => f
Expand All @@ -152,7 +153,8 @@ public void Index()
indexResult.ApiCall.HttpStatusCode.Should().Be(201);
indexResult.Result.Should().Be(Result.Created);
indexResult.Index.Should().Be(indexName);
indexResult.Type.Should().Be("_doc");
if (Cluster.ClusterConfiguration.Version < "2.0.0")
indexResult.Type.Should().Be("_doc");
indexResult.Id.Should().Be(commitActivity.Id);
indexResult.Version.Should().Be(1);
indexResult.Shards.Should().NotBeNull();
Expand Down Expand Up @@ -207,7 +209,8 @@ public void Index()
indexResult.ApiCall.HttpStatusCode.Should().Be(201);
indexResult.Result.Should().Be(Result.Created);
indexResult.Index.Should().Be(index);
indexResult.Type.Should().Be("_doc");
if (Cluster.ClusterConfiguration.Version < "2.0.0")
indexResult.Type.Should().Be("_doc");
indexResult.Shards.Should().NotBeNull();
indexResult.Shards.Total.Should().BeGreaterOrEqualTo(1);
indexResult.Shards.Successful.Should().BeGreaterOrEqualTo(1);
Expand Down Expand Up @@ -263,7 +266,8 @@ [I] public void Index()
indexResult.ApiCall.HttpStatusCode.Should().Be(201);
indexResult.Result.Should().Be(Result.Created);
indexResult.Index.Should().Be(index);
indexResult.Type.Should().StartWith("_doc");
if (Cluster.ClusterConfiguration.Version < "2.0.0")
indexResult.Type.Should().StartWith("_doc");
indexResult.Shards.Should().NotBeNull();
indexResult.Shards.Total.Should().BeGreaterOrEqualTo(1);
indexResult.Shards.Successful.Should().BeGreaterOrEqualTo(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
using Tests.Framework.EndpointTests;
using Tests.Framework.EndpointTests.TestState;
using static OpenSearch.Client.Infer;
using OpenSearch.OpenSearch.Xunit.XunitPlumbing;

namespace Tests.Indices.IndexManagement.TypesExists
{
[SkipVersion(">=2.0.0", "Type Mapping API was removed from OpenSearch 2.0")]
public class TypeExistsApiTests
: ApiIntegrationTestBase<ReadOnlyCluster, ExistsResponse, ITypeExistsRequest, TypeExistsDescriptor, TypeExistsRequest>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public class MultiSearchLowLevelPostDataTests : IClusterFixture<ReadOnlyCluster>
new { from = 0, size = 10, query = new { match_all = new { } } },
new { search_type = "query_then_fetch" },
new { },
new { index = "devs", type = "developer" },
new { index = "devs" },
new { from = 0, size = 5, query = new { match_all = new { } } },
new { index = "devs", type = "developer" },
new { index = "devs" },
new { from = 0, size = 5, query = new { match_all = new { } } }
}.ToList();

Expand Down
3 changes: 2 additions & 1 deletion tests/Tests/Search/Search/SearchApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ protected override void ExpectResponse(ISearchResponse<Project> response)
response.HitsMetadata.Should().NotBeNull();
response.Hits.Count().Should().BeGreaterThan(0);
response.Hits.First().Should().NotBeNull();
response.Hits.First().Type.Should().NotBeNullOrWhiteSpace();
if (Cluster.ClusterConfiguration.Version < "2.0.0")
response.Hits.First().Type.Should().NotBeNullOrWhiteSpace();
response.Hits.First().Fields.ValueOf<Project, string>(p => p.Name).Should().NotBeNullOrEmpty();
var lastActivityYear = Convert.ToInt32(response.Hits.First().Fields.Value<string>("lastActivity"));
lastActivityYear.Should().BeGreaterThan(0);
Expand Down

0 comments on commit a021357

Please sign in to comment.