mirror of
https://github.com/gofiber/storage.git
synced 2025-10-05 08:37:10 +08:00
fix tests
This commit is contained in:
@@ -69,6 +69,9 @@ func Test_AzureBlob_GetWithContext(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -99,6 +102,9 @@ func Test_AzureBlob_SetWithContext(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
@@ -137,6 +143,9 @@ func Test_AzureBlob_DeleteWithContext(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@@ -84,18 +84,17 @@ func Test_Connection(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_SetWithContext(t *testing.T) {
|
||||
client, err := getTestConnection(t, Config{
|
||||
client := newTestStore(t, Config{
|
||||
Engine: Memory,
|
||||
Table: "test_table",
|
||||
Clean: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
defer client.Close()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
err = client.SetWithContext(ctx, "somekey", []byte("somevalue"), 0)
|
||||
err := client.SetWithContext(ctx, "somekey", []byte("somevalue"), 0)
|
||||
require.ErrorIs(t, err, context.Canceled)
|
||||
}
|
||||
|
||||
@@ -124,15 +123,14 @@ func Test_Set_With_Exp(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_GetWithContext(t *testing.T) {
|
||||
client, err := getTestConnection(t, Config{
|
||||
client := newTestStore(t, Config{
|
||||
Engine: Memory,
|
||||
Table: "test_table",
|
||||
Clean: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
defer client.Close()
|
||||
|
||||
err = client.Set("somekey", []byte("somevalue"), 0)
|
||||
err := client.Set("somekey", []byte("somevalue"), 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
@@ -187,16 +185,15 @@ func Test_Get_With_Exp(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_DeleteWithContext(t *testing.T) {
|
||||
client, err := getTestConnection(t, Config{
|
||||
client := newTestStore(t, Config{
|
||||
Engine: Memory,
|
||||
Table: "test_table",
|
||||
Clean: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
defer client.Close()
|
||||
|
||||
err = client.Set("somekeytodelete", []byte("somevalue"), time.Second*5)
|
||||
err := client.Set("somekeytodelete", []byte("somevalue"), time.Second*5)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
@@ -232,16 +229,15 @@ func Test_Delete(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_ResetWithContext(t *testing.T) {
|
||||
client, err := getTestConnection(t, Config{
|
||||
client := newTestStore(t, Config{
|
||||
Engine: Memory,
|
||||
Table: "test_table",
|
||||
Clean: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
defer client.Close()
|
||||
|
||||
err = client.Set("testkey", []byte("somevalue"), 0)
|
||||
err := client.Set("testkey", []byte("somevalue"), 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
@@ -62,13 +62,12 @@ func TestSetCouchbase_ShouldReturnNoError(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSetWithContextCouchbase_ContextCancelled_ShouldReturnError(t *testing.T) {
|
||||
testStore, err := newTestStore(t)
|
||||
require.NoError(t, err)
|
||||
testStore := newTestStore(t)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Microsecond)
|
||||
defer cancel()
|
||||
|
||||
err = testStore.SetWithContext(ctx, "test", []byte("test"), 0)
|
||||
err := testStore.SetWithContext(ctx, "test", []byte("test"), 0)
|
||||
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
@@ -69,11 +69,10 @@ func Test_DynamoDB_SetWithContext(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
testStore, err := newTestStore(t)
|
||||
require.NoError(t, err)
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err = testStore.SetWithContext(ctx, key, val, 0)
|
||||
err := testStore.SetWithContext(ctx, key, val, 0)
|
||||
require.ErrorIs(t, err, context.Canceled)
|
||||
}
|
||||
|
||||
@@ -118,8 +117,7 @@ func Test_DynamoDB_GetWithContext(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
testStore, err := newTestStore(t)
|
||||
require.NoError(t, err)
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
result, err := testStore.GetWithContext(ctx, key)
|
||||
@@ -162,11 +160,10 @@ func Test_DynamoDB_DeleteWithContext(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore, err := newTestStore(t)
|
||||
require.NoError(t, err)
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err = testStore.Set(key, val, 0)
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
@@ -207,11 +204,10 @@ func Test_DynamoDB_Reset(t *testing.T) {
|
||||
func Test_DynamoDB_ResetWithContext(t *testing.T) {
|
||||
val := []byte("doe")
|
||||
|
||||
testStore, err := newTestStore(t)
|
||||
require.NoError(t, err)
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err = testStore.Set("john1", val, 0)
|
||||
err := testStore.Set("john1", val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = testStore.Set("john2", val, 0)
|
||||
|
@@ -310,7 +310,7 @@ func Test_ResetWithContext(t *testing.T) {
|
||||
cancel()
|
||||
|
||||
err = testStore.ResetWithContext(ctx)
|
||||
require.NoError(t, err)
|
||||
require.ErrorIs(t, err, context.Canceled)
|
||||
|
||||
result, err := testStore.Get("john1")
|
||||
require.NoError(t, err)
|
||||
@@ -322,6 +322,9 @@ func Test_Reset_Not_Exists_Bucket(t *testing.T) {
|
||||
defer testStore.Close()
|
||||
|
||||
err := testStore.RemoveBucket()
|
||||
require.NoError(t, err)
|
||||
|
||||
err = testStore.Reset()
|
||||
require.Error(t, err)
|
||||
require.EqualError(t, err, "The specified bucket does not exist")
|
||||
}
|
||||
|
@@ -75,11 +75,10 @@ func Test_MongoDB_SetWithContext(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
testStore, err := newTestStore(t)
|
||||
require.NoError(t, err)
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err = testStore.SetWithContext(ctx, key, val, 0)
|
||||
err := testStore.SetWithContext(ctx, key, val, 0)
|
||||
require.ErrorIs(t, err, context.Canceled)
|
||||
}
|
||||
|
||||
@@ -122,11 +121,10 @@ func Test_MongoDB_GetWithContext(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore, err := newTestStore(t)
|
||||
require.NoError(t, err)
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err = testStore.Set(key, val, 0)
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
@@ -203,11 +201,10 @@ func Test_MongoDB_DeleteWithContext(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore, err := newTestStore(t)
|
||||
require.NoError(t, err)
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err = testStore.Set(key, val, 0)
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
@@ -248,11 +245,10 @@ func Test_MongoDB_Reset(t *testing.T) {
|
||||
func Test_MongoDB_ResetWithContext(t *testing.T) {
|
||||
val := []byte("doe")
|
||||
|
||||
testStore, err := newTestStore(t)
|
||||
require.NoError(t, err)
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err = testStore.Set("john1", val, 0)
|
||||
err := testStore.Set("john1", val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = testStore.Set("john2", val, 0)
|
||||
|
@@ -99,11 +99,10 @@ func Test_MYSQL_SetWithContext(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
testStore, err := newTestStore(t)
|
||||
require.NoError(t, err)
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err = testStore.SetWithContext(ctx, key, val, 0)
|
||||
err := testStore.SetWithContext(ctx, key, val, 0)
|
||||
require.ErrorIs(t, err, context.Canceled)
|
||||
}
|
||||
|
||||
@@ -146,11 +145,10 @@ func Test_MYSQL_GetWithContext(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore, err := newTestStore(t)
|
||||
require.NoError(t, err)
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err = testStore.Set(key, val, 0)
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
@@ -227,11 +225,10 @@ func Test_MYSQL_DeleteWithContext(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore, err := newTestStore(t)
|
||||
require.NoError(t, err)
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err = testStore.Set(key, val, 0)
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
@@ -272,11 +269,10 @@ func Test_MYSQL_Reset(t *testing.T) {
|
||||
func Test_MYSQL_ResetWithContext(t *testing.T) {
|
||||
val := []byte("doe")
|
||||
|
||||
testStore, err := newTestStore(t)
|
||||
require.NoError(t, err)
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err = testStore.Set("john1", val, 0)
|
||||
err := testStore.Set("john1", val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = testStore.Set("john2", val, 0)
|
||||
|
@@ -168,14 +168,12 @@ func Test_Storage_Nats_SetWithContext(t *testing.T) {
|
||||
key = "john"
|
||||
val = []byte("doe")
|
||||
)
|
||||
testStore, err := newTestStore(t)
|
||||
require.NoError(t, err)
|
||||
defer testStore.Close()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
err = testStore.SetWithContext(ctx, key, val, 0)
|
||||
err := testStore.SetWithContext(ctx, key, val, 0)
|
||||
require.ErrorIs(t, err, context.Canceled)
|
||||
|
||||
keys, err := testStore.Keys()
|
||||
@@ -235,14 +233,12 @@ func Test_Storage_Nats_GetWithContext(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore, err := newTestStore(t)
|
||||
require.NoError(t, err)
|
||||
defer testStore.Close()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
err = testStore.Set(key, val, 30*time.Second)
|
||||
err := testStore.Set(key, val, 30*time.Second)
|
||||
require.NoError(t, err)
|
||||
|
||||
result, err := testStore.GetWithContext(ctx, key)
|
||||
@@ -359,11 +355,9 @@ func Test_Storage_Nats_DeleteWithContext(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore, err := newTestStore(t)
|
||||
require.NoError(t, err)
|
||||
defer testStore.Close()
|
||||
|
||||
err = testStore.Set(key, val, 5*time.Second)
|
||||
err := testStore.Set(key, val, 5*time.Second)
|
||||
require.NoError(t, err)
|
||||
|
||||
keys, err := testStore.Keys()
|
||||
|
@@ -248,11 +248,10 @@ func Test_Postgres_SetWithContext(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
testStore, err := newTestStore(t)
|
||||
require.NoError(t, err)
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err = testStore.SetWithContext(ctx, key, val, 0)
|
||||
err := testStore.SetWithContext(ctx, key, val, 0)
|
||||
require.ErrorIs(t, err, context.Canceled)
|
||||
}
|
||||
|
||||
@@ -295,11 +294,10 @@ func Test_Postgres_GetWithContext(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore, err := newTestStore(t)
|
||||
require.NoError(t, err)
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err = testStore.Set(key, val, 0)
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
@@ -376,11 +374,10 @@ func Test_Postgres_DeleteWithContext(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore, err := newTestStore(t)
|
||||
require.NoError(t, err)
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err = testStore.Set(key, val, 0)
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
@@ -417,11 +414,10 @@ func Test_Postgres_Reset(t *testing.T) {
|
||||
func Test_Postgres_ResetWithContext(t *testing.T) {
|
||||
val := []byte("doe")
|
||||
|
||||
testStore, err := newTestStore(t)
|
||||
require.NoError(t, err)
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err = testStore.Set("john1", val, 0)
|
||||
err := testStore.Set("john1", val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = testStore.Set("john2", val, 0)
|
||||
|
@@ -26,6 +26,9 @@ func Test_S3_SetWithContext(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
@@ -72,6 +75,9 @@ func Test_S3_GetWithContext(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -118,6 +124,9 @@ func Test_S3_DeleteWithContext(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -159,6 +168,9 @@ func Test_S3_Reset(t *testing.T) {
|
||||
func Test_S3_ResetWithContext(t *testing.T) {
|
||||
val := []byte("doe")
|
||||
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err := testStore.Set("john1", val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@@ -68,6 +68,9 @@ func Test_Scylla_SetWithContext(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
@@ -123,6 +126,9 @@ func Test_Scylla_GetWithContext(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -189,6 +195,9 @@ func Test_Scylla_DeleteWithContext(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -230,6 +239,9 @@ func Test_Scylla_Reset(t *testing.T) {
|
||||
func Test_Scylla_ResetWithContext(t *testing.T) {
|
||||
val := []byte("doe")
|
||||
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err := testStore.Set("john1", val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
Reference in New Issue
Block a user