mirror of
https://github.com/gofiber/storage.git
synced 2025-10-12 20:11:09 +08:00
sqlite3: add support for context management
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package sqlite3
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -23,6 +24,19 @@ func Test_SQLite3_Set(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func Test_SQLite3_SetWithContext(t *testing.T) {
|
||||
var (
|
||||
key = "john"
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
err := testStore.SetWithContext(ctx, key, val, 0)
|
||||
require.ErrorIs(t, err, context.Canceled)
|
||||
}
|
||||
|
||||
func Test_SQLite3_Set_Override(t *testing.T) {
|
||||
var (
|
||||
key = "john"
|
||||
@@ -50,6 +64,23 @@ func Test_SQLite3_Get(t *testing.T) {
|
||||
require.Equal(t, val, result)
|
||||
}
|
||||
|
||||
func Test_SQLite3_GetWithContext(t *testing.T) {
|
||||
var (
|
||||
key = "john"
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
result, err := testStore.GetWithContext(ctx, key)
|
||||
require.ErrorIs(t, err, context.Canceled)
|
||||
require.Zero(t, len(result))
|
||||
}
|
||||
|
||||
func Test_SQLite3_Set_Expiration(t *testing.T) {
|
||||
var (
|
||||
key = "john"
|
||||
@@ -94,6 +125,26 @@ func Test_SQLite3_Delete(t *testing.T) {
|
||||
require.Zero(t, len(result))
|
||||
}
|
||||
|
||||
func Test_SQLite3_DeleteWithContext(t *testing.T) {
|
||||
var (
|
||||
key = "john"
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
err = testStore.DeleteWithContext(ctx, key)
|
||||
require.ErrorIs(t, err, context.Canceled)
|
||||
|
||||
result, err := testStore.Get(key)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, val, result)
|
||||
}
|
||||
|
||||
func Test_SQLite3_Reset(t *testing.T) {
|
||||
val := []byte("doe")
|
||||
|
||||
@@ -115,6 +166,30 @@ func Test_SQLite3_Reset(t *testing.T) {
|
||||
require.Zero(t, len(result))
|
||||
}
|
||||
|
||||
func Test_SQLite3_ResetWithContext(t *testing.T) {
|
||||
val := []byte("doe")
|
||||
|
||||
err := testStore.Set("john1", val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = testStore.Set("john2", val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
err = testStore.ResetWithContext(ctx)
|
||||
require.ErrorIs(t, err, context.Canceled)
|
||||
|
||||
result, err := testStore.Get("john1")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, val, result)
|
||||
|
||||
result, err = testStore.Get("john2")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, val, result)
|
||||
}
|
||||
|
||||
func Test_SQLite3_GC(t *testing.T) {
|
||||
testVal := []byte("doe")
|
||||
|
||||
|
Reference in New Issue
Block a user