mirror of
https://github.com/gofiber/storage.git
synced 2025-09-29 13:52:20 +08:00
Merge branch 'main' into add-withcontext
* main: (168 commits) chore: read redis image for ruedis chore: align ruedis expiration test with redis chore: skip cluster tests chore: align valkey expiration test with redis chore: refine message fix: reuse valkey container in benchmarks chore: pass the redis-like image explicitly in tests fix: missing eval of redis image from env var chore: proper parallel layout chore: add integration tests to the redis helper module chore: verify mtls properly in tests chore(deps): bump github.com/aws/aws-sdk-go-v2/feature/s3/manager in /s3 chore(deps): bump github.com/aws/aws-sdk-go-v2/service/s3 in /s3 chore(deps): bump github.com/ClickHouse/clickhouse-go/v2 in /clickhouse chore(deps): bump github.com/minio/minio-go/v7 in /minio chore(deps): bump github.com/valkey-io/valkey-go in /valkey chore(deps): bump github.com/jackc/pgx/v5 in /postgres chore: add tests for the helper module chore: make sure the client gets the variable locally fix(coherence): set coherence log level to ERROR in benchmarks ...
This commit is contained in:
@@ -2,15 +2,57 @@ package arangodb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/modules/arangodb"
|
||||
)
|
||||
|
||||
var testStore = New(Config{
|
||||
Reset: true,
|
||||
})
|
||||
const (
|
||||
// arangoDB is the default image used for running arangoDB in tests.
|
||||
arangoDBImage = "arangodb:latest"
|
||||
arangoDBImageEnvVar = "TEST_ARANGODB_IMAGE"
|
||||
arangoDBPassword = "test"
|
||||
)
|
||||
|
||||
func newTestStore(t testing.TB) *Storage {
|
||||
t.Helper()
|
||||
|
||||
img := arangoDBImage
|
||||
if imgFromEnv := os.Getenv(arangoDBImageEnvVar); imgFromEnv != "" {
|
||||
img = imgFromEnv
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
arangodbContainer, err := arangodb.Run(ctx, img, arangodb.WithRootPassword(arangoDBPassword))
|
||||
testcontainers.CleanupContainer(t, arangodbContainer)
|
||||
require.NoError(t, err)
|
||||
|
||||
endpoint, err := arangodbContainer.HTTPEndpoint(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
parsedURL, err := url.Parse(endpoint)
|
||||
require.NoError(t, err)
|
||||
host := parsedURL.Scheme + "://" + parsedURL.Hostname()
|
||||
port := parsedURL.Port()
|
||||
|
||||
iPort, err := strconv.Atoi(port)
|
||||
require.NoError(t, err)
|
||||
|
||||
return New(Config{
|
||||
Host: host,
|
||||
Port: iPort,
|
||||
Username: "root",
|
||||
Password: arangoDBPassword,
|
||||
})
|
||||
}
|
||||
|
||||
func Test_ArangoDB_Set(t *testing.T) {
|
||||
var (
|
||||
@@ -18,6 +60,9 @@ func Test_ArangoDB_Set(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
@@ -28,6 +73,9 @@ func Test_ArangoDB_SetWithContext(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
@@ -41,6 +89,9 @@ func Test_ArangoDB_Upsert(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -54,6 +105,9 @@ func Test_ArangoDB_Get(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -68,6 +122,9 @@ func Test_ArangoDB_GetWithContext(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -86,6 +143,9 @@ func Test_ArangoDB_Set_Expiration(t *testing.T) {
|
||||
exp = 1 * time.Second
|
||||
)
|
||||
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err := testStore.Set(key, val, exp)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -95,12 +155,18 @@ func Test_ArangoDB_Set_Expiration(t *testing.T) {
|
||||
func Test_ArangoDB_Get_Expired(t *testing.T) {
|
||||
key := "john"
|
||||
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
result, err := testStore.Get(key)
|
||||
require.NoError(t, err)
|
||||
require.Zero(t, len(result))
|
||||
}
|
||||
|
||||
func Test_ArangoDB_Get_NotExist(t *testing.T) {
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
result, err := testStore.Get("notexist")
|
||||
require.NoError(t, err)
|
||||
require.Zero(t, len(result))
|
||||
@@ -112,6 +178,9 @@ func Test_ArangoDB_Delete(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -129,6 +198,9 @@ func Test_ArangoDB_DeleteWithContext(t *testing.T) {
|
||||
val = []byte("doe")
|
||||
)
|
||||
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err := testStore.Set(key, val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -146,6 +218,9 @@ func Test_ArangoDB_DeleteWithContext(t *testing.T) {
|
||||
func Test_ArangoDB_Reset(t *testing.T) {
|
||||
val := []byte("doe")
|
||||
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err := testStore.Set("john1", val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -167,6 +242,9 @@ func Test_ArangoDB_Reset(t *testing.T) {
|
||||
func Test_ArangoDB_ResetWithContext(t *testing.T) {
|
||||
val := []byte("doe")
|
||||
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err := testStore.Set("john1", val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -191,6 +269,9 @@ func Test_ArangoDB_ResetWithContext(t *testing.T) {
|
||||
func Test_ArangoDB_Non_UTF8(t *testing.T) {
|
||||
val := []byte("0xF5")
|
||||
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
err := testStore.Set("0xF6", val, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -200,14 +281,21 @@ func Test_ArangoDB_Non_UTF8(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_ArangoDB_Close(t *testing.T) {
|
||||
testStore := newTestStore(t)
|
||||
require.Nil(t, testStore.Close())
|
||||
}
|
||||
|
||||
func Test_ArangoDB_Conn(t *testing.T) {
|
||||
testStore := newTestStore(t)
|
||||
defer testStore.Close()
|
||||
|
||||
require.True(t, testStore.Conn() != nil)
|
||||
}
|
||||
|
||||
func Benchmark_ArangoDB_Set(b *testing.B) {
|
||||
testStore := newTestStore(b)
|
||||
defer testStore.Close()
|
||||
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
|
||||
@@ -220,6 +308,9 @@ func Benchmark_ArangoDB_Set(b *testing.B) {
|
||||
}
|
||||
|
||||
func Benchmark_ArangoDB_Get(b *testing.B) {
|
||||
testStore := newTestStore(b)
|
||||
defer testStore.Close()
|
||||
|
||||
err := testStore.Set("john", []byte("doe"), 0)
|
||||
require.NoError(b, err)
|
||||
|
||||
@@ -234,6 +325,9 @@ func Benchmark_ArangoDB_Get(b *testing.B) {
|
||||
}
|
||||
|
||||
func Benchmark_ArangoDB_SetAndDelete(b *testing.B) {
|
||||
testStore := newTestStore(b)
|
||||
defer testStore.Close()
|
||||
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
|
||||
|
Reference in New Issue
Block a user