-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure we support endpoints with subpaths to write to as well (Elasti…
…csearch as a service) (#73) * Ensure we support endpoints with subpaths to write to as well (Elasticsearch as a service) * fix datastream url builder
- Loading branch information
Showing
7 changed files
with
77 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
using System; | ||
using System.IO; | ||
using System.Threading; | ||
using Elastic.Ingest.Elasticsearch.Indices; | ||
using Elastic.Transport; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace Elastic.Ingest.Elasticsearch.Tests; | ||
|
||
public class SubPathTests : ChannelTestWithSingleDocResponseBase | ||
{ | ||
public SubPathTests() : base("https://localhost:9200/subpath") { } | ||
|
||
[Fact] | ||
public void IndexChannel_WithFixedIndexName_UsesCorrectUrlAndOperationHeader() => | ||
ExecuteAndAssert("/subpath/fixed-index/_bulk", "{\"create\":{}}", "fixed-index"); | ||
|
||
[Fact] | ||
public void IndexChannel_WithDynamicIndexName_UsesCorrectUrlAndOperationHeader() => | ||
ExecuteAndAssert("/subpath/_bulk", "{\"create\":{\"_index\":\"dotnet-2023.07.29\"}}"); | ||
|
||
private void ExecuteAndAssert(string expectedUrl, string expectedOperationHeader, string indexName = null) | ||
{ | ||
ApiCallDetails callDetails = null; | ||
var wait = new ManualResetEvent(false); | ||
|
||
var options = new IndexChannelOptions<TestDocument>(Transport) | ||
{ | ||
BufferOptions = new() | ||
{ | ||
OutboundBufferMaxSize = 1 | ||
}, | ||
ExportResponseCallback = (response, _) => | ||
{ | ||
callDetails = response.ApiCallDetails; | ||
wait.Set(); | ||
}, | ||
TimestampLookup = _ => new DateTimeOffset(2023, 07, 29, 20, 00, 00, TimeSpan.Zero), | ||
}; | ||
|
||
if (indexName is not null) | ||
{ | ||
options.IndexFormat = indexName; | ||
} | ||
|
||
using var channel = new IndexChannel<TestDocument>(options); | ||
|
||
channel.TryWrite(new TestDocument()); | ||
wait.WaitOne(); | ||
|
||
callDetails.Should().NotBeNull(); | ||
callDetails.Uri.AbsolutePath.Should().Be(expectedUrl); | ||
|
||
var stream = new MemoryStream(callDetails.RequestBodyInBytes); | ||
var sr = new StreamReader(stream); | ||
var operation = sr.ReadLine(); | ||
operation.Should().Be(expectedOperationHeader); | ||
} | ||
} |