|
1 | 1 | using DotNet.Testcontainers.Builders;
|
2 | 2 | using DotNet.Testcontainers.Configurations;
|
3 | 3 | using DotNet.Testcontainers.Containers;
|
| 4 | +using Microsoft.Extensions.DependencyInjection; |
| 5 | +using Microsoft.Extensions.Logging; |
4 | 6 | using System.Threading.Tasks;
|
5 | 7 | using Xunit;
|
6 | 8 |
|
7 | 9 | namespace ElasticLogger.Test
|
8 | 10 | {
|
9 |
| - internal class ContainerESTests |
| 11 | + public class ContainerESTests |
10 | 12 | {
|
11 |
| - ContainerESTests() |
12 |
| - { |
13 |
| - } |
14 |
| - |
| 13 | + [Fact] |
15 | 14 | public async Task DoTheTest()
|
16 | 15 | {
|
17 |
| - await new TestcontainersBuilder<ElasticsearchTestcontainer>() |
18 |
| - .WithDatabase(new ElasticsearchTestcontainerConfiguration()) |
19 |
| - .Build() |
20 |
| - .StartAsync() |
21 |
| - .ConfigureAwait(false); |
22 |
| - } |
23 |
| - } |
| 16 | + var serviceCollection = new ServiceCollection(); |
| 17 | + serviceCollection.AddLogging(b => { |
| 18 | + b.AddDebug(); |
| 19 | + b.AddConsole(); |
| 20 | + }); |
24 | 21 |
|
| 22 | + var secureHttpServiceProvider = serviceCollection.BuildServiceProvider(); |
| 23 | + var loggerFactory = secureHttpServiceProvider.GetService<ILoggerFactory>(); |
25 | 24 |
|
26 |
| - //[Collection(nameof(Testcontainers))] |
27 |
| - public sealed class ElasticsearchTestcontainerTest : IClassFixture<ElasticsearchFixture> |
28 |
| - { |
29 |
| - private readonly ElasticsearchFixture elasticsearchFixture; |
| 25 | + ILogger logger = loggerFactory.CreateLogger("es"); |
30 | 26 |
|
31 |
| - public ElasticsearchTestcontainerTest(ElasticsearchFixture elasticsearchFixture) |
32 |
| - { |
33 |
| - this.elasticsearchFixture = elasticsearchFixture; |
34 |
| - } |
| 27 | + TestcontainersSettings.Logger = logger; |
35 | 28 |
|
36 |
| - [Fact] |
37 |
| - [Trait("Category", "Elasticsearch")] |
38 |
| - public async Task ConnectionEstablished() |
39 |
| - { |
40 |
| - // Given |
41 |
| - var connection = this.elasticsearchFixture.Connection; |
42 | 29 |
|
43 |
| - // When |
44 |
| - var result = await connection.InfoAsync() |
45 |
| - .ConfigureAwait(false); |
| 30 | + /** |
| 31 | + * WARNING |
| 32 | + * "org.elasticsearch.plugins.PluginsService","elasticsearch.node.name":"1b1454ac59a8","elasticsearch.cluster.name":"docker-cluster"} |
| 33 | + * bootstrap check failure [1] of [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] |
| 34 | + * ERROR: Elasticsearch did not exit normally - check the logs at /usr/share/elasticsearch/logs/docker-cluster.log |
| 35 | + * |
| 36 | + * ERROR: [1] bootstrap checks failed. You must address the points described in the following [1] lines before starting Elasticsearch. |
| 37 | + * |
| 38 | + * |
| 39 | + * |
| 40 | + * in docker-desktop |
| 41 | + * https://gist.github.com/jarek-przygodzki/4721932bba3bd434512ae6cc58f508b0 |
| 42 | + * wsl -d docker-desktop |
| 43 | + * echo "vm.max_map_count = 262144" > /etc/sysctl.d/99-docker-desktop.conf |
| 44 | + * reboot |
| 45 | + * |
| 46 | + * basically the linux VM running docker needs |
| 47 | + * wsl -d docker-desktop |
| 48 | + * sysctl -w vm.max_map_count=262144 |
| 49 | + * |
| 50 | + * |
| 51 | + **/ |
| 52 | + |
| 53 | + var container = new TestcontainersBuilder<ElasticsearchTestcontainer>() |
| 54 | + .WithDatabase(new ElasticsearchTestcontainerConfiguration() |
| 55 | + { |
| 56 | + Password="aaaa", |
| 57 | + |
| 58 | + }) |
| 59 | + //.WithAutoRemove(false) |
| 60 | + //.WithWaitStrategy( Wait.ForUnixContainer()) |
| 61 | + //.WithOutputConsumer(Consume.RedirectStdoutAndStderrToConsole()) |
| 62 | + .Build(); |
| 63 | + |
| 64 | + await container.StartAsync() |
| 65 | + .ConfigureAwait(false); |
46 | 66 |
|
47 |
| - // Then |
48 |
| - Assert.True(result.IsValid); |
| 67 | + Assert.NotEmpty(container.ConnectionString); |
49 | 68 | }
|
50 | 69 | }
|
| 70 | + |
| 71 | + |
| 72 | + ////[Collection(nameof(Testcontainers))] |
| 73 | + //public sealed class ElasticsearchTestcontainerTest : IClassFixture<ElasticsearchFixture> |
| 74 | + //{ |
| 75 | + // private readonly ElasticsearchFixture elasticsearchFixture; |
| 76 | + |
| 77 | + // public ElasticsearchTestcontainerTest(ElasticsearchFixture elasticsearchFixture) |
| 78 | + // { |
| 79 | + // this.elasticsearchFixture = elasticsearchFixture; |
| 80 | + // } |
| 81 | + |
| 82 | + // [Fact] |
| 83 | + // [Trait("Category", "Elasticsearch")] |
| 84 | + // public async Task ConnectionEstablished() |
| 85 | + // { |
| 86 | + // // Given |
| 87 | + // var connection = this.elasticsearchFixture.Connection; |
| 88 | + |
| 89 | + // // When |
| 90 | + // var result = await connection.InfoAsync() |
| 91 | + // .ConfigureAwait(false); |
| 92 | + |
| 93 | + // // Then |
| 94 | + // Assert.True(result.IsValid); |
| 95 | + // } |
| 96 | + //} |
| 97 | +} |
0 commit comments