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

Add integration tests #16

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions RqliteDotnet.IntegrationTest/RqliteClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Text.RegularExpressions;
using DotNet.Testcontainers.Builders;
using NUnit.Framework;

namespace RqliteDotnet.IntegrationTest;

public class RqliteClientTests
{
private const int Port = 4001;

[Test]
public async Task RqliteClientPing_Works()
{
var container = new ContainerBuilder()
.WithImage("rqlite/rqlite:8.32.7")
.WithPortBinding(Port, true)
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(r => r.ForPort(Port)))
.Build();

await container.StartAsync().ConfigureAwait(false);

var url = $"http://{container.Hostname}:{container.GetMappedPublicPort(Port)}";
var client = new RqliteClient(url);

var version = await client.Ping();

Assert.That(version, Is.Not.Empty);
Assert.That(Regex.IsMatch(version, @"v\d+.\d+\.*")); //v8.10.1
}
}
20 changes: 20 additions & 0 deletions RqliteDotnet.IntegrationTest/RqliteDotnet.IntegrationTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="Testcontainers" Version="4.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\RqliteDotnet\RqliteDotnet.csproj" />
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions RqliteDotnet.Test/UrlBuilderTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using NUnit.Framework;

namespace RqliteDotnet.Test;
Expand Down Expand Up @@ -25,4 +26,12 @@ public void UrlBuilder_BuildsCorrectUrlWithReadLevel()
Assert.That(url.StartsWith(baseUrl));
Assert.That(url, Is.EqualTo("/db/query?timings&q=select%20%2A%20from%20foo&level=strong"));
}

[Test]
public void UrlBuilder_ThrowsWhenIncorrectReadLevelSupplied()
{
var query = "select * from foo";
var baseUrl = "/db/query?timings";
Assert.Throws<ArgumentException>(() => UrlBuilder.Build(baseUrl, query, (ReadLevel)0));
}
}
6 changes: 6 additions & 0 deletions RqliteDotnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RqliteDotnetExample", "Rqli
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RqliteDotnet.Test", "RqliteDotnet.Test\RqliteDotnet.Test.csproj", "{694FCE70-640F-4CAD-852A-4D9031600ADC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RqliteDotnet.IntegrationTest", "RqliteDotnet.IntegrationTest\RqliteDotnet.IntegrationTest.csproj", "{949312B5-5476-4AEA-9669-CD6CE44B6242}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -24,5 +26,9 @@ Global
{694FCE70-640F-4CAD-852A-4D9031600ADC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{694FCE70-640F-4CAD-852A-4D9031600ADC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{694FCE70-640F-4CAD-852A-4D9031600ADC}.Release|Any CPU.Build.0 = Release|Any CPU
{949312B5-5476-4AEA-9669-CD6CE44B6242}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{949312B5-5476-4AEA-9669-CD6CE44B6242}.Debug|Any CPU.Build.0 = Debug|Any CPU
{949312B5-5476-4AEA-9669-CD6CE44B6242}.Release|Any CPU.ActiveCfg = Release|Any CPU
{949312B5-5476-4AEA-9669-CD6CE44B6242}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
3 changes: 2 additions & 1 deletion RqliteDotnet/UrlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ private static string GetReadLevel(ReadLevel level)
ReadLevel.Linearizable => "&level=linearizable",
ReadLevel.Strong => "&level=strong",
ReadLevel.None => "&level=none",
ReadLevel.Auto => "&level=auto"
ReadLevel.Auto => "&level=auto",
_ => throw new ArgumentException("Unknown read level")
};
return result;
}
Expand Down
Loading