Skip to content

Commit

Permalink
Implement integration test for Execute (#22)
Browse files Browse the repository at this point in the history
Add integration test
  • Loading branch information
arthrp authored Dec 21, 2024
1 parent fab654c commit 5c15a7e
Showing 1 changed file with 39 additions and 9 deletions.
48 changes: 39 additions & 9 deletions RqliteDotnet.IntegrationTest/RqliteClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,60 @@
using System.Net.Http.Json;
using System.Runtime.InteropServices.JavaScript;
using System.Text;
using System.Text.RegularExpressions;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Containers;
using NUnit.Framework;

namespace RqliteDotnet.IntegrationTest;

public class RqliteClientTests
{
private const int Port = 4001;

[Test]
public async Task RqliteClientPing_Works()
private IContainer _container;
private HttpClient _httpClient;

[SetUp]
public async Task Setup()
{
var container = new ContainerBuilder()
.WithImage("rqlite/rqlite:8.32.7")
_container = new ContainerBuilder()
.WithImage("rqlite/rqlite:8.36.1")
.WithPortBinding(Port, true)
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(r => r.ForPort(Port)))
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(r => r.ForPort(Port))
.UntilMessageIsLogged("is now Leader",o => o.WithTimeout(TimeSpan.FromSeconds(20))))
.Build();

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

var url = $"http://{container.Hostname}:{container.GetMappedPublicPort(Port)}";
await _container.StartAsync().ConfigureAwait(false);
}

[Test]
public async Task RqliteClientPing_Works()
{
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
}

[Test]
public async Task RqliteClient_CanGetInsertData()
{
var url = $"http://{_container.Hostname}:{_container.GetMappedPublicPort(Port)}";
_httpClient = new HttpClient() { BaseAddress = new Uri(url) };
var content =
new StringContent("[ \"CREATE TABLE foo (id INTEGER NOT NULL PRIMARY KEY, name TEXT, age INTEGER)\" ]", Encoding.UTF8, "application/json");
var r = await _httpClient.PostAsync("/db/execute?timings", content);

Assert.That(r.IsSuccessStatusCode);

var client = new RqliteClient(url);


var result = await client.Execute("insert into foo(id, name, age) VALUES(1,\\\"john\\\", 42)");
Assert.That(result!.Results!.Count, Is.EqualTo(1));
Assert.That(result!.Results[0].RowsAffected, Is.EqualTo(1));
}
}

0 comments on commit 5c15a7e

Please sign in to comment.