Skip to content

Commit

Permalink
Test fix: SurrealDB 2.2 live query error message update (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuel-keller authored Feb 10, 2025
1 parent 27749a1 commit f2e4361
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 37 deletions.
25 changes: 13 additions & 12 deletions SurrealDb.Net.LiveQuery.Tests/KillTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SurrealDb.Net.Exceptions;
using System.Linq.Expressions;
using SurrealDb.Net.Exceptions;
using SurrealDb.Net.Models.Response;

namespace SurrealDb.Net.LiveQuery.Tests;
Expand Down Expand Up @@ -72,16 +73,16 @@ public async Task ShouldFailToKillInexistantLiveQueryOnWsProtocol(string connect
await client.Kill(liveQueryUuid);
};

string errorMessage = version switch
{
{ Major: 1 } =>
"There was a problem with the database: Can not execute KILL statement using id 'KILL statement uuid did not exist'",
{ Major: 2, Minor: 0 } =>
"There was a problem with the database: Can not execute KILL statement using id '$id'",
_ =>
$"There was a problem with the database: Can not execute KILL statement using id 'u'{liveQueryUuid}''",
};

await func.Should().ThrowAsync<SurrealDbException>().WithMessage(errorMessage);
Expression<Func<SurrealDbException, bool>> validErrorMessage = ex =>
ex.Message.Contains(
"There was a problem with the database: Can not execute KILL statement using id"
)
&& (
ex.Message.Contains(liveQueryUuid.ToString()) // >= 2.1
|| ex.Message.Contains("KILL statement uuid did not exist") // 1.x
|| ex.Message.Contains("Can not execute KILL statement using id '$id'") // 2.0.x
);

await func.Should().ThrowAsync<SurrealDbException>().Where(validErrorMessage);
}
}
47 changes: 22 additions & 25 deletions SurrealDb.Net.LiveQuery.Tests/LiveQueryTests.Kill.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SurrealDb.Net.Exceptions;
using System.Linq.Expressions;
using SurrealDb.Net.Exceptions;
using SurrealDb.Net.Models.LiveQuery;
using SurrealDb.Net.Models.Response;

Expand All @@ -10,8 +11,6 @@ public class KillLiveQueryTests
[Arguments("Endpoint=ws://127.0.0.1:8000/rpc;User=root;Pass=root")]
public async Task ShouldAutomaticallyKillLiveQueryWhenDisposed(string connectionString)
{
var version = await SurrealDbClientGenerator.GetSurrealTestVersion(connectionString);

await using var surrealDbClientGenerator = new SurrealDbClientGenerator();
var dbInfo = surrealDbClientGenerator.GenerateDatabaseInfo();

Expand Down Expand Up @@ -44,28 +43,26 @@ public async Task ShouldAutomaticallyKillLiveQueryWhenDisposed(string connection

liveQueryUuid.Should().NotBeEmpty();

string errorMessage = version switch
{
{ Major: 1 } =>
"There was a problem with the database: Can not execute KILL statement using id 'KILL statement uuid did not exist'",
{ Major: 2, Minor: 0 } =>
"There was a problem with the database: Can not execute KILL statement using id '$id'",
_ =>
$"There was a problem with the database: Can not execute KILL statement using id 'u'{liveQueryUuid}''",
};
Expression<Func<SurrealDbException, bool>> validErrorMessage = ex =>
ex.Message.Contains(
"There was a problem with the database: Can not execute KILL statement using id"
)
&& (
ex.Message.Contains(liveQueryUuid.ToString()) // >= 2.1
|| ex.Message.Contains("KILL statement uuid did not exist") // 1.x
|| ex.Message.Contains("Can not execute KILL statement using id '$id'") // 2.0.x
);

await liveQueryAlreadyKilledFunc
.Should()
.ThrowAsync<SurrealDbException>()
.WithMessage(errorMessage);
.Where(validErrorMessage);
}

[Test]
[Arguments("Endpoint=ws://127.0.0.1:8000/rpc;User=root;Pass=root")]
public async Task ShouldManuallyKillLiveQuery(string connectionString)
{
var version = await SurrealDbClientGenerator.GetSurrealTestVersion(connectionString);

await using var surrealDbClientGenerator = new SurrealDbClientGenerator();
var dbInfo = surrealDbClientGenerator.GenerateDatabaseInfo();

Expand Down Expand Up @@ -102,19 +99,19 @@ public async Task ShouldManuallyKillLiveQuery(string connectionString)

await manuallyKillLiveQueryFunc.Should().NotThrowAsync();

string errorMessage = version switch
{
{ Major: 1 } =>
"There was a problem with the database: Can not execute KILL statement using id 'KILL statement uuid did not exist'",
{ Major: 2, Minor: 0 } =>
"There was a problem with the database: Can not execute KILL statement using id '$id'",
_ =>
$"There was a problem with the database: Can not execute KILL statement using id 'u'{liveQueryUuid}''",
};
Expression<Func<SurrealDbException, bool>> validErrorMessage = ex =>
ex.Message.Contains(
"There was a problem with the database: Can not execute KILL statement using id"
)
&& (
ex.Message.Contains(liveQueryUuid.ToString()) // >= 2.1
|| ex.Message.Contains("KILL statement uuid did not exist") // 1.x
|| ex.Message.Contains("Can not execute KILL statement using id '$id'") // 2.0.x
);

await liveQueryAlreadyKilledFunc
.Should()
.ThrowAsync<SurrealDbException>()
.WithMessage(errorMessage);
.Where(validErrorMessage);
}
}

0 comments on commit f2e4361

Please sign in to comment.