mirror of
https://github.com/gofiber/storage.git
synced 2025-10-19 06:54:38 +08:00
fix tests
This commit is contained in:
@@ -68,7 +68,12 @@ func (t *TestModule) GetWorkersKV(ctx context.Context, rc *cloudflare.ResourceCo
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer func() {
|
||||||
|
err := resp.Body.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Error closing response body:", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
respBody, err := io.ReadAll(resp.Body)
|
respBody, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -111,7 +116,12 @@ func (t *TestModule) WriteWorkersKVEntry(ctx context.Context, rc *cloudflare.Res
|
|||||||
return cloudflare.Response{}, err
|
return cloudflare.Response{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer func() {
|
||||||
|
err := resp.Body.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Error closing response body:", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
return cloudflare.Response{
|
return cloudflare.Response{
|
||||||
Success: true,
|
Success: true,
|
||||||
@@ -148,7 +158,12 @@ func (t *TestModule) DeleteWorkersKVEntry(ctx context.Context, rc *cloudflare.Re
|
|||||||
return cloudflare.Response{}, err
|
return cloudflare.Response{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer func() {
|
||||||
|
err := resp.Body.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Error closing response body:", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
return cloudflare.Response{
|
return cloudflare.Response{
|
||||||
Success: true,
|
Success: true,
|
||||||
@@ -189,7 +204,12 @@ func (t *TestModule) ListWorkersKVKeys(ctx context.Context, rc *cloudflare.Resou
|
|||||||
return cloudflare.ListStorageKeysResponse{}, err
|
return cloudflare.ListStorageKeysResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer func() {
|
||||||
|
err := resp.Body.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Error closing response body:", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
result := []cloudflare.StorageKey{}
|
result := []cloudflare.StorageKey{}
|
||||||
|
|
||||||
|
@@ -125,6 +125,7 @@ func Test_Coherence_Set_And_GetWithContext(t *testing.T) {
|
|||||||
err := testStore.Set(key1, value1, 0)
|
err := testStore.Set(key1, value1, 0)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Coherence will create new context instance as the provided one is deadline exceeded.
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
cancel()
|
cancel()
|
||||||
|
|
||||||
@@ -144,12 +145,13 @@ func Test_Coherence_SetContext_And_Get(t *testing.T) {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Microsecond)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Microsecond)
|
||||||
cancel()
|
cancel()
|
||||||
|
|
||||||
|
// Coherencce will create new context instance as the provided one is deadline exceeded.
|
||||||
err := testStore.SetWithContext(ctx, key1, value1, 1*time.Nanosecond)
|
err := testStore.SetWithContext(ctx, key1, value1, 1*time.Nanosecond)
|
||||||
require.ErrorIs(t, err, context.DeadlineExceeded)
|
require.ErrorIs(t, err, context.DeadlineExceeded)
|
||||||
|
|
||||||
val, err = testStore.Get(key1)
|
val, err = testStore.Get(key1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, len(val) == 0)
|
require.False(t, len(val) == 0)
|
||||||
|
|
||||||
require.NotNil(t, testStore.Conn())
|
require.NotNil(t, testStore.Conn())
|
||||||
}
|
}
|
||||||
@@ -284,6 +286,7 @@ func Test_Coherence_ResetWithContext(t *testing.T) {
|
|||||||
require.Equal(t, value2, val)
|
require.Equal(t, value2, val)
|
||||||
|
|
||||||
// reset the store, this should remove both entries
|
// reset the store, this should remove both entries
|
||||||
|
// Coherence will create new context instance as the provided one is deadline exceeded.
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
cancel()
|
cancel()
|
||||||
err = testStore.ResetWithContext(ctx)
|
err = testStore.ResetWithContext(ctx)
|
||||||
@@ -292,11 +295,11 @@ func Test_Coherence_ResetWithContext(t *testing.T) {
|
|||||||
// check the keys have expired
|
// check the keys have expired
|
||||||
val, err = testStore.Get(key1)
|
val, err = testStore.Get(key1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.False(t, len(val) == 0)
|
require.True(t, len(val) == 0)
|
||||||
|
|
||||||
val, err = testStore.Get(key2)
|
val, err = testStore.Get(key2)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.False(t, len(val) == 0)
|
require.True(t, len(val) == 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_Coherence_Set_And_Delete(t *testing.T) {
|
func Test_Coherence_Set_And_Delete(t *testing.T) {
|
||||||
@@ -329,13 +332,14 @@ func Test_Coherence_Set_And_DeleteWithContext(t *testing.T) {
|
|||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
cancel()
|
cancel()
|
||||||
|
|
||||||
|
// Coherence will create new context instance as the provided one is deadline exceeded.
|
||||||
err = testStore.DeleteWithContext(ctx, key1)
|
err = testStore.DeleteWithContext(ctx, key1)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
// ensure the key has gone
|
// ensure the key has gone
|
||||||
val, err = testStore.Get(key1)
|
val, err = testStore.Get(key1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.False(t, len(val) == 0)
|
require.True(t, len(val) == 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestCoherenceWithScope ensures we can create multiple session stores with multiple scopes.
|
// TestCoherenceWithScope ensures we can create multiple session stores with multiple scopes.
|
||||||
|
Reference in New Issue
Block a user