Skip to content

Commit 7898e9c

Browse files
committed
Make ListTasks the target call for OpaqueId
Will allow the list tasks response to be written out in the event of a failed assertion
1 parent 05b91a8 commit 7898e9c

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

src/Tests/Tests/Search/Search/SearchApiTests.cs

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ protected override void ExpectResponse(ISearchResponse<Project> response)
357357

358358

359359
[SkipVersion("<6.2.0", "OpaqueId introduced in 6.2.0")]
360-
public class OpaqueIdApiTests : ApiIntegrationTestBase<ReadOnlyCluster, ISearchResponse<Project>, ISearchRequest, SearchDescriptor<Project>, SearchRequest<Project>>
360+
public class OpaqueIdApiTests : ApiIntegrationTestBase<ReadOnlyCluster, IListTasksResponse, IListTasksRequest, ListTasksDescriptor, ListTasksRequest>
361361
{
362362
public OpaqueIdApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
363363

@@ -368,42 +368,47 @@ public OpaqueIdApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(clu
368368
protected override HttpMethod HttpMethod => HttpMethod.POST;
369369
protected override string UrlPath => $"/project/doc/_search?scroll=10m";
370370

371-
protected override Func<SearchDescriptor<Project>, ISearchRequest> Fluent => s => s
372-
.RequestConfiguration(r => r.OpaqueId(CallIsolatedValue))
373-
.Scroll("10m"); // Create a scroll in order to keep the task around.
371+
protected override Func<ListTasksDescriptor, IListTasksRequest> Fluent => s => s
372+
.RequestConfiguration(r => r.OpaqueId(CallIsolatedValue));
374373

375-
protected override SearchRequest<Project> Initializer => new SearchRequest<Project>()
374+
protected override ListTasksRequest Initializer => new ListTasksRequest()
376375
{
377376
RequestConfiguration = new RequestConfiguration { OpaqueId = CallIsolatedValue },
378-
Scroll = "10m"
379377
};
380378

381379
protected override LazyResponses ClientUsage() => Calls(
382-
fluent: (c, f) => c.Search(f),
383-
fluentAsync: (c, f) => c.SearchAsync(f),
384-
request: (c, r) => c.Search<Project>(r),
385-
requestAsync: (c, r) => c.SearchAsync<Project>(r)
380+
fluent: (c, f) => c.ListTasks(f),
381+
fluentAsync: (c, f) => c.ListTasksAsync(f),
382+
request: (c, r) => c.ListTasks(r),
383+
requestAsync: (c, r) => c.ListTasksAsync(r)
386384
);
387385

388-
protected override void ExpectResponse(ISearchResponse<Project> response)
386+
protected override void OnBeforeCall(IElasticClient client)
389387
{
390-
response.ShouldBeValid();
388+
var searchResponse = client.Search<Project>(s => s
389+
.RequestConfiguration(r => r.OpaqueId(CallIsolatedValue))
390+
.Scroll("10m") // Create a scroll in order to keep the task around.
391+
);
392+
393+
searchResponse.ShouldBeValid();
394+
}
391395

392-
var tasks = Client.ListTasks(d => d.RequestConfiguration(r => r.OpaqueId(CallIsolatedValue)));
393-
tasks.Should().NotBeNull();
394-
foreach (var node in tasks.Nodes)
396+
protected override void ExpectResponse(IListTasksResponse response)
397+
{
398+
response.ShouldBeValid();
399+
foreach (var node in response.Nodes)
400+
foreach (var task in node.Value.Tasks)
395401
{
396-
foreach (var task in node.Value.Tasks)
402+
task.Value.Headers.Should().NotBeNull();
403+
if (task.Value.Headers.TryGetValue(RequestData.OpaqueIdHeader, out var opaqueIdValue))
397404
{
398-
task.Value.Headers.Should().NotBeNull();
399-
if (task.Value.Headers.TryGetValue(RequestData.OpaqueIdHeader, out var opaqueIdValue))
400-
{
401-
opaqueIdValue.Should().Be(CallIsolatedValue, $"OpaqueId header {opaqueIdValue} did not match {CallIsolatedValue}");
402-
}
403-
else
404-
{
405-
Assert.True(false, $"No OpaqueId header for task {task.Key} and OpaqueId value {CallIsolatedValue}");
406-
}
405+
opaqueIdValue.Should().Be(this.CallIsolatedValue,
406+
$"OpaqueId header {opaqueIdValue} did not match {this.CallIsolatedValue}");
407+
}
408+
else
409+
{
410+
Assert.True(false,
411+
$"No OpaqueId header for task {task.Key} and OpaqueId value {this.CallIsolatedValue}");
407412
}
408413
}
409414
}

0 commit comments

Comments
 (0)