|
1 | 1 | using System;
|
2 | 2 | using System.Collections.Generic;
|
| 3 | +using Elastic.Xunit.XunitPlumbing; |
3 | 4 | using Elasticsearch.Net;
|
4 | 5 | using FluentAssertions;
|
5 | 6 | using Nest;
|
@@ -317,4 +318,90 @@ protected override void ExpectResponse(CreateIndexResponse response)
|
317 | 318 | aliases[CallIsolatedValue + "-alias"].IsWriteIndex.Should().BeTrue();
|
318 | 319 | }
|
319 | 320 | }
|
| 321 | + |
| 322 | + |
| 323 | + [SkipVersion("<7.7.0", "hidden indices and aliases introduced in 7.7.0")] |
| 324 | + public class CreateHiddenIndexApiTests |
| 325 | + : ApiIntegrationTestBase<WritableCluster, CreateIndexResponse, ICreateIndexRequest, CreateIndexDescriptor, CreateIndexRequest> |
| 326 | + { |
| 327 | + public CreateHiddenIndexApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { } |
| 328 | + |
| 329 | + protected override bool ExpectIsValid => true; |
| 330 | + |
| 331 | + protected override object ExpectJson => new |
| 332 | + { |
| 333 | + settings = new Dictionary<string, object> |
| 334 | + { |
| 335 | + { "index.number_of_replicas", 0 }, |
| 336 | + { "index.number_of_shards", 1 }, |
| 337 | + { "index.hidden", true } |
| 338 | + }, |
| 339 | + aliases = new Dictionary<string, object> |
| 340 | + { |
| 341 | + { CallIsolatedValue + "-alias", new { is_write_index = true, is_hidden = true } } |
| 342 | + } |
| 343 | + }; |
| 344 | + |
| 345 | + protected override int ExpectStatusCode => 200; |
| 346 | + |
| 347 | + protected override Func<CreateIndexDescriptor, ICreateIndexRequest> Fluent => d => d |
| 348 | + .Settings(s => s |
| 349 | + .NumberOfReplicas(0) |
| 350 | + .NumberOfShards(1) |
| 351 | + .Hidden() |
| 352 | + ) |
| 353 | + .Aliases(a => a |
| 354 | + .Alias(CallIsolatedValue + "-alias", aa => aa |
| 355 | + .IsWriteIndex() |
| 356 | + .IsHidden() |
| 357 | + ) |
| 358 | + ); |
| 359 | + |
| 360 | + protected override HttpMethod HttpMethod => HttpMethod.PUT; |
| 361 | + |
| 362 | + protected override CreateIndexRequest Initializer => new CreateIndexRequest(CallIsolatedValue) |
| 363 | + { |
| 364 | + Settings = new Nest.IndexSettings |
| 365 | + { |
| 366 | + NumberOfReplicas = 0, |
| 367 | + NumberOfShards = 1, |
| 368 | + Hidden = true |
| 369 | + }, |
| 370 | + Aliases = new Aliases |
| 371 | + { |
| 372 | + { CallIsolatedValue + "-alias", new Alias { IsWriteIndex = true, IsHidden = true} } |
| 373 | + } |
| 374 | + }; |
| 375 | + |
| 376 | + protected override string UrlPath => $"/{CallIsolatedValue}"; |
| 377 | + |
| 378 | + protected override LazyResponses ClientUsage() => Calls( |
| 379 | + (client, f) => client.Indices.Create(CallIsolatedValue, f), |
| 380 | + (client, f) => client.Indices.CreateAsync(CallIsolatedValue, f), |
| 381 | + (client, r) => client.Indices.Create(r), |
| 382 | + (client, r) => client.Indices.CreateAsync(r) |
| 383 | + ); |
| 384 | + |
| 385 | + protected override CreateIndexDescriptor NewDescriptor() => new CreateIndexDescriptor(CallIsolatedValue); |
| 386 | + |
| 387 | + protected override void ExpectResponse(CreateIndexResponse response) |
| 388 | + { |
| 389 | + response.ShouldBeValid(); |
| 390 | + response.Acknowledged.Should().BeTrue(); |
| 391 | + response.ShardsAcknowledged.Should().BeTrue(); |
| 392 | + |
| 393 | + var indexResponse = Client.Indices.Get(CallIsolatedValue); |
| 394 | + |
| 395 | + indexResponse.ShouldBeValid(); |
| 396 | + indexResponse.Indices.Should().NotBeEmpty().And.ContainKey(CallIsolatedValue); |
| 397 | + var index = indexResponse.Indices[CallIsolatedValue]; |
| 398 | + |
| 399 | + index.Settings.Hidden.Should().BeTrue(); |
| 400 | + |
| 401 | + var aliases = indexResponse.Indices[CallIsolatedValue].Aliases; |
| 402 | + aliases.Count.Should().Be(1); |
| 403 | + aliases[CallIsolatedValue + "-alias"].IsWriteIndex.Should().BeTrue(); |
| 404 | + aliases[CallIsolatedValue + "-alias"].IsHidden.Should().BeTrue(); |
| 405 | + } |
| 406 | + } |
320 | 407 | }
|
0 commit comments