|
| 1 | +// Licensed to Elasticsearch B.V under one or more agreements. |
| 2 | +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. |
| 3 | +// See the LICENSE file in the project root for more information |
| 4 | + |
| 5 | +using System; |
| 6 | +using System.Collections.Generic; |
| 7 | +using System.Linq; |
| 8 | +using Elastic.Elasticsearch.Xunit.XunitPlumbing; |
| 9 | +using Elasticsearch.Net; |
| 10 | +using FluentAssertions; |
| 11 | +using Nest; |
| 12 | +using Tests.Core.Extensions; |
| 13 | +using Tests.Core.ManagedElasticsearch.Clusters; |
| 14 | +using Tests.Framework.EndpointTests; |
| 15 | +using Tests.Framework.EndpointTests.TestState; |
| 16 | + |
| 17 | +namespace Tests.Indices.IndexManagement.ResolveIndex |
| 18 | +{ |
| 19 | + [SkipVersion("<7.9.0", "resolve index introduced in 7.9.0")] |
| 20 | + public class ResolveIndexApiTests |
| 21 | + : ApiIntegrationTestBase<WritableCluster, ResolveIndexResponse, IResolveIndexRequest, ResolveIndexDescriptor, ResolveIndexRequest> |
| 22 | + { |
| 23 | + public ResolveIndexApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { } |
| 24 | + |
| 25 | + protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values) |
| 26 | + { |
| 27 | + foreach (var value in values) |
| 28 | + { |
| 29 | + var createIndexResponse = client.Indices.Create(value.Value, c => c |
| 30 | + .Settings(s => s |
| 31 | + .NumberOfShards(1) |
| 32 | + .NumberOfReplicas(0) |
| 33 | + ) |
| 34 | + .Aliases(a => a |
| 35 | + .Alias(value.Value + "-alias") |
| 36 | + ) |
| 37 | + ); |
| 38 | + |
| 39 | + if (!createIndexResponse.IsValid) |
| 40 | + throw new Exception($"exception whilst setting up integration test: {createIndexResponse.DebugInformation}"); |
| 41 | + |
| 42 | + var clusterResponse = client.Cluster.Health(value.Value, c => c.WaitForStatus(WaitForStatus.Green)); |
| 43 | + |
| 44 | + if (!clusterResponse.IsValid) |
| 45 | + throw new Exception($"exception whilst setting up integration test: {clusterResponse.DebugInformation}"); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + protected override bool ExpectIsValid => true; |
| 50 | + |
| 51 | + protected override int ExpectStatusCode => 200; |
| 52 | + |
| 53 | + protected override Func<ResolveIndexDescriptor, IResolveIndexRequest> Fluent => d => d; |
| 54 | + |
| 55 | + protected override HttpMethod HttpMethod => HttpMethod.GET; |
| 56 | + |
| 57 | + protected override ResolveIndexRequest Initializer => new ResolveIndexRequest($"{CallIsolatedValue}*"); |
| 58 | + |
| 59 | + protected override string UrlPath => $"/_resolve/index/{CallIsolatedValue}%2A"; |
| 60 | + |
| 61 | + protected override LazyResponses ClientUsage() => Calls( |
| 62 | + (client, f) => client.Indices.Resolve($"{CallIsolatedValue}*", f), |
| 63 | + (client, f) => client.Indices.ResolveAsync($"{CallIsolatedValue}*", f), |
| 64 | + (client, r) => client.Indices.Resolve(r), |
| 65 | + (client, r) => client.Indices.ResolveAsync(r) |
| 66 | + ); |
| 67 | + |
| 68 | + protected override ResolveIndexDescriptor NewDescriptor() => new ResolveIndexDescriptor($"{CallIsolatedValue}*"); |
| 69 | + |
| 70 | + protected override void ExpectResponse(ResolveIndexResponse response) |
| 71 | + { |
| 72 | + response.ShouldBeValid(); |
| 73 | + response.Indices.Should().HaveCount(1); |
| 74 | + var resolvedIndex = response.Indices.First(); |
| 75 | + resolvedIndex.Name.Should().Be(CallIsolatedValue); |
| 76 | + resolvedIndex.Aliases.Should().Contain(CallIsolatedValue + "-alias"); |
| 77 | + resolvedIndex.Attributes.Should().Contain("open"); |
| 78 | + var resolvedAlias = response.Aliases.First(); |
| 79 | + resolvedAlias.Name.Should().Be(CallIsolatedValue + "-alias"); |
| 80 | + resolvedAlias.Indices.Should().Contain(CallIsolatedValue); |
| 81 | + } |
| 82 | + } |
| 83 | +} |
0 commit comments