mirror of
https://github.com/gofiber/storage.git
synced 2025-10-04 08:16:36 +08:00
review updates
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
package neo4jstore
|
||||
package neo4j
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -11,15 +10,14 @@ import (
|
||||
"github.com/testcontainers/testcontainers-go/modules/neo4j"
|
||||
)
|
||||
|
||||
var testStore *Storage
|
||||
const neo4jImgVer string = "neo4j:5.26"
|
||||
|
||||
// TestMain sets up and tears down the test container
|
||||
func TestMain(m *testing.M) {
|
||||
func startContainer() (*Storage, func()) {
|
||||
ctx := context.Background()
|
||||
|
||||
// Start a Neo4j test container
|
||||
neo4jContainer, err := neo4j.Run(ctx,
|
||||
"neo4j:5.26",
|
||||
neo4jImgVer,
|
||||
neo4j.WithAdminPassword("pass#w*#d"),
|
||||
)
|
||||
if err != nil {
|
||||
@@ -40,21 +38,23 @@ func TestMain(m *testing.M) {
|
||||
Password: "pass#w*#d",
|
||||
})
|
||||
|
||||
testStore = store
|
||||
return store, func() {
|
||||
store.Close()
|
||||
|
||||
defer testStore.Close()
|
||||
defer func() {
|
||||
if err := neo4jContainer.Terminate(ctx); err != nil {
|
||||
log.Printf("Failed to terminate Neo4j container: %v", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
code := m.Run()
|
||||
|
||||
os.Exit(code)
|
||||
}
|
||||
|
||||
func Test_Neo4jStore_Set(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testStore, cleanup := startContainer()
|
||||
|
||||
t.Cleanup(cleanup)
|
||||
|
||||
var (
|
||||
key = "john"
|
||||
val = []byte("doe")
|
||||
@@ -65,6 +65,12 @@ func Test_Neo4jStore_Set(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_Neo4jStore_Upsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testStore, cleanup := startContainer()
|
||||
|
||||
t.Cleanup(cleanup)
|
||||
|
||||
var (
|
||||
key = "john"
|
||||
val = []byte("doe")
|
||||
@@ -78,6 +84,12 @@ func Test_Neo4jStore_Upsert(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_Neo4jStore_Get(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testStore, cleanup := startContainer()
|
||||
|
||||
t.Cleanup(cleanup)
|
||||
|
||||
var (
|
||||
key = "john"
|
||||
val = []byte("doe")
|
||||
@@ -92,6 +104,12 @@ func Test_Neo4jStore_Get(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_Neo4jStore_Set_Expiration(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testStore, cleanup := startContainer()
|
||||
|
||||
t.Cleanup(cleanup)
|
||||
|
||||
var (
|
||||
key = "john"
|
||||
val = []byte("doe")
|
||||
@@ -109,6 +127,12 @@ func Test_Neo4jStore_Set_Expiration(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_Neo4jStore_Get_Expired(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testStore, cleanup := startContainer()
|
||||
|
||||
t.Cleanup(cleanup)
|
||||
|
||||
key := "john"
|
||||
|
||||
result, err := testStore.Get(key)
|
||||
@@ -117,12 +141,24 @@ func Test_Neo4jStore_Get_Expired(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_Neo4jStore_Get_NotExist(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testStore, cleanup := startContainer()
|
||||
|
||||
t.Cleanup(cleanup)
|
||||
|
||||
result, err := testStore.Get("notexist")
|
||||
require.NoError(t, err)
|
||||
require.Zero(t, len(result))
|
||||
}
|
||||
|
||||
func Test_Neo4jStore_Delete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testStore, cleanup := startContainer()
|
||||
|
||||
t.Cleanup(cleanup)
|
||||
|
||||
var (
|
||||
key = "john"
|
||||
val = []byte("doe")
|
||||
@@ -140,6 +176,12 @@ func Test_Neo4jStore_Delete(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_Neo4jStore_Reset(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testStore, cleanup := startContainer()
|
||||
|
||||
t.Cleanup(cleanup)
|
||||
|
||||
val := []byte("doe")
|
||||
|
||||
err := testStore.Set("john1", val, 0)
|
||||
@@ -161,6 +203,12 @@ func Test_Neo4jStore_Reset(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_Neo4jStore_Non_UTF8(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testStore, cleanup := startContainer()
|
||||
|
||||
t.Cleanup(cleanup)
|
||||
|
||||
val := []byte("0xF5")
|
||||
|
||||
err := testStore.Set("0xF6", val, 0)
|
||||
@@ -172,14 +220,29 @@ func Test_Neo4jStore_Non_UTF8(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_Neo4jStore_Close(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testStore, cleanup := startContainer()
|
||||
|
||||
t.Cleanup(cleanup)
|
||||
|
||||
require.Nil(t, testStore.Close())
|
||||
}
|
||||
|
||||
func Test_Neo4jStore_Conn(t *testing.T) {
|
||||
t.Parallel()
|
||||
testStore, cleanup := startContainer()
|
||||
|
||||
t.Cleanup(cleanup)
|
||||
|
||||
require.True(t, testStore.Conn() != nil)
|
||||
}
|
||||
|
||||
func Benchmark_Neo4jStore_Set(b *testing.B) {
|
||||
testStore, cleanup := startContainer()
|
||||
|
||||
b.Cleanup(cleanup)
|
||||
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
|
||||
@@ -192,6 +255,10 @@ func Benchmark_Neo4jStore_Set(b *testing.B) {
|
||||
}
|
||||
|
||||
func Benchmark_Neo4jStore_Get(b *testing.B) {
|
||||
testStore, cleanup := startContainer()
|
||||
|
||||
b.Cleanup(cleanup)
|
||||
|
||||
err := testStore.Set("john", []byte("doe"), 0)
|
||||
require.NoError(b, err)
|
||||
|
||||
@@ -206,6 +273,10 @@ func Benchmark_Neo4jStore_Get(b *testing.B) {
|
||||
}
|
||||
|
||||
func Benchmark_Neo4jStore_SetAndDelete(b *testing.B) {
|
||||
testStore, cleanup := startContainer()
|
||||
|
||||
b.Cleanup(cleanup)
|
||||
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
|
||||
|
Reference in New Issue
Block a user