Skip to content

Commit

Permalink
Add tests for CreatePit
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia committed Oct 27, 2023
1 parent c30d9c4 commit 1b71002
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tests/Tests/Search/PointInTime/CreatePitApiTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* 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 FluentAssertions;
using OpenSearch.Client;
using OpenSearch.Net;
using Tests.Core.ManagedOpenSearch.Clusters;
using Tests.Framework.EndpointTests;
using Tests.Framework.EndpointTests.TestState;

namespace Tests.Search.PointInTime;

public class CreatePitApiTests
: ApiIntegrationTestBase<WritableCluster, CreatePitResponse, ICreatePitRequest, CreatePitDescriptor, CreatePitRequest>
{
public CreatePitApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { }

protected override bool ExpectIsValid => true;

protected override object ExpectJson => null;

protected override int ExpectStatusCode => 200;

protected override Func<CreatePitDescriptor, ICreatePitRequest> Fluent => e => e
.KeepAlive("1h");

protected override HttpMethod HttpMethod => HttpMethod.POST;

protected override CreatePitRequest Initializer => new(CallIsolatedValue)
{
KeepAlive = "1h"
};

protected override bool SupportsDeserialization => false;

protected override string UrlPath =>
$"/{CallIsolatedValue}/_search/point_in_time?keep_alive=1h";

protected override LazyResponses ClientUsage() => Calls(
(c, f) => c.CreatePit(CallIsolatedValue, f),
(c, f) => c.CreatePitAsync(CallIsolatedValue, f),
(c, r) => c.CreatePit(r),
(c, r) => c.CreatePitAsync(r)
);

protected override CreatePitDescriptor NewDescriptor() => new(CallIsolatedValue);

protected override void ExpectResponse(CreatePitResponse response)
{
response.IsValid.Should().BeTrue();
response.PitId.Should().NotBeNullOrEmpty();
response.CreationTime.Should().BeCloseTo(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), 10000);
response.Shards.Should().NotBeNull();
}
}
30 changes: 30 additions & 0 deletions tests/Tests/Search/PointInTime/CreatePitUrlTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* 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 CreatePitUrlTests
{
[U] public async Task Urls()
{
const string index = "temp";
const string keepAlive = "1h";

await POST($"/{index}/_search/point_in_time?keep_alive={keepAlive}")
.Fluent(c => c.CreatePit(index, c => c.KeepAlive(keepAlive)))
.Request(c => c.CreatePit(new CreatePitRequest(index) { KeepAlive = keepAlive }))
.FluentAsync(c => c.CreatePitAsync(index, c => c.KeepAlive(keepAlive)))
.RequestAsync(c => c.CreatePitAsync(new CreatePitRequest(index) { KeepAlive = keepAlive }))
;
}
}

0 comments on commit 1b71002

Please sign in to comment.