Skip to content

Commit 7852f2c

Browse files
committed
docs(ClickHouse): Add example
1 parent 2162c44 commit 7852f2c

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

docs/modules/clickhouse.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# ClickHouse
2+
3+
[ClickHouse](https://clickhouse.com/) is a high-performance, column-oriented SQL database management system (DBMS) for online analytical processing (OLAP).
4+
5+
Add the following dependency to your project file:
6+
7+
```shell title="NuGet"
8+
dotnet add package Testcontainers.ClickHouse
9+
```
10+
11+
You can start a ClickHouse container instance from any .NET application. This example uses xUnit.net's `IAsyncLifetime` interface to manage the lifecycle of the container. The container is started in the `InitializeAsync` method before the test method runs, ensuring that the environment is ready for testing. After the test completes, the container is removed in the `DisposeAsync` method.
12+
13+
=== "Test class"
14+
```csharp
15+
--8<-- "tests/Testcontainers.ClickHouse.Tests/ClickHouseContainerTest.cs:Class"
16+
}
17+
```
18+
19+
=== "Connecting to ClickHouse"
20+
```csharp
21+
--8<-- "tests/Testcontainers.ClickHouse.Tests/ClickHouseContainerTest.cs:Connecting"
22+
```
23+
24+
Execute SQL script example:
25+
=== "SQL Script"
26+
```csharp
27+
--8<-- "tests/Testcontainers.ClickHouse.Tests/ClickHouseContainerTest.cs:SQLScript"
28+
```
29+
30+
The test example uses the following NuGet dependencies:
31+
32+
=== "Package References"
33+
```xml
34+
--8<-- "tests/Testcontainers.ClickHouse.Tests/Testcontainers.ClickHouse.Tests.csproj:PackageReferences"
35+
```
36+
37+
To execute the tests, use the command `dotnet test` from a terminal.
38+
39+
--8<-- "docs/modules/_call_out_test_projects.txt"

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ nav:
5353
- modules/pulsar.md # Apache
5454
- modules/eventhubs.md # Azure
5555
- modules/servicebus.md # Azure
56+
- modules/clickhouse.md
5657
- modules/db2.md
5758
- modules/elasticsearch.md
5859
- modules/mongodb.md

tests/Testcontainers.ClickHouse.Tests/ClickHouseContainerTest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace Testcontainers.ClickHouse;
22

3+
// <!-- -8<- [start:Class] -->
34
public sealed class ClickHouseContainerTest : IAsyncLifetime
45
{
56
private readonly ClickHouseContainer _clickHouseContainer = new ClickHouseBuilder().Build();
@@ -13,7 +14,9 @@ public Task DisposeAsync()
1314
{
1415
return _clickHouseContainer.DisposeAsync().AsTask();
1516
}
17+
// <!-- -8<- [end:Class] -->
1618

19+
// <!-- -8<- [start:Connecting] -->
1720
[Fact]
1821
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
1922
public void ConnectionStateReturnsOpen()
@@ -27,7 +30,9 @@ public void ConnectionStateReturnsOpen()
2730
// Then
2831
Assert.Equal(ConnectionState.Open, connection.State);
2932
}
33+
// <!-- -8<- [end:Connecting] -->
3034

35+
// <!-- -8<- [start:SQLScript] -->
3136
[Fact]
3237
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
3338
public async Task ExecScriptReturnsSuccessful()
@@ -43,4 +48,5 @@ public async Task ExecScriptReturnsSuccessful()
4348
Assert.True(0L.Equals(execResult.ExitCode), execResult.Stderr);
4449
Assert.Empty(execResult.Stderr);
4550
}
51+
// <!-- -8<- [end:SQLScript] -->
4652
}

tests/Testcontainers.ClickHouse.Tests/Testcontainers.ClickHouse.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
<IsPublishable>false</IsPublishable>
66
</PropertyGroup>
77
<ItemGroup>
8+
<!-- -8<- [start:PackageReferences] -->
89
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
910
<PackageReference Include="coverlet.collector"/>
1011
<PackageReference Include="xunit.runner.visualstudio"/>
1112
<PackageReference Include="xunit"/>
1213
<PackageReference Include="ClickHouse.Client"/>
14+
<!-- -8<- [end:PackageReferences] -->
1315
</ItemGroup>
1416
<ItemGroup>
1517
<ProjectReference Include="../../src/Testcontainers.ClickHouse/Testcontainers.ClickHouse.csproj"/>

0 commit comments

Comments
 (0)