-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add read level support for queries and unit tests
- Loading branch information
Showing
5 changed files
with
70 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using NUnit.Framework; | ||
|
||
namespace RqliteDotnet.Test; | ||
|
||
public class UrlBuilderTests | ||
{ | ||
[Test] | ||
public void UrlBuilder_BuildsCorrectUrl() | ||
{ | ||
var query = "select * from foo"; | ||
var baseUrl = "/db/query?timings"; | ||
var url = UrlBuilder.Build(baseUrl, query, ReadLevel.Default); | ||
|
||
Assert.That(url.StartsWith(baseUrl)); | ||
Assert.That(url, Is.EqualTo("/db/query?timings&q=select%20%2A%20from%20foo")); | ||
} | ||
|
||
[Test] | ||
public void UrlBuilder_BuildsCorrectUrlWithReadLevel() | ||
{ | ||
var query = "select * from foo"; | ||
var baseUrl = "/db/query?timings"; | ||
var url = UrlBuilder.Build(baseUrl, query, ReadLevel.Strong); | ||
|
||
Assert.That(url.StartsWith(baseUrl)); | ||
Assert.That(url, Is.EqualTo("/db/query?timings&q=select%20%2A%20from%20foo&level=strong")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace RqliteDotnet; | ||
|
||
public enum ReadLevel | ||
{ | ||
Default = 1, | ||
Weak, | ||
Linearizable, | ||
Strong, | ||
None, | ||
Auto | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
namespace RqliteDotnet; | ||
|
||
public static class UrlBuilder | ||
{ | ||
public static string Build(string baseUrl, string query, ReadLevel level) | ||
{ | ||
var data = "&q=" + Uri.EscapeDataString(query); | ||
var readLevelParam = GetReadLevel(level); | ||
|
||
return $"{baseUrl}{data}{readLevelParam}"; | ||
} | ||
|
||
private static string GetReadLevel(ReadLevel level) | ||
{ | ||
var result = level switch | ||
Check warning on line 15 in RqliteDotnet/UrlBuilder.cs GitHub Actions / build
Check warning on line 15 in RqliteDotnet/UrlBuilder.cs GitHub Actions / build
|
||
{ | ||
ReadLevel.Default => "", | ||
ReadLevel.Weak => "&level=weak", | ||
ReadLevel.Linearizable => "&level=linearizable", | ||
ReadLevel.Strong => "&level=strong", | ||
ReadLevel.None => "&level=none", | ||
ReadLevel.Auto => "&level=auto" | ||
}; | ||
return result; | ||
} | ||
} |