Skip to content

Commit d2265de

Browse files
Improvements tests and docs
* docs: scripts comments in English * fix: readme and cache extensions tests * docs: update readme.md * fix: template issue --------- Co-authored-by: Alisson Solitto <alisson.solitto>
1 parent d758d5d commit d2265de

File tree

7 files changed

+32
-30
lines changed

7 files changed

+32
-30
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,3 @@ body:
6666
label: Relevant log output
6767
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
6868
render: shell
69-
- type: checkboxes
70-
id: terms
71-
attributes:
72-
label: Code of Conduct
73-
description: By submitting this issue, you agree to follow our [Code of Conduct](https://example.com/codeofconduct)
74-
options:
75-
- label: I agree to follow this project's Code of Conduct
76-
required: true

.github/ISSUE_TEMPLATE/feature_request.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,3 @@ body:
3434
attributes:
3535
label: Additional context
3636
description: Add any other context or screenshots about the feature request here.
37-
- type: checkboxes
38-
id: terms
39-
attributes:
40-
label: Code of Conduct
41-
description: By submitting this issue, you agree to follow our [Code of Conduct](https://example.com/codeofconduct)
42-
options:
43-
- label: I agree to follow this project's Code of Conduct
44-
required: true

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# BKlug.Extensions.Caching.PostgreSql
22

33
[![Build & Test](https://github.com/bKlug-ai/BKlug.Extensions.Caching.PostgreSql/actions/workflows/ci.yml/badge.svg)](https://github.com/bKlug-ai/BKlug.Extensions.Caching.PostgreSql/actions/workflows/ci.yml)
4+
[![Create Release Draft](https://github.com/bKlug-ai/BKlug.Extensions.Caching.PostgreSql/actions/workflows/draft-release.yml/badge.svg)](https://github.com/bKlug-ai/BKlug.Extensions.Caching.PostgreSql/actions/workflows/draft-release.yml)
5+
[![Release](https://github.com/bKlug-ai/BKlug.Extensions.Caching.PostgreSql/actions/workflows/release.yml/badge.svg)](https://github.com/bKlug-ai/BKlug.Extensions.Caching.PostgreSql/actions/workflows/release.yml)
6+
[![NuGet Version](https://img.shields.io/nuget/v/BKlug.Extensions.Caching.PostgreSql.svg)](https://www.nuget.org/packages/BKlug.Extensions.Caching.PostgreSql)
47
[![NuGet Downloads](https://img.shields.io/nuget/dt/BKlug.Extensions.Caching.PostgreSql.svg)](https://www.nuget.org/packages/BKlug.Extensions.Caching.PostgreSql)
8+
[![.NET 6.0](https://img.shields.io/badge/.NET-6.0-blue.svg)](https://dotnet.microsoft.com/en-us/download/dotnet/6.0)
9+
[![.NET 8.0](https://img.shields.io/badge/.NET-8.0-blue.svg)](https://dotnet.microsoft.com/en-us/download/dotnet/8.0)
10+
[![.NET 9.0](https://img.shields.io/badge/.NET-9.0-blue.svg)](https://dotnet.microsoft.com/en-us/download/dotnet/9.0)
511
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
612

713
> **Supported .NET versions:**

test/PostgreSqlCacheExtensionsTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public PostgreSqlCacheExtensionsTests(PostgreSqlCacheFixture fixture)
2121
public void Get_Generic_ReturnsDeserializedValue()
2222
{
2323
// Arrange
24-
var key = "test-key";
24+
var key = Guid.NewGuid().ToString();
2525
var value = new TestClass { Id = 1, Name = "Test" };
2626
var serializedValue = JsonSerializer.SerializeToUtf8Bytes(value);
2727
_cache.Set(key, serializedValue);
@@ -52,7 +52,7 @@ public void Get_Generic_ReturnsDefault_WhenKeyNotExists()
5252
public async Task GetAsync_Generic_ReturnsDeserializedValue()
5353
{
5454
// Arrange
55-
var key = "test-key";
55+
var key = Guid.NewGuid().ToString();
5656
var value = new TestClass { Id = 1, Name = "Test" };
5757
var serializedValue = JsonSerializer.SerializeToUtf8Bytes(value);
5858
await _cache.SetAsync(key, serializedValue);
@@ -83,7 +83,7 @@ public async Task GetAsync_Generic_ReturnsDefault_WhenKeyNotExists()
8383
public void TryGetValue_Generic_ReturnsTrueAndValue_WhenKeyExists()
8484
{
8585
// Arrange
86-
var key = "test-key";
86+
var key = Guid.NewGuid().ToString();
8787
var value = new TestClass { Id = 1, Name = "Test" };
8888
var serializedValue = JsonSerializer.SerializeToUtf8Bytes(value);
8989
_cache.Set(key, serializedValue);
@@ -116,7 +116,7 @@ public void TryGetValue_Generic_ReturnsFalseAndDefault_WhenKeyNotExists()
116116
public async Task TryGetValueAsync_Generic_ReturnsTrueAndValue_WhenKeyExists()
117117
{
118118
// Arrange
119-
var key = "test-key";
119+
var key = Guid.NewGuid().ToString();
120120
var value = new TestClass { Id = 1, Name = "Test" };
121121
var serializedValue = JsonSerializer.SerializeToUtf8Bytes(value);
122122
await _cache.SetAsync(key, serializedValue);
@@ -149,7 +149,7 @@ public async Task TryGetValueAsync_Generic_ReturnsFalseAndDefault_WhenKeyNotExis
149149
public void Set_Generic_SerializesAndStoresValue()
150150
{
151151
// Arrange
152-
var key = "test-key";
152+
var key = Guid.NewGuid().ToString();
153153
var value = new TestClass { Id = 1, Name = "Test" };
154154

155155
// Act
@@ -170,7 +170,7 @@ public void Set_Generic_SerializesAndStoresValue()
170170
public void Set_Generic_WithAbsoluteExpiration_SerializesAndStoresValue()
171171
{
172172
// Arrange
173-
var key = "test-key";
173+
var key = Guid.NewGuid().ToString();
174174
var value = new TestClass { Id = 1, Name = "Test" };
175175
var expiration = DateTimeOffset.UtcNow.AddMinutes(5);
176176

@@ -192,7 +192,7 @@ public void Set_Generic_WithAbsoluteExpiration_SerializesAndStoresValue()
192192
public void Set_Generic_WithRelativeExpiration_SerializesAndStoresValue()
193193
{
194194
// Arrange
195-
var key = "test-key";
195+
var key = Guid.NewGuid().ToString();
196196
var value = new TestClass { Id = 1, Name = "Test" };
197197
var expiration = TimeSpan.FromMinutes(5);
198198

@@ -214,7 +214,7 @@ public void Set_Generic_WithRelativeExpiration_SerializesAndStoresValue()
214214
public void Set_Generic_WithOptions_SerializesAndStoresValue()
215215
{
216216
// Arrange
217-
var key = "test-key";
217+
var key = Guid.NewGuid().ToString();
218218
var value = new TestClass { Id = 1, Name = "Test" };
219219
var options = new DistributedCacheEntryOptions
220220
{
@@ -239,7 +239,7 @@ public void Set_Generic_WithOptions_SerializesAndStoresValue()
239239
public async Task SetAsync_Generic_SerializesAndStoresValue()
240240
{
241241
// Arrange
242-
var key = "test-key";
242+
var key = Guid.NewGuid().ToString();
243243
var value = new TestClass { Id = 1, Name = "Test" };
244244

245245
// Act
@@ -260,7 +260,7 @@ public async Task SetAsync_Generic_SerializesAndStoresValue()
260260
public void GetOrCreate_ReturnsExistingValue_WhenKeyExists()
261261
{
262262
// Arrange
263-
var key = "test-key";
263+
var key = Guid.NewGuid().ToString();
264264
var value = new TestClass { Id = 1, Name = "Test" };
265265
var serializedValue = JsonSerializer.SerializeToUtf8Bytes(value);
266266
_cache.Set(key, serializedValue);
@@ -313,7 +313,7 @@ public void GetOrCreate_CreatesAndReturnsNewValue_WhenKeyNotExists()
313313
public async Task GetOrCreateAsync_ReturnsExistingValue_WhenKeyExists()
314314
{
315315
// Arrange
316-
var key = "test-key";
316+
var key = Guid.NewGuid().ToString();
317317
var value = new TestClass { Id = 1, Name = "Test" };
318318
var serializedValue = JsonSerializer.SerializeToUtf8Bytes(value);
319319
await _cache.SetAsync(key, serializedValue);

test/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This project contains integration tests for the PostgreSQL distributed cache lib
44

55
## Prerequisites
66
- Docker or a local PostgreSQL instance
7-
- .NET 8 SDK or higher
7+
- .NET 6 SDK or higher
88
- The [pg_cron](https://github.com/citusdata/pg_cron) extension must be installed in the test database
99
- The official `postgres:15` or higher image already includes pg_cron by default
1010

@@ -22,10 +22,12 @@ The test database will be created automatically if it doesn't exist.
2222
## Running the tests
2323
### Windows
2424
```powershell
25+
cd scripts
2526
./run-db-tests.ps1
2627
```
2728
### Linux/macOS
2829
```sh
30+
cd scripts
2931
chmod +x run-db-tests.sh
3032
./run-db-tests.sh
3133
```
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ param(
77
[string]$Table = "cache_items_test"
88
)
99

10+
# Start PostgreSQL Docker container
1011
Write-Host "Starting PostgreSQL Docker container..."
1112
docker run --name pgcache-test -e POSTGRES_DB=$DbName -e POSTGRES_USER=$User -e POSTGRES_PASSWORD=$Pass -p $Port:5432 -d postgres:16
1213

@@ -15,15 +16,20 @@ Start-Sleep -Seconds 10
1516
# Ensure pg_cron is installed (postgres:15+ already includes pg_cron)
1617
docker exec pgcache-test psql -U $User -d $DbName -c "CREATE EXTENSION IF NOT EXISTS pg_cron;"
1718

19+
# Export environment variables for test execution
1820
$env:PGCACHE_TEST_DB = $DbName
1921
$env:PGCACHE_TEST_USER = $User
2022
$env:PGCACHE_TEST_PASS = $Pass
2123
$env:PGCACHE_TEST_HOST = $DbHost
2224
$env:PGCACHE_TEST_PORT = $Port
2325
$env:PGCACHE_TEST_TABLE = $Table
2426

27+
# Run tests
28+
# The test project path is relative to this script location
29+
# If you move this script, update the path accordingly
2530
Write-Host "Running tests..."
2631
dotnet test ..\BKlug.Extensions.Caching.PostgreSql.Tests.csproj
2732

33+
# Clean up Docker container
2834
Write-Host "Removing Docker container..."
2935
docker rm -f pgcache-test
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22
set -e
33

4+
# Set environment variables with defaults if not provided
45
DB_NAME=${PGCACHE_TEST_DB:-cache_test}
56
USER=${PGCACHE_TEST_USER:-postgres}
67
PASS=${PGCACHE_TEST_PASS:-postgres}
@@ -10,7 +11,7 @@ TABLE=${PGCACHE_TEST_TABLE:-cache_items_test}
1011

1112
CONTAINER_NAME=pgcache-test
1213

13-
# Start PostgreSQL Docker container
14+
# Start PostgreSQL Docker container if not already running
1415
if [ ! $(docker ps -q -f name=$CONTAINER_NAME) ]; then
1516
echo "Starting PostgreSQL Docker container..."
1617
docker run --name $CONTAINER_NAME -e POSTGRES_DB=$DB_NAME -e POSTGRES_USER=$USER -e POSTGRES_PASSWORD=$PASS -p $PORT:5432 -d postgres:16
@@ -20,6 +21,7 @@ fi
2021
# Ensure pg_cron is installed (postgres:15+ already includes pg_cron)
2122
docker exec $CONTAINER_NAME psql -U $USER -d $DB_NAME -c "CREATE EXTENSION IF NOT EXISTS pg_cron;"
2223

24+
# Export environment variables for test execution
2325
export PGCACHE_TEST_DB=$DB_NAME
2426
export PGCACHE_TEST_USER=$USER
2527
export PGCACHE_TEST_PASS=$PASS
@@ -28,9 +30,11 @@ export PGCACHE_TEST_PORT=$PORT
2830
export PGCACHE_TEST_TABLE=$TABLE
2931

3032
# Run tests
33+
# The test project path is relative to this script location
34+
# If you move this script, update the path accordingly
3135
echo "Running tests..."
3236
dotnet test ../BKlug.Extensions.Caching.PostgreSql.Tests.csproj
3337

34-
# Clean up
38+
# Clean up Docker container
3539
echo "Removing Docker container..."
3640
docker rm -f $CONTAINER_NAME

0 commit comments

Comments
 (0)