Skip to content

Commit

Permalink
Add tests for DeletePit
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia committed Oct 29, 2023
1 parent 1b71002 commit 78d301f
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
63 changes: 63 additions & 0 deletions tests/Tests/Search/PointInTime/DeletePitApiTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

using System;
using OpenSearch.Client;
using OpenSearch.Net;
using Tests.Core.ManagedOpenSearch.Clusters;
using Tests.Domain;
using Tests.Framework.EndpointTests;
using Tests.Framework.EndpointTests.TestState;

namespace Tests.Search.PointInTime;

// ReadOnlyCluster because eventhough its technically a write action it does not hinder
// on going reads
public class DeletePitApiTests
: ApiIntegrationTestBase<ReadOnlyCluster, DeletePitResponse, IDeletePitRequest, DeletePitDescriptor, DeletePitRequest>
{
private string _pitId = "default-for-unit-tests";

public DeletePitApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }

protected override bool ExpectIsValid => true;

protected override object ExpectJson => new
{
pit_ids = new[]
{
_pitId
}
};

protected override int ExpectStatusCode => 200;

protected override Func<DeletePitDescriptor, IDeletePitRequest> Fluent => d => d.PitIds(_pitId);
protected override HttpMethod HttpMethod => HttpMethod.DELETE;

protected override DeletePitRequest Initializer => new(_pitId);
protected override bool SupportsDeserialization => false;
protected override string UrlPath => "/_search/point_in_time";

protected override LazyResponses ClientUsage() => Calls(
(c, f) => c.DeletePit(f),
(c, f) => c.DeletePitAsync(f),
(c, r) => c.DeletePit(r),
(c, r) => c.DeletePitAsync(r)
);

protected override DeletePitDescriptor NewDescriptor() => new();

protected override void OnBeforeCall(IOpenSearchClient client)
{
var pit = Client.CreatePit(OpenSearch.Client.Indices.Index<Project>(), c => c.KeepAlive("1h"));
if (!pit.IsValid)
throw new Exception("Setup: Initial PIT failed.");

_pitId = pit.PitId ?? _pitId;
}
}
28 changes: 28 additions & 0 deletions tests/Tests/Search/PointInTime/DeletePitUrlTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

using System.Threading.Tasks;
using OpenSearch.Client;
using OpenSearch.OpenSearch.Xunit.XunitPlumbing;
using Tests.Framework.EndpointTests;
using static Tests.Framework.EndpointTests.UrlTester;

namespace Tests.Search.PointInTime;

public class DeletePitUrlTests
{
[U] public async Task Urls()
{
var pitIds = new[] { "pitid1", "pitid2" };

await DELETE("/_search/point_in_time")
.Fluent(c => c.DeletePit(d => d.PitIds(pitIds)))
.Request(c => c.DeletePit(new DeletePitRequest(pitIds)))
.FluentAsync(c => c.DeletePitAsync(d => d.PitIds(pitIds)))
.RequestAsync(c => c.DeletePitAsync(new DeletePitRequest(pitIds)));
}
}

0 comments on commit 78d301f

Please sign in to comment.