Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ClickHouse tests, fixed & improved CI pipeline #1895

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
18 changes: 18 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,24 @@ jobs:
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: test
clickhouse:
image: clickhouse/clickhouse-server:latest
ports:
- 8123/tcp
steps:
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
3.1.x
5.x
- uses: actions/cache@v3
name: Cache NuGet packages
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Checkout code
uses: actions/checkout@v1
- name: .NET Build
Expand All @@ -49,5 +66,6 @@ jobs:
OLEDBConnectionString: Provider=SQLOLEDB;Server=tcp:localhost,${{ job.services.sqlserver.ports[1433] }};Database=tempdb;User Id=sa;Password=Password.;
PostgesConnectionString: Server=localhost;Port=${{ job.services.postgres.ports[5432] }};Database=test;User Id=postgres;Password=postgres;
SqlServerConnectionString: Server=tcp:localhost,${{ job.services.sqlserver.ports[1433] }};Database=tempdb;User Id=sa;Password=Password.;
ClickHouseConnectionString: Server=localhost;Port=${{ job.services.clickhouse.ports[8123] }};Username=default
- name: .NET Lib Pack
run: dotnet pack Build.csproj --no-build -c Release /p:PackageOutputPath=%CD%\.nupkgs /p:CI=true
5 changes: 5 additions & 0 deletions tests/Dapper.Tests/Dapper.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1' OR '$(TargetFramework)' == 'net5.0'">
DarkWanderer marked this conversation as resolved.
Show resolved Hide resolved
<PackageReference Include="ClickHouse.Client">
<Version>6.5.2</Version>
</PackageReference>
</ItemGroup>
</Project>
93 changes: 93 additions & 0 deletions tests/Dapper.Tests/Providers/ClickHouseTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#if NETCOREAPP3_1_OR_GREATER

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using ClickHouse.Client.ADO;
using Xunit;
using Xunit.Sdk;

namespace Dapper.Tests.Providers
{
public class ClickHouseProvider : DatabaseProvider
{
public override DbProviderFactory Factory { get; } = new ClickHouseConnectionFactory();

public override string GetConnectionString() =>
GetConnectionString("ClickHouseConnectionString", "Server=localhost;Port=8123;Username=default");
}

public class ClickHouseTests : TestBase<ClickHouseProvider>
{
private ClickHouseConnection CreateConnection() => (ClickHouseConnection)Provider.GetOpenConnection();

public static IEnumerable<object[]> SelectTestCases
{
get
{
yield return new object[] { "SELECT toInt16(-16)", (short)-16 };
yield return new object[] { "SELECT toUInt16(16)", (ushort)16 };
yield return new object[] { "SELECT toInt32(-32)", -32 };
yield return new object[] { "SELECT toFloat64(64)", 64.0 };
yield return new object[] { "SELECT 'hello'", "hello" };
yield return new object[] { "SELECT array('hello', 'world')", new[] { "hello", "world" } };
}
}

[TheoryClickHouse]
[MemberData(nameof(SelectTestCases))]
public void ShouldSelect(string sql, object expected) => Assert.Equal(expected, connection.ExecuteScalar(sql));

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class FactClickHouseAttribute : FactAttribute
{
public override string Skip
{
get { return unavailable ?? base.Skip; }
set { base.Skip = value; }
}

private static readonly string unavailable;

static FactClickHouseAttribute()
{
try
{
using (DatabaseProvider<ClickHouseProvider>.Instance.GetOpenConnection()) { /* just trying to see if it works */ }
}
catch (Exception ex)
{
unavailable = $"ClickHouse is unavailable: {ex.Message}";
}
}
}

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class TheoryClickHouseAttribute : TheoryAttribute
{
public override string Skip
{
get { return unavailable ?? base.Skip; }
set { base.Skip = value; }
}

private static readonly string unavailable;

static TheoryClickHouseAttribute()
{
try
{
using (DatabaseProvider<ClickHouseProvider>.Instance.GetOpenConnection()) { /* just trying to see if it works */ }
}
catch (Exception ex)
{
unavailable = $"ClickHouse is unavailable: {ex.Message}";
}
}
}
}
}

#endif