Use testify.Require for all Storage Drivers

This commit is contained in:
Juan Calderon-Perez
2023-08-19 22:36:33 -04:00
parent 2779bfdf01
commit 02d809987a
66 changed files with 811 additions and 691 deletions

View File

@@ -7,7 +7,7 @@ import (
"github.com/arangodb/go-driver" "github.com/arangodb/go-driver"
"github.com/arangodb/go-driver/http" "github.com/arangodb/go-driver/http"
"github.com/gofiber/utils" "github.com/gofiber/utils/v2"
) )
// Storage interface that is implemented by storage providers // Storage interface that is implemented by storage providers

View File

@@ -4,7 +4,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/gofiber/utils" "github.com/stretchr/testify/require"
) )
var testStore = New(Config{ var testStore = New(Config{
@@ -18,7 +18,7 @@ func Test_ARANGODB_Set(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_ARANGODB_Upsert(t *testing.T) { func Test_ARANGODB_Upsert(t *testing.T) {
@@ -28,10 +28,10 @@ func Test_ARANGODB_Upsert(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set(key, val, 0) err = testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_ARANGODB_Get(t *testing.T) { func Test_ARANGODB_Get(t *testing.T) {
@@ -41,11 +41,11 @@ func Test_ARANGODB_Get(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
} }
func Test_ARANGODB_Set_Expiration(t *testing.T) { func Test_ARANGODB_Set_Expiration(t *testing.T) {
@@ -56,26 +56,23 @@ func Test_ARANGODB_Set_Expiration(t *testing.T) {
) )
err := testStore.Set(key, val, exp) err := testStore.Set(key, val, exp)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
time.Sleep(1100 * time.Millisecond) time.Sleep(1100 * time.Millisecond)
} }
func Test_ARANGODB_Get_Expired(t *testing.T) { func Test_ARANGODB_Get_Expired(t *testing.T) {
var ( key := "john"
key = "john"
)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_ARANGODB_Get_NotExist(t *testing.T) { func Test_ARANGODB_Get_NotExist(t *testing.T) {
result, err := testStore.Get("notexist") result, err := testStore.Get("notexist")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_ARANGODB_Delete(t *testing.T) { func Test_ARANGODB_Delete(t *testing.T) {
@@ -85,54 +82,52 @@ func Test_ARANGODB_Delete(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Delete(key) err = testStore.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_ARANGODB_Reset(t *testing.T) { func Test_ARANGODB_Reset(t *testing.T) {
var ( val := []byte("doe")
val = []byte("doe")
)
err := testStore.Set("john1", val, 0) err := testStore.Set("john1", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set("john2", val, 0) err = testStore.Set("john2", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Reset() err = testStore.Reset()
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get("john1") result, err := testStore.Get("john1")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
result, err = testStore.Get("john2") result, err = testStore.Get("john2")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_ARANGODB_Non_UTF8(t *testing.T) { func Test_ARANGODB_Non_UTF8(t *testing.T) {
val := []byte("0xF5") val := []byte("0xF5")
err := testStore.Set("0xF6", val, 0) err := testStore.Set("0xF6", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get("0xF6") result, err := testStore.Get("0xF6")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
} }
func Test_ARANGODB_Close(t *testing.T) { func Test_ARANGODB_Close(t *testing.T) {
utils.AssertEqual(t, nil, testStore.Close()) require.Nil(t, testStore.Close())
} }
func Test_ARANGODB_Conn(t *testing.T) { func Test_ARANGODB_Conn(t *testing.T) {
utils.AssertEqual(t, true, testStore.Conn() != nil) require.True(t, testStore.Conn() != nil)
} }

View File

@@ -4,10 +4,15 @@ go 1.18
require ( require (
github.com/arangodb/go-driver v1.6.0 github.com/arangodb/go-driver v1.6.0
github.com/gofiber/utils v1.1.0 github.com/gofiber/utils/v2 v2.0.0-beta.3
github.com/stretchr/testify v1.8.3
) )
require ( require (
github.com/arangodb/go-velocypack v0.0.0-20200318135517-5af53c29c67e // indirect github.com/arangodb/go-velocypack v0.0.0-20200318135517-5af53c29c67e // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
) )

View File

@@ -2,17 +2,23 @@ github.com/arangodb/go-driver v1.6.0 h1:NFWj/idqXZxhFVueihMSI2R9NotNIsgvNfM/xmpe
github.com/arangodb/go-driver v1.6.0/go.mod h1:HQmdGkvNMVBTE3SIPSQ8T/ZddC6iwNsfMR+dDJQxIsI= github.com/arangodb/go-driver v1.6.0/go.mod h1:HQmdGkvNMVBTE3SIPSQ8T/ZddC6iwNsfMR+dDJQxIsI=
github.com/arangodb/go-velocypack v0.0.0-20200318135517-5af53c29c67e h1:Xg+hGrY2LcQBbxd0ZFdbGSyRKTYMZCfBbw/pMJFOk1g= github.com/arangodb/go-velocypack v0.0.0-20200318135517-5af53c29c67e h1:Xg+hGrY2LcQBbxd0ZFdbGSyRKTYMZCfBbw/pMJFOk1g=
github.com/arangodb/go-velocypack v0.0.0-20200318135517-5af53c29c67e/go.mod h1:mq7Shfa/CaixoDxiyAAc5jZ6CVBAyPaNQCGS7mkj4Ho= github.com/arangodb/go-velocypack v0.0.0-20200318135517-5af53c29c67e/go.mod h1:mq7Shfa/CaixoDxiyAAc5jZ6CVBAyPaNQCGS7mkj4Ho=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gofiber/utils/v2 v2.0.0-beta.3 h1:pfOhUDDVjBJpkWv6C5jaDyYLvpui7zQ97zpyFFsUOKw=
github.com/gofiber/utils/v2 v2.0.0-beta.3/go.mod h1:jsl17+MsKfwJjM3ONCE9Rzji/j8XNbwjhUVTjzgfDCo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -4,10 +4,11 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/bloberror"
"io" "io"
"time" "time"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/bloberror"
) )
// Storage interface that is implemented by storage providers // Storage interface that is implemented by storage providers

View File

@@ -1,9 +1,10 @@
package azureblob package azureblob
import ( import (
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/bloberror"
"github.com/gofiber/fiber/v2/utils"
"testing" "testing"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/bloberror"
"github.com/stretchr/testify/require"
) )
func newStore() *Storage { func newStore() *Storage {
@@ -17,6 +18,7 @@ func newStore() *Storage {
}, },
}) })
} }
func Test_AzureBlob_Get(t *testing.T) { func Test_AzureBlob_Get(t *testing.T) {
var ( var (
key = "john" key = "john"
@@ -25,11 +27,11 @@ func Test_AzureBlob_Get(t *testing.T) {
testStore := newStore() testStore := newStore()
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
} }
func Test_AzureBlob_Set(t *testing.T) { func Test_AzureBlob_Set(t *testing.T) {
@@ -40,7 +42,7 @@ func Test_AzureBlob_Set(t *testing.T) {
testStore := newStore() testStore := newStore()
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_AzureBlob_Delete(t *testing.T) { func Test_AzureBlob_Delete(t *testing.T) {
@@ -51,10 +53,10 @@ func Test_AzureBlob_Delete(t *testing.T) {
testStore := newStore() testStore := newStore()
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Delete(key) err = testStore.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
if err != nil { if err != nil {
@@ -62,8 +64,8 @@ func Test_AzureBlob_Delete(t *testing.T) {
err = nil err = nil
} }
} }
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_AzureBlob_Override(t *testing.T) { func Test_AzureBlob_Override(t *testing.T) {
@@ -74,10 +76,10 @@ func Test_AzureBlob_Override(t *testing.T) {
testStore := newStore() testStore := newStore()
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set(key, val, 0) err = testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_AzureBlob_Get_NotExist(t *testing.T) { func Test_AzureBlob_Get_NotExist(t *testing.T) {
@@ -88,24 +90,22 @@ func Test_AzureBlob_Get_NotExist(t *testing.T) {
err = nil err = nil
} }
} }
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_AzureBlob_Reset(t *testing.T) { func Test_AzureBlob_Reset(t *testing.T) {
var ( val := []byte("doe")
val = []byte("doe")
)
testStore := newStore() testStore := newStore()
err := testStore.Set("john1", val, 0) err := testStore.Set("john1", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set("john2", val, 0) err = testStore.Set("john2", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Reset() err = testStore.Reset()
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get("john1") result, err := testStore.Get("john1")
if err != nil { if err != nil {
@@ -113,8 +113,8 @@ func Test_AzureBlob_Reset(t *testing.T) {
err = nil err = nil
} }
} }
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
result, err = testStore.Get("john2") result, err = testStore.Get("john2")
if err != nil { if err != nil {
@@ -122,16 +122,16 @@ func Test_AzureBlob_Reset(t *testing.T) {
err = nil err = nil
} }
} }
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_S3_Conn(t *testing.T) { func Test_S3_Conn(t *testing.T) {
testStore := newStore() testStore := newStore()
utils.AssertEqual(t, true, testStore.Conn() != nil) require.True(t, testStore.Conn() != nil)
} }
func Test_AzureBlob_Close(t *testing.T) { func Test_AzureBlob_Close(t *testing.T) {
testStore := newStore() testStore := newStore()
utils.AssertEqual(t, nil, testStore.Close()) require.Nil(t, testStore.Close())
} }

View File

@@ -4,14 +4,17 @@ go 1.18
require ( require (
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.6.1 github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.6.1
github.com/gofiber/fiber/v2 v2.43.0 github.com/stretchr/testify v1.7.1
) )
require ( require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.2.0 // indirect github.com/Azure/azure-sdk-for-go/sdk/azcore v1.2.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.1.2 // indirect github.com/Azure/azure-sdk-for-go/sdk/internal v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.3.0 // indirect github.com/google/uuid v1.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/crypto v0.7.0 // indirect golang.org/x/crypto v0.7.0 // indirect
golang.org/x/net v0.8.0 // indirect golang.org/x/net v0.8.0 // indirect
golang.org/x/text v0.8.0 // indirect golang.org/x/text v0.8.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
) )

View File

@@ -6,17 +6,20 @@ github.com/Azure/azure-sdk-for-go/sdk/internal v1.1.2/go.mod h1:eWRD7oawr1Mu1sLC
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.6.1 h1:YvQv9Mz6T8oR5ypQOL6erY0Z5t71ak1uHV4QFokCOZk= github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.6.1 h1:YvQv9Mz6T8oR5ypQOL6erY0Z5t71ak1uHV4QFokCOZk=
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.6.1/go.mod h1:c6WvOhtmjNUWbLfOG1qxM/q0SPvQNSVJvolm+C52dIU= github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.6.1/go.mod h1:c6WvOhtmjNUWbLfOG1qxM/q0SPvQNSVJvolm+C52dIU=
github.com/AzureAD/microsoft-authentication-library-for-go v0.5.1 h1:BWe8a+f/t+7KY7zH2mqygeUD0t8hNFXe08p1Pb3/jKE= github.com/AzureAD/microsoft-authentication-library-for-go v0.5.1 h1:BWe8a+f/t+7KY7zH2mqygeUD0t8hNFXe08p1Pb3/jKE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c= github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c=
github.com/gofiber/fiber/v2 v2.43.0 h1:yit3E4kHf178B60p5CQBa/3v+WVuziWMa/G2ZNyLJB0=
github.com/gofiber/fiber/v2 v2.43.0/go.mod h1:mpS1ZNE5jU+u+BA4FbM+KKnUzJ4wzTK+FT2tG3tU+6I=
github.com/golang-jwt/jwt v3.2.1+incompatible h1:73Z+4BJcrTC+KczS6WvTPvRGOp1WmfEP4Q1lOd9Z/+c= github.com/golang-jwt/jwt v3.2.1+incompatible h1:73Z+4BJcrTC+KczS6WvTPvRGOp1WmfEP4Q1lOd9Z/+c=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 h1:Qj1ukM4GlMWXNdMBuXcXfz/Kw9s1qm0CLY32QxuSImI= github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 h1:Qj1ukM4GlMWXNdMBuXcXfz/Kw9s1qm0CLY32QxuSImI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
@@ -24,5 +27,9 @@ golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -4,7 +4,7 @@ import (
"time" "time"
"github.com/dgraph-io/badger/v3" "github.com/dgraph-io/badger/v3"
"github.com/gofiber/utils" "github.com/gofiber/utils/v2"
) )
// Storage interface that is implemented by storage providers // Storage interface that is implemented by storage providers

View File

@@ -4,7 +4,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/gofiber/utils" "github.com/stretchr/testify/require"
) )
var testStore = New() var testStore = New()
@@ -16,7 +16,7 @@ func Test_Badger_Set(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_Badger_Set_Override(t *testing.T) { func Test_Badger_Set_Override(t *testing.T) {
@@ -26,10 +26,10 @@ func Test_Badger_Set_Override(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set(key, val, 0) err = testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_Badger_Get(t *testing.T) { func Test_Badger_Get(t *testing.T) {
@@ -39,11 +39,11 @@ func Test_Badger_Get(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
} }
func Test_Badger_Set_Expiration(t *testing.T) { func Test_Badger_Set_Expiration(t *testing.T) {
@@ -54,26 +54,23 @@ func Test_Badger_Set_Expiration(t *testing.T) {
) )
err := testStore.Set(key, val, exp) err := testStore.Set(key, val, exp)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
time.Sleep(1100 * time.Millisecond) time.Sleep(1100 * time.Millisecond)
} }
func Test_Badger_Get_Expired(t *testing.T) { func Test_Badger_Get_Expired(t *testing.T) {
var ( key := "john"
key = "john"
)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Badger_Get_NotExist(t *testing.T) { func Test_Badger_Get_NotExist(t *testing.T) {
result, err := testStore.Get("notexist") result, err := testStore.Get("notexist")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Badger_Delete(t *testing.T) { func Test_Badger_Delete(t *testing.T) {
@@ -83,43 +80,41 @@ func Test_Badger_Delete(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Delete(key) err = testStore.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Badger_Reset(t *testing.T) { func Test_Badger_Reset(t *testing.T) {
var ( val := []byte("doe")
val = []byte("doe")
)
err := testStore.Set("john1", val, 0) err := testStore.Set("john1", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set("john2", val, 0) err = testStore.Set("john2", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Reset() err = testStore.Reset()
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get("john1") result, err := testStore.Get("john1")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
result, err = testStore.Get("john2") result, err = testStore.Get("john2")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Badger_Close(t *testing.T) { func Test_Badger_Close(t *testing.T) {
utils.AssertEqual(t, nil, testStore.Close()) require.Nil(t, testStore.Close())
} }
func Test_Badger_Conn(t *testing.T) { func Test_Badger_Conn(t *testing.T) {
utils.AssertEqual(t, true, testStore.Conn() != nil) require.True(t, testStore.Conn() != nil)
} }

View File

@@ -1,8 +1,9 @@
package badger package badger
import ( import (
"github.com/dgraph-io/badger/v3"
"time" "time"
"github.com/dgraph-io/badger/v3"
) )
// Config defines the config for storage. // Config defines the config for storage.

View File

@@ -1,14 +1,16 @@
package badger package badger
import ( import (
"testing"
"github.com/dgraph-io/badger/v3" "github.com/dgraph-io/badger/v3"
"github.com/gofiber/utils" "github.com/gofiber/utils"
"testing" "github.com/stretchr/testify/require"
) )
func assertRecoveryPanic(t *testing.T) { func assertRecoveryPanic(t *testing.T) {
err := recover() err := recover()
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_Badger_Only_Name(t *testing.T) { func Test_Badger_Only_Name(t *testing.T) {

View File

@@ -5,11 +5,14 @@ go 1.18
require ( require (
github.com/dgraph-io/badger/v3 v3.2103.5 github.com/dgraph-io/badger/v3 v3.2103.5
github.com/gofiber/utils v1.1.0 github.com/gofiber/utils v1.1.0
github.com/gofiber/utils/v2 v2.0.0-beta.3
github.com/stretchr/testify v1.8.3
) )
require ( require (
github.com/cespare/xxhash v1.1.0 // indirect github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect github.com/dustin/go-humanize v1.0.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect
@@ -18,10 +21,13 @@ require (
github.com/golang/protobuf v1.5.2 // indirect github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect github.com/golang/snappy v0.0.4 // indirect
github.com/google/flatbuffers v22.10.26+incompatible // indirect github.com/google/flatbuffers v22.10.26+incompatible // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/klauspost/compress v1.15.12 // indirect github.com/klauspost/compress v1.15.12 // indirect
github.com/pkg/errors v0.9.1 // indirect github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opencensus.io v0.24.0 // indirect go.opencensus.io v0.24.0 // indirect
golang.org/x/net v0.7.0 // indirect golang.org/x/net v0.7.0 // indirect
golang.org/x/sys v0.5.0 // indirect golang.org/x/sys v0.5.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
) )

View File

@@ -33,6 +33,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM= github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM=
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0= github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0=
github.com/gofiber/utils/v2 v2.0.0-beta.3 h1:pfOhUDDVjBJpkWv6C5jaDyYLvpui7zQ97zpyFFsUOKw=
github.com/gofiber/utils/v2 v2.0.0-beta.3/go.mod h1:jsl17+MsKfwJjM3ONCE9Rzji/j8XNbwjhUVTjzgfDCo=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
@@ -72,6 +74,8 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
@@ -79,8 +83,10 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
github.com/klauspost/compress v1.12.3/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= github.com/klauspost/compress v1.12.3/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM= github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM=
github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
@@ -108,8 +114,9 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
@@ -195,6 +202,7 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -3,7 +3,7 @@ package bbolt
import ( import (
"time" "time"
"github.com/gofiber/utils" "github.com/gofiber/utils/v2"
"go.etcd.io/bbolt" "go.etcd.io/bbolt"
) )
@@ -18,7 +18,7 @@ func New(config ...Config) *Storage {
// Set default config // Set default config
cfg := configDefault(config...) cfg := configDefault(config...)
conn, err := bbolt.Open(cfg.Database, 0666, &bbolt.Options{ conn, err := bbolt.Open(cfg.Database, 0o666, &bbolt.Options{
Timeout: cfg.Timeout, Timeout: cfg.Timeout,
ReadOnly: cfg.ReadOnly, ReadOnly: cfg.ReadOnly,
}) })
@@ -42,7 +42,6 @@ func New(config ...Config) *Storage {
conn: conn, conn: conn,
bucket: cfg.Bucket, bucket: cfg.Bucket,
} }
} }
// Get value by key // Get value by key

View File

@@ -3,7 +3,7 @@ package bbolt
import ( import (
"testing" "testing"
"github.com/gofiber/utils" "github.com/stretchr/testify/require"
) )
var testStore = New() var testStore = New()
@@ -15,7 +15,7 @@ func Test_Bbolt_Set(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_Bbolt_Set_Override(t *testing.T) { func Test_Bbolt_Set_Override(t *testing.T) {
@@ -25,10 +25,10 @@ func Test_Bbolt_Set_Override(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set(key, val, 0) err = testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_Bbolt_Get(t *testing.T) { func Test_Bbolt_Get(t *testing.T) {
@@ -38,18 +38,17 @@ func Test_Bbolt_Get(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
} }
func Test_Bbolt_Get_NotExist(t *testing.T) { func Test_Bbolt_Get_NotExist(t *testing.T) {
result, err := testStore.Get("notexist") result, err := testStore.Get("notexist")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Bbolt_Delete(t *testing.T) { func Test_Bbolt_Delete(t *testing.T) {
@@ -59,43 +58,41 @@ func Test_Bbolt_Delete(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Delete(key) err = testStore.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Bbolt_Reset(t *testing.T) { func Test_Bbolt_Reset(t *testing.T) {
var ( val := []byte("doe")
val = []byte("doe")
)
err := testStore.Set("john1", val, 0) err := testStore.Set("john1", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set("john2", val, 0) err = testStore.Set("john2", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Reset() err = testStore.Reset()
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get("john1") result, err := testStore.Get("john1")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
result, err = testStore.Get("john2") result, err = testStore.Get("john2")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Bbolt_Close(t *testing.T) { func Test_Bbolt_Close(t *testing.T) {
utils.AssertEqual(t, nil, testStore.Close()) require.Nil(t, testStore.Close())
} }
func Test_Bbolt_Conn(t *testing.T) { func Test_Bbolt_Conn(t *testing.T) {
utils.AssertEqual(t, true, testStore.Conn() != nil) require.True(t, testStore.Conn() != nil)
} }

View File

@@ -4,7 +4,15 @@ go 1.18
require ( require (
github.com/gofiber/utils v1.0.1 github.com/gofiber/utils v1.0.1
github.com/gofiber/utils/v2 v2.0.0-beta.3
github.com/stretchr/testify v1.8.3
go.etcd.io/bbolt v1.3.7 go.etcd.io/bbolt v1.3.7
) )
require golang.org/x/sys v0.4.0 // indirect require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

View File

@@ -1,10 +1,20 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gofiber/utils v1.0.1 h1:knct4cXwBipWQqFrOy1Pv6UcgPM+EXo9jDgc66V1Qio= github.com/gofiber/utils v1.0.1 h1:knct4cXwBipWQqFrOy1Pv6UcgPM+EXo9jDgc66V1Qio=
github.com/gofiber/utils v1.0.1/go.mod h1:pacRFtghAE3UoknMOUiXh2Io/nLWSUHtQCi/3QASsOc= github.com/gofiber/utils v1.0.1/go.mod h1:pacRFtghAE3UoknMOUiXh2Io/nLWSUHtQCi/3QASsOc=
github.com/gofiber/utils/v2 v2.0.0-beta.3 h1:pfOhUDDVjBJpkWv6C5jaDyYLvpui7zQ97zpyFFsUOKw=
github.com/gofiber/utils/v2 v2.0.0-beta.3/go.mod h1:jsl17+MsKfwJjM3ONCE9Rzji/j8XNbwjhUVTjzgfDCo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
go.etcd.io/bbolt v1.3.7 h1:j+zJOnnEjF/kyHlDDgGnVL/AIqIJPq8UoB2GSNfkUfQ= go.etcd.io/bbolt v1.3.7 h1:j+zJOnnEjF/kyHlDDgGnVL/AIqIJPq8UoB2GSNfkUfQ=
go.etcd.io/bbolt v1.3.7/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw= go.etcd.io/bbolt v1.3.7/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -26,7 +26,6 @@ func New(config ...Config) *Storage {
}, },
Transcoder: gocb.NewLegacyTranscoder(), Transcoder: gocb.NewLegacyTranscoder(),
}) })
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@@ -4,7 +4,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/gofiber/utils" "github.com/stretchr/testify/require"
) )
func TestSetCouchbase_ShouldReturnNoError(t *testing.T) { func TestSetCouchbase_ShouldReturnNoError(t *testing.T) {
@@ -17,7 +17,7 @@ func TestSetCouchbase_ShouldReturnNoError(t *testing.T) {
err := testStorage.Set("test", []byte("test"), 0) err := testStorage.Set("test", []byte("test"), 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func TestGetCouchbase_ShouldReturnNil_WhenDocumentNotFound(t *testing.T) { func TestGetCouchbase_ShouldReturnNil_WhenDocumentNotFound(t *testing.T) {
@@ -30,8 +30,8 @@ func TestGetCouchbase_ShouldReturnNil_WhenDocumentNotFound(t *testing.T) {
val, err := testStorage.Get("not_found_key") val, err := testStorage.Get("not_found_key")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, 0, len(val)) require.Zero(len(val))
} }
func TestSetAndGet_GetShouldReturn_SettedValueWithoutError(t *testing.T) { func TestSetAndGet_GetShouldReturn_SettedValueWithoutError(t *testing.T) {
@@ -43,12 +43,12 @@ func TestSetAndGet_GetShouldReturn_SettedValueWithoutError(t *testing.T) {
}) })
err := testStorage.Set("test", []byte("fiber_test_value"), 0) err := testStorage.Set("test", []byte("fiber_test_value"), 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
val, err := testStorage.Get("test") val, err := testStorage.Get("test")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, []byte("fiber_test_value")) require.Equal(t, val, []byte("fiber_test_value"))
} }
func TestSetAndGet_GetShouldReturnNil_WhenTTLExpired(t *testing.T) { func TestSetAndGet_GetShouldReturnNil_WhenTTLExpired(t *testing.T) {
@@ -60,14 +60,14 @@ func TestSetAndGet_GetShouldReturnNil_WhenTTLExpired(t *testing.T) {
}) })
err := testStorage.Set("test", []byte("fiber_test_value"), 3*time.Second) err := testStorage.Set("test", []byte("fiber_test_value"), 3*time.Second)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
time.Sleep(6 * time.Second) time.Sleep(6 * time.Second)
val, err := testStorage.Get("test") val, err := testStorage.Get("test")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, 0, len(val)) require.Zero(len(val))
} }
func TestSetAndDelete_DeleteShouldReturn_NoError(t *testing.T) { func TestSetAndDelete_DeleteShouldReturn_NoError(t *testing.T) {
@@ -79,13 +79,13 @@ func TestSetAndDelete_DeleteShouldReturn_NoError(t *testing.T) {
}) })
err := testStorage.Set("test", []byte("fiber_test_value"), 0) err := testStorage.Set("test", []byte("fiber_test_value"), 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStorage.Delete("test") err = testStorage.Delete("test")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
_, err = testStorage.Get("test") _, err = testStorage.Get("test")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func TestSetAndReset_ResetShouldReturn_NoError(t *testing.T) { func TestSetAndReset_ResetShouldReturn_NoError(t *testing.T) {
@@ -97,13 +97,13 @@ func TestSetAndReset_ResetShouldReturn_NoError(t *testing.T) {
}) })
err := testStorage.Set("test", []byte("fiber_test_value"), 0) err := testStorage.Set("test", []byte("fiber_test_value"), 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStorage.Reset() err = testStorage.Reset()
utils.AssertEqual(t, nil, err) require.Nil(t, err)
_, err = testStorage.Get("test") _, err = testStorage.Get("test")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func TestClose_CloseShouldReturn_NoError(t *testing.T) { func TestClose_CloseShouldReturn_NoError(t *testing.T) {
@@ -115,7 +115,7 @@ func TestClose_CloseShouldReturn_NoError(t *testing.T) {
}) })
err := testStorage.Close() err := testStorage.Close()
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func TestGetConn_ReturnsNotNill(t *testing.T) { func TestGetConn_ReturnsNotNill(t *testing.T) {
@@ -125,6 +125,5 @@ func TestGetConn_ReturnsNotNill(t *testing.T) {
Host: "127.0.0.1:8091", Host: "127.0.0.1:8091",
Bucket: "fiber_storage", Bucket: "fiber_storage",
}) })
conn := testStorage.Conn() require.True(t, testStorage.Conn() != nil)
utils.AssertEqual(t, true, conn != nil)
} }

View File

@@ -4,11 +4,14 @@ go 1.19
require ( require (
github.com/couchbase/gocb/v2 v2.6.3 github.com/couchbase/gocb/v2 v2.6.3
github.com/gofiber/utils v1.1.0 github.com/stretchr/testify v1.8.2
) )
require ( require (
github.com/couchbase/gocbcore/v10 v10.2.3 // indirect github.com/couchbase/gocbcore/v10 v10.2.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/snappy v0.0.4 // indirect github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.3.0 // indirect github.com/google/uuid v1.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
) )

View File

@@ -8,8 +8,6 @@ github.com/couchbaselabs/gocaves/client v0.0.0-20230404095311-05e3ba4f0259/go.mo
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM=
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
@@ -24,6 +22,7 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

View File

@@ -3,7 +3,7 @@ package dynamodb
import ( import (
"testing" "testing"
"github.com/gofiber/utils" "github.com/stretchr/testify/require"
) )
var testStore = New( var testStore = New(
@@ -25,7 +25,7 @@ func Test_DynamoDB_Set(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_DynamoDB_Set_Override(t *testing.T) { func Test_DynamoDB_Set_Override(t *testing.T) {
@@ -35,10 +35,10 @@ func Test_DynamoDB_Set_Override(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set(key, val, 0) err = testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_DynamoDB_Get(t *testing.T) { func Test_DynamoDB_Get(t *testing.T) {
@@ -48,18 +48,17 @@ func Test_DynamoDB_Get(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
} }
func Test_DynamoDB_Get_NotExist(t *testing.T) { func Test_DynamoDB_Get_NotExist(t *testing.T) {
result, err := testStore.Get("notexist") result, err := testStore.Get("notexist")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_DynamoDB_Delete(t *testing.T) { func Test_DynamoDB_Delete(t *testing.T) {
@@ -69,43 +68,41 @@ func Test_DynamoDB_Delete(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Delete(key) err = testStore.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_DynamoDB_Reset(t *testing.T) { func Test_DynamoDB_Reset(t *testing.T) {
var ( val := []byte("doe")
val = []byte("doe")
)
err := testStore.Set("john1", val, 0) err := testStore.Set("john1", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set("john2", val, 0) err = testStore.Set("john2", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Reset() err = testStore.Reset()
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get("john1") result, err := testStore.Get("john1")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
result, err = testStore.Get("john2") result, err = testStore.Get("john2")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_DynamoDB_Close(t *testing.T) { func Test_DynamoDB_Close(t *testing.T) {
utils.AssertEqual(t, nil, testStore.Close()) require.Nil(t, testStore.Close())
} }
func Test_DynamoDB_Conn(t *testing.T) { func Test_DynamoDB_Conn(t *testing.T) {
utils.AssertEqual(t, true, testStore.Conn() != nil) require.True(t, testStore.Conn() != nil)
} }

View File

@@ -8,7 +8,7 @@ require (
github.com/aws/aws-sdk-go-v2/credentials v1.13.32 github.com/aws/aws-sdk-go-v2/credentials v1.13.32
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.10.36 github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.10.36
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.21.2 github.com/aws/aws-sdk-go-v2/service/dynamodb v1.21.2
github.com/gofiber/utils v1.1.0 github.com/stretchr/testify v1.8.4
) )
require ( require (
@@ -24,5 +24,8 @@ require (
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.15.2 // indirect github.com/aws/aws-sdk-go-v2/service/ssooidc v1.15.2 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.21.2 // indirect github.com/aws/aws-sdk-go-v2/service/sts v1.21.2 // indirect
github.com/aws/smithy-go v1.14.1 // indirect github.com/aws/smithy-go v1.14.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
) )

View File

@@ -32,10 +32,9 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.21.2 h1:ympg1+Lnq33XLhcK/xTG4yZHPs1O
github.com/aws/aws-sdk-go-v2/service/sts v1.21.2/go.mod h1:FQ/DQcOfESELfJi5ED+IPPAjI5xC6nxtSolVVB773jM= github.com/aws/aws-sdk-go-v2/service/sts v1.21.2/go.mod h1:FQ/DQcOfESELfJi5ED+IPPAjI5xC6nxtSolVVB773jM=
github.com/aws/smithy-go v1.14.1 h1:EFKMUmH/iHMqLiwoEDx2rRjRQpI1YCn5jTysoaDujFs= github.com/aws/smithy-go v1.14.1 h1:EFKMUmH/iHMqLiwoEDx2rRjRQpI1YCn5jTysoaDujFs=
github.com/aws/smithy-go v1.14.1/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/aws/smithy-go v1.14.1/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
@@ -45,6 +44,11 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfC
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -2,8 +2,9 @@ package etcd
import ( import (
"context" "context"
"go.etcd.io/etcd/client/v3"
"time" "time"
"go.etcd.io/etcd/client/v3"
) )
type Storage struct { type Storage struct {
@@ -36,7 +37,6 @@ func (s *Storage) Get(key string) ([]byte, error) {
return nil, nil return nil, nil
} }
item, err := s.db.Get(context.Background(), key) item, err := s.db.Get(context.Background(), key)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -55,7 +55,6 @@ func (s *Storage) Set(key string, val []byte, exp time.Duration) error {
} }
lease, err := s.db.Grant(context.Background(), int64(exp.Seconds())) lease, err := s.db.Grant(context.Background(), int64(exp.Seconds()))
if err != nil { if err != nil {
return err return err
} }
@@ -83,7 +82,6 @@ func (s *Storage) Delete(key string) error {
func (s *Storage) Reset() error { func (s *Storage) Reset() error {
_, err := s.db.Delete(context.Background(), "", clientv3.WithPrefix()) _, err := s.db.Delete(context.Background(), "", clientv3.WithPrefix())
if err != nil { if err != nil {
return err return err
} }

View File

@@ -1,9 +1,10 @@
package etcd package etcd
import ( import (
"github.com/gofiber/utils"
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/require"
) )
func TestSetEtcd_ShouldReturnNoError(t *testing.T) { func TestSetEtcd_ShouldReturnNoError(t *testing.T) {
@@ -17,7 +18,7 @@ func TestSetEtcd_ShouldReturnNoError(t *testing.T) {
) )
err := testStorage.Set(key, val, 0) err := testStorage.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func TestGetEtcd_ShouldReturnNil_WhenDocumentNotFound(t *testing.T) { func TestGetEtcd_ShouldReturnNil_WhenDocumentNotFound(t *testing.T) {
@@ -27,8 +28,8 @@ func TestGetEtcd_ShouldReturnNil_WhenDocumentNotFound(t *testing.T) {
val, err := testStorage.Get("not_found_key") val, err := testStorage.Get("not_found_key")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, 0, len(val)) require.Zero(len(val))
} }
func TestSetAndGet_GetShouldReturn_SettedValueWithoutError(t *testing.T) { func TestSetAndGet_GetShouldReturn_SettedValueWithoutError(t *testing.T) {
@@ -37,12 +38,12 @@ func TestSetAndGet_GetShouldReturn_SettedValueWithoutError(t *testing.T) {
}) })
err := testStorage.Set("test", []byte("fiber_test_value"), 0) err := testStorage.Set("test", []byte("fiber_test_value"), 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
val, err := testStorage.Get("test") val, err := testStorage.Get("test")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, []byte("fiber_test_value")) require.Equal(t, val, []byte("fiber_test_value"))
} }
func TestSetAndGet_GetShouldReturnNil_WhenTTLExpired(t *testing.T) { func TestSetAndGet_GetShouldReturnNil_WhenTTLExpired(t *testing.T) {
@@ -51,14 +52,14 @@ func TestSetAndGet_GetShouldReturnNil_WhenTTLExpired(t *testing.T) {
}) })
err := testStorage.Set("test", []byte("fiber_test_value"), 3*time.Second) err := testStorage.Set("test", []byte("fiber_test_value"), 3*time.Second)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
time.Sleep(6 * time.Second) time.Sleep(6 * time.Second)
val, err := testStorage.Get("test") val, err := testStorage.Get("test")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, 0, len(val)) require.Zero(len(val))
} }
func TestSetAndDelete_DeleteShouldReturn_NoError(t *testing.T) { func TestSetAndDelete_DeleteShouldReturn_NoError(t *testing.T) {
@@ -67,13 +68,13 @@ func TestSetAndDelete_DeleteShouldReturn_NoError(t *testing.T) {
}) })
err := testStorage.Set("test", []byte("fiber_test_value"), 0) err := testStorage.Set("test", []byte("fiber_test_value"), 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStorage.Delete("test") err = testStorage.Delete("test")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
_, err = testStorage.Get("test") _, err = testStorage.Get("test")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func TestSetAndReset_ResetShouldReturn_NoError(t *testing.T) { func TestSetAndReset_ResetShouldReturn_NoError(t *testing.T) {
@@ -82,13 +83,13 @@ func TestSetAndReset_ResetShouldReturn_NoError(t *testing.T) {
}) })
err := testStorage.Set("test", []byte("fiber_test_value"), 0) err := testStorage.Set("test", []byte("fiber_test_value"), 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStorage.Reset() err = testStorage.Reset()
utils.AssertEqual(t, nil, err) require.Nil(t, err)
_, err = testStorage.Get("test") _, err = testStorage.Get("test")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func TestClose_CloseShouldReturn_NoError(t *testing.T) { func TestClose_CloseShouldReturn_NoError(t *testing.T) {
@@ -97,7 +98,7 @@ func TestClose_CloseShouldReturn_NoError(t *testing.T) {
}) })
err := testStorage.Close() err := testStorage.Close()
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func TestGetConn_ReturnsNotNill(t *testing.T) { func TestGetConn_ReturnsNotNill(t *testing.T) {
@@ -105,6 +106,5 @@ func TestGetConn_ReturnsNotNill(t *testing.T) {
Endpoints: []string{"localhost:2379"}, Endpoints: []string{"localhost:2379"},
}) })
conn := testStorage.Conn() require.True(t, testStorage.Conn() != nil)
utils.AssertEqual(t, true, conn != nil)
} }

View File

@@ -3,15 +3,17 @@ module github.com/gofiber/storage/etcd
go 1.19 go 1.19
require ( require (
github.com/gofiber/utils v1.1.0 github.com/stretchr/testify v1.8.1
go.etcd.io/etcd/client/v3 v3.5.9 go.etcd.io/etcd/client/v3 v3.5.9
) )
require ( require (
github.com/coreos/go-semver v0.3.1 // indirect github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect github.com/golang/protobuf v1.5.3 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.etcd.io/etcd/api/v3 v3.5.9 // indirect go.etcd.io/etcd/api/v3 v3.5.9 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.9 // indirect go.etcd.io/etcd/client/pkg/v3 v3.5.9 // indirect
go.uber.org/atomic v1.7.0 // indirect go.uber.org/atomic v1.7.0 // indirect
@@ -23,4 +25,5 @@ require (
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
google.golang.org/grpc v1.55.0 // indirect google.golang.org/grpc v1.55.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
) )

View File

@@ -7,8 +7,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM=
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
@@ -22,8 +20,13 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.etcd.io/etcd/api/v3 v3.5.9 h1:4wSsluwyTbGGmyjJktOf3wFQoTBIURXHnq9n/G/JQHs= go.etcd.io/etcd/api/v3 v3.5.9 h1:4wSsluwyTbGGmyjJktOf3wFQoTBIURXHnq9n/G/JQHs=
@@ -78,6 +81,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -4,5 +4,13 @@ go 1.18
require ( require (
github.com/bradfitz/gomemcache v0.0.0-20221031212613-62deef7fc822 github.com/bradfitz/gomemcache v0.0.0-20221031212613-62deef7fc822
github.com/gofiber/utils v1.1.0 github.com/gofiber/utils/v2 v2.0.0-beta.3
github.com/stretchr/testify v1.8.4
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
) )

View File

@@ -1,4 +1,16 @@
github.com/bradfitz/gomemcache v0.0.0-20221031212613-62deef7fc822 h1:hjXJeBcAMS1WGENGqDpzvmgS43oECTx8UXq31UBu0Jw= github.com/bradfitz/gomemcache v0.0.0-20221031212613-62deef7fc822 h1:hjXJeBcAMS1WGENGqDpzvmgS43oECTx8UXq31UBu0Jw=
github.com/bradfitz/gomemcache v0.0.0-20221031212613-62deef7fc822/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA= github.com/bradfitz/gomemcache v0.0.0-20221031212613-62deef7fc822/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gofiber/utils/v2 v2.0.0-beta.3 h1:pfOhUDDVjBJpkWv6C5jaDyYLvpui7zQ97zpyFFsUOKw=
github.com/gofiber/utils/v2 v2.0.0-beta.3/go.mod h1:jsl17+MsKfwJjM3ONCE9Rzji/j8XNbwjhUVTjzgfDCo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -6,7 +6,7 @@ import (
"time" "time"
mc "github.com/bradfitz/gomemcache/memcache" mc "github.com/bradfitz/gomemcache/memcache"
"github.com/gofiber/utils" "github.com/gofiber/utils/v2"
) )
// Storage interface that is implemented by storage providers // Storage interface that is implemented by storage providers

View File

@@ -4,7 +4,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/gofiber/utils" "github.com/stretchr/testify/require"
) )
var testStore = New() var testStore = New()
@@ -16,7 +16,7 @@ func Test_Memcache_Set(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_Memcache_Set_Override(t *testing.T) { func Test_Memcache_Set_Override(t *testing.T) {
@@ -26,10 +26,10 @@ func Test_Memcache_Set_Override(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set(key, val, 0) err = testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_Memcache_Get(t *testing.T) { func Test_Memcache_Get(t *testing.T) {
@@ -39,11 +39,11 @@ func Test_Memcache_Get(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
} }
func Test_Memcache_Set_Expiration(t *testing.T) { func Test_Memcache_Set_Expiration(t *testing.T) {
@@ -54,26 +54,23 @@ func Test_Memcache_Set_Expiration(t *testing.T) {
) )
err := testStore.Set(key, val, exp) err := testStore.Set(key, val, exp)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
time.Sleep(1100 * time.Millisecond) time.Sleep(1100 * time.Millisecond)
} }
func Test_Memcache_Get_Expired(t *testing.T) { func Test_Memcache_Get_Expired(t *testing.T) {
var ( key := "john"
key = "john"
)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Memcache_Get_NotExist(t *testing.T) { func Test_Memcache_Get_NotExist(t *testing.T) {
result, err := testStore.Get("notexist") result, err := testStore.Get("notexist")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Memcache_Delete(t *testing.T) { func Test_Memcache_Delete(t *testing.T) {
@@ -83,43 +80,41 @@ func Test_Memcache_Delete(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Delete(key) err = testStore.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Memcache_Reset(t *testing.T) { func Test_Memcache_Reset(t *testing.T) {
var ( val := []byte("doe")
val = []byte("doe")
)
err := testStore.Set("john1", val, 0) err := testStore.Set("john1", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set("john2", val, 0) err = testStore.Set("john2", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Reset() err = testStore.Reset()
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get("john1") result, err := testStore.Get("john1")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
result, err = testStore.Get("john2") result, err = testStore.Get("john2")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Memcache_Close(t *testing.T) { func Test_Memcache_Close(t *testing.T) {
utils.AssertEqual(t, nil, testStore.Close()) require.Nil(t, testStore.Close())
} }
func Test_Memcache_Conn(t *testing.T) { func Test_Memcache_Conn(t *testing.T) {
utils.AssertEqual(t, true, testStore.Conn() != nil) require.True(t, testStore.Conn() != nil)
} }

View File

@@ -2,4 +2,15 @@ module github.com/gofiber/storage/memory
go 1.18 go 1.18
require github.com/gofiber/utils v1.1.0 require (
github.com/gofiber/utils v1.1.0
github.com/gofiber/utils/v2 v2.0.0-beta.3
github.com/stretchr/testify v1.8.4
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

View File

@@ -1,2 +1,16 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM= github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM=
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0= github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0=
github.com/gofiber/utils/v2 v2.0.0-beta.3 h1:pfOhUDDVjBJpkWv6C5jaDyYLvpui7zQ97zpyFFsUOKw=
github.com/gofiber/utils/v2 v2.0.0-beta.3/go.mod h1:jsl17+MsKfwJjM3ONCE9Rzji/j8XNbwjhUVTjzgfDCo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -4,7 +4,8 @@ import (
"testing" "testing"
"time" "time"
"github.com/gofiber/utils" "github.com/gofiber/utils/v2"
"github.com/stretchr/testify/require"
) )
var testStore = New() var testStore = New()
@@ -16,7 +17,7 @@ func Test_Storage_Memory_Set(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_Storage_Memory_Set_Override(t *testing.T) { func Test_Storage_Memory_Set_Override(t *testing.T) {
@@ -26,10 +27,10 @@ func Test_Storage_Memory_Set_Override(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set(key, val, 0) err = testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_Storage_Memory_Get(t *testing.T) { func Test_Storage_Memory_Get(t *testing.T) {
@@ -39,11 +40,11 @@ func Test_Storage_Memory_Get(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
} }
func Test_Storage_Memory_Set_Expiration(t *testing.T) { func Test_Storage_Memory_Set_Expiration(t *testing.T) {
@@ -54,26 +55,23 @@ func Test_Storage_Memory_Set_Expiration(t *testing.T) {
) )
err := testStore.Set(key, val, exp) err := testStore.Set(key, val, exp)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
time.Sleep(1100 * time.Millisecond) time.Sleep(1100 * time.Millisecond)
} }
func Test_Storage_Memory_Get_Expired(t *testing.T) { func Test_Storage_Memory_Get_Expired(t *testing.T) {
var ( key := "john"
key = "john"
)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Storage_Memory_Get_NotExist(t *testing.T) { func Test_Storage_Memory_Get_NotExist(t *testing.T) {
result, err := testStore.Get("notexist") result, err := testStore.Get("notexist")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Storage_Memory_Delete(t *testing.T) { func Test_Storage_Memory_Delete(t *testing.T) {
@@ -83,48 +81,45 @@ func Test_Storage_Memory_Delete(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Delete(key) err = testStore.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Storage_Memory_Reset(t *testing.T) { func Test_Storage_Memory_Reset(t *testing.T) {
var ( val := []byte("doe")
val = []byte("doe")
)
err := testStore.Set("john1", val, 0) err := testStore.Set("john1", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set("john2", val, 0) err = testStore.Set("john2", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Reset() err = testStore.Reset()
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get("john1") result, err := testStore.Get("john1")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
result, err = testStore.Get("john2") result, err = testStore.Get("john2")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Storage_Memory_Close(t *testing.T) { func Test_Storage_Memory_Close(t *testing.T) {
utils.AssertEqual(t, nil, testStore.Close()) require.Nil(t, testStore.Close())
} }
func Test_Storage_Memory_Conn(t *testing.T) { func Test_Storage_Memory_Conn(t *testing.T) {
utils.AssertEqual(t, true, testStore.Conn() != nil) require.True(t, testStore.Conn() != nil)
} }
// go test -v -run=^$ -bench=Benchmark_Storage_Memory -benchmem -count=4 // go test -v -run=^$ -bench=Benchmark_Storage_Memory -benchmem -count=4
func Benchmark_Storage_Memory(b *testing.B) { func Benchmark_Storage_Memory(b *testing.B) {
keyLength := 1000 keyLength := 1000

View File

@@ -3,14 +3,16 @@ module github.com/gofiber/storage/mongodb
go 1.18 go 1.18
require ( require (
github.com/gofiber/utils v1.1.0 github.com/stretchr/testify v1.8.4
go.mongodb.org/mongo-driver v1.12.1 go.mongodb.org/mongo-driver v1.12.1
) )
require ( require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/snappy v0.0.4 // indirect github.com/golang/snappy v0.0.4 // indirect
github.com/klauspost/compress v1.13.6 // indirect github.com/klauspost/compress v1.13.6 // indirect
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect github.com/xdg-go/stringprep v1.0.4 // indirect
@@ -18,4 +20,5 @@ require (
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/text v0.7.0 // indirect golang.org/x/text v0.7.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
) )

View File

@@ -1,7 +1,5 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM=
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
@@ -11,6 +9,10 @@ github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQ
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
@@ -59,3 +61,7 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -4,7 +4,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/gofiber/utils" "github.com/stretchr/testify/require"
) )
var testStore = New(Config{ var testStore = New(Config{
@@ -18,7 +18,7 @@ func Test_MongoDB_Set(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_MongoDB_Set_Override(t *testing.T) { func Test_MongoDB_Set_Override(t *testing.T) {
@@ -28,10 +28,10 @@ func Test_MongoDB_Set_Override(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set(key, val, 0) err = testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_MongoDB_Get(t *testing.T) { func Test_MongoDB_Get(t *testing.T) {
@@ -41,11 +41,11 @@ func Test_MongoDB_Get(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
} }
func Test_MongoDB_Set_Expiration(t *testing.T) { func Test_MongoDB_Set_Expiration(t *testing.T) {
@@ -56,26 +56,23 @@ func Test_MongoDB_Set_Expiration(t *testing.T) {
) )
err := testStore.Set(key, val, exp) err := testStore.Set(key, val, exp)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
time.Sleep(1100 * time.Millisecond) time.Sleep(1100 * time.Millisecond)
} }
func Test_MongoDB_Get_Expired(t *testing.T) { func Test_MongoDB_Get_Expired(t *testing.T) {
var ( key := "john"
key = "john"
)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_MongoDB_Get_NotExist(t *testing.T) { func Test_MongoDB_Get_NotExist(t *testing.T) {
result, err := testStore.Get("notexist") result, err := testStore.Get("notexist")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_MongoDB_Delete(t *testing.T) { func Test_MongoDB_Delete(t *testing.T) {
@@ -85,43 +82,41 @@ func Test_MongoDB_Delete(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Delete(key) err = testStore.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_MongoDB_Reset(t *testing.T) { func Test_MongoDB_Reset(t *testing.T) {
var ( val := []byte("doe")
val = []byte("doe")
)
err := testStore.Set("john1", val, 0) err := testStore.Set("john1", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set("john2", val, 0) err = testStore.Set("john2", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Reset() err = testStore.Reset()
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get("john1") result, err := testStore.Get("john1")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
result, err = testStore.Get("john2") result, err = testStore.Get("john2")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_MongoDB_Close(t *testing.T) { func Test_MongoDB_Close(t *testing.T) {
utils.AssertEqual(t, nil, testStore.Close()) require.Nil(t, testStore.Close())
} }
func Test_MongoDB_Conn(t *testing.T) { func Test_MongoDB_Conn(t *testing.T) {
utils.AssertEqual(t, true, testStore.Conn() != nil) require.True(t, testStore.Conn() != nil)
} }

View File

@@ -3,12 +3,15 @@ module github.com/gofiber/storage/mssql
go 1.18 go 1.18
require ( require (
github.com/gofiber/utils v1.1.0
github.com/microsoft/go-mssqldb v1.5.0 github.com/microsoft/go-mssqldb v1.5.0
github.com/stretchr/testify v1.8.1
) )
require ( require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
github.com/golang-sql/sqlexp v0.1.0 // indirect github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/crypto v0.9.0 // indirect golang.org/x/crypto v0.9.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
) )

View File

@@ -3,11 +3,10 @@ github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0/go.mod h1:OQeznEEkTZ9Orh
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0/go.mod h1:okt5dMMTOFjX/aovMlrjvvXoPMBVSPzk9185BT0+eZM= github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0/go.mod h1:okt5dMMTOFjX/aovMlrjvvXoPMBVSPzk9185BT0+eZM=
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0/go.mod h1:kgDmCTgBzIEPFElEF+FK0SdjAor06dRq2Go927dnQ6o= github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0/go.mod h1:kgDmCTgBzIEPFElEF+FK0SdjAor06dRq2Go927dnQ6o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko= github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko=
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM=
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0=
github.com/golang-jwt/jwt/v4 v4.4.3/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang-jwt/jwt/v4 v4.4.3/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA= github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA=
@@ -31,6 +30,7 @@ github.com/microsoft/go-mssqldb v1.5.0/go.mod h1:lmWsjHD8XX/Txr0f8ZqgbEZSC+BZjmE
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
github.com/montanaflynn/stats v0.7.0/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= github.com/montanaflynn/stats v0.7.0/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
@@ -39,6 +39,7 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
@@ -85,10 +86,12 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -6,7 +6,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/gofiber/utils" "github.com/stretchr/testify/require"
) )
var testStore = New(Config{ var testStore = New(Config{
@@ -23,7 +23,7 @@ func Test_MSSQL_Set(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_MSSQL_Set_Override(t *testing.T) { func Test_MSSQL_Set_Override(t *testing.T) {
@@ -33,10 +33,10 @@ func Test_MSSQL_Set_Override(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set(key, val, 0) err = testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_MSSQL_Get(t *testing.T) { func Test_MSSQL_Get(t *testing.T) {
@@ -46,11 +46,11 @@ func Test_MSSQL_Get(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
} }
func Test_MSSQL_Set_Expiration(t *testing.T) { func Test_MSSQL_Set_Expiration(t *testing.T) {
@@ -61,26 +61,23 @@ func Test_MSSQL_Set_Expiration(t *testing.T) {
) )
err := testStore.Set(key, val, exp) err := testStore.Set(key, val, exp)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
time.Sleep(1100 * time.Millisecond) time.Sleep(1100 * time.Millisecond)
} }
func Test_MSSQL_Get_Expired(t *testing.T) { func Test_MSSQL_Get_Expired(t *testing.T) {
var ( key := "john"
key = "john"
)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_MSSQL_Get_NotExist(t *testing.T) { func Test_MSSQL_Get_NotExist(t *testing.T) {
result, err := testStore.Get("notexist") result, err := testStore.Get("notexist")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_MSSQL_Delete(t *testing.T) { func Test_MSSQL_Delete(t *testing.T) {
@@ -90,79 +87,74 @@ func Test_MSSQL_Delete(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Delete(key) err = testStore.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_MSSQL_Reset(t *testing.T) { func Test_MSSQL_Reset(t *testing.T) {
var ( val := []byte("doe")
val = []byte("doe")
)
err := testStore.Set("john1", val, 0) err := testStore.Set("john1", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set("john2", val, 0) err = testStore.Set("john2", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Reset() err = testStore.Reset()
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get("john1") result, err := testStore.Get("john1")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
result, err = testStore.Get("john2") result, err = testStore.Get("john2")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_MSSQL_GC(t *testing.T) { func Test_MSSQL_GC(t *testing.T) {
var ( testVal := []byte("doe")
testVal = []byte("doe")
)
// This key should expire // This key should expire
err := testStore.Set("john", testVal, time.Nanosecond) err := testStore.Set("john", testVal, time.Nanosecond)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
testStore.gc(time.Now()) testStore.gc(time.Now())
row := testStore.db.QueryRow(testStore.sqlSelect, "john") row := testStore.db.QueryRow(testStore.sqlSelect, "john")
err = row.Scan(nil, nil) err = row.Scan(nil, nil)
utils.AssertEqual(t, sql.ErrNoRows, err) require.Equal(t, sql.ErrNoRows, err)
// This key should not expire // This key should not expire
err = testStore.Set("john", testVal, 0) err = testStore.Set("john", testVal, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
testStore.gc(time.Now()) testStore.gc(time.Now())
val, err := testStore.Get("john") val, err := testStore.Get("john")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, testVal, val) require.Equal(t, testVal, val)
} }
func Test_MSSQL_Non_UTF8(t *testing.T) { func Test_MSSQL_Non_UTF8(t *testing.T) {
val := []byte("0xF5") val := []byte("0xF5")
err := testStore.Set("0xF6", val, 0) err := testStore.Set("0xF6", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get("0xF6") result, err := testStore.Get("0xF6")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
} }
func Test_SslRequiredMode(t *testing.T) { func Test_SslRequiredMode(t *testing.T) {
defer func() { defer func() {
if recover() == nil { if recover() == nil {
utils.AssertEqual(t, true, nil, "Connection was established with a `require`") require.Equalf(t, true, nil, "Connection was established with a `require`")
} }
}() }()
_ = New(Config{ _ = New(Config{
@@ -175,9 +167,9 @@ func Test_SslRequiredMode(t *testing.T) {
} }
func Test_MSSQL_Close(t *testing.T) { func Test_MSSQL_Close(t *testing.T) {
utils.AssertEqual(t, nil, testStore.Close()) require.Nil(t, testStore.Close())
} }
func Test_MSSQL_Conn(t *testing.T) { func Test_MSSQL_Conn(t *testing.T) {
utils.AssertEqual(t, true, testStore.Conn() != nil) require.True(t, testStore.Conn() != nil)
} }

View File

@@ -4,5 +4,11 @@ go 1.18
require ( require (
github.com/go-sql-driver/mysql v1.7.1 github.com/go-sql-driver/mysql v1.7.1
github.com/gofiber/utils v1.1.0 github.com/stretchr/testify v1.8.4
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
) )

View File

@@ -1,4 +1,12 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -5,9 +5,9 @@ import (
"fmt" "fmt"
"os" "os"
"testing" "testing"
"github.com/gofiber/utils"
"time" "time"
"github.com/stretchr/testify/require"
) )
var testStore = New(Config{ var testStore = New(Config{
@@ -25,7 +25,7 @@ func Test_MYSQL_New(t *testing.T) {
Reset: true, Reset: true,
}) })
utils.AssertEqual(t, true, newConfigStore.db != nil) require.True(t, newConfigStore.db != nil)
newConfigStore.Close() newConfigStore.Close()
dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", os.Getenv("MYSQL_USERNAME"), os.Getenv("MYSQL_PASSWORD"), "127.0.0.1", 3306, os.Getenv("MYSQL_DATABASE")) dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", os.Getenv("MYSQL_USERNAME"), os.Getenv("MYSQL_PASSWORD"), "127.0.0.1", 3306, os.Getenv("MYSQL_DATABASE"))
@@ -34,7 +34,7 @@ func Test_MYSQL_New(t *testing.T) {
Reset: true, Reset: true,
}) })
utils.AssertEqual(t, true, newConfigStore.db != nil) require.True(t, newConfigStore.db != nil)
newConfigStore.Close() newConfigStore.Close()
db, _ := sql.Open("mysql", dsn) db, _ := sql.Open("mysql", dsn)
@@ -43,7 +43,7 @@ func Test_MYSQL_New(t *testing.T) {
Reset: true, Reset: true,
}) })
utils.AssertEqual(t, true, newConfigStore.db != nil) require.True(t, newConfigStore.db != nil)
newConfigStore.Close() newConfigStore.Close()
} }
@@ -54,7 +54,7 @@ func Test_MYSQL_Set(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_MYSQL_Set_Override(t *testing.T) { func Test_MYSQL_Set_Override(t *testing.T) {
@@ -64,10 +64,10 @@ func Test_MYSQL_Set_Override(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set(key, val, 0) err = testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_MYSQL_Get(t *testing.T) { func Test_MYSQL_Get(t *testing.T) {
@@ -77,11 +77,11 @@ func Test_MYSQL_Get(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
} }
func Test_MYSQL_Set_Expiration(t *testing.T) { func Test_MYSQL_Set_Expiration(t *testing.T) {
@@ -92,26 +92,23 @@ func Test_MYSQL_Set_Expiration(t *testing.T) {
) )
err := testStore.Set(key, val, exp) err := testStore.Set(key, val, exp)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
time.Sleep(1100 * time.Millisecond) time.Sleep(1100 * time.Millisecond)
} }
func Test_MYSQL_Get_Expired(t *testing.T) { func Test_MYSQL_Get_Expired(t *testing.T) {
var ( key := "john"
key = "john"
)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_MYSQL_Get_NotExist(t *testing.T) { func Test_MYSQL_Get_NotExist(t *testing.T) {
result, err := testStore.Get("notexist") result, err := testStore.Get("notexist")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_MYSQL_Delete(t *testing.T) { func Test_MYSQL_Delete(t *testing.T) {
@@ -121,79 +118,74 @@ func Test_MYSQL_Delete(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Delete(key) err = testStore.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_MYSQL_Reset(t *testing.T) { func Test_MYSQL_Reset(t *testing.T) {
var ( val := []byte("doe")
val = []byte("doe")
)
err := testStore.Set("john1", val, 0) err := testStore.Set("john1", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set("john2", val, 0) err = testStore.Set("john2", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Reset() err = testStore.Reset()
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get("john1") result, err := testStore.Get("john1")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
result, err = testStore.Get("john2") result, err = testStore.Get("john2")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_MYSQL_GC(t *testing.T) { func Test_MYSQL_GC(t *testing.T) {
var ( testVal := []byte("doe")
testVal = []byte("doe")
)
// This key should expire // This key should expire
err := testStore.Set("john", testVal, time.Nanosecond) err := testStore.Set("john", testVal, time.Nanosecond)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
testStore.gc(time.Now()) testStore.gc(time.Now())
row := testStore.db.QueryRow(testStore.sqlSelect, "john") row := testStore.db.QueryRow(testStore.sqlSelect, "john")
err = row.Scan(nil, nil) err = row.Scan(nil, nil)
utils.AssertEqual(t, sql.ErrNoRows, err) require.Equal(t, sql.ErrNoRows, err)
// This key should not expire // This key should not expire
err = testStore.Set("john", testVal, 0) err = testStore.Set("john", testVal, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
testStore.gc(time.Now()) testStore.gc(time.Now())
val, err := testStore.Get("john") val, err := testStore.Get("john")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, testVal, val) require.Equal(t, testVal, val)
} }
func Test_MYSQL_Non_UTF8(t *testing.T) { func Test_MYSQL_Non_UTF8(t *testing.T) {
val := []byte("0xF5") val := []byte("0xF5")
err := testStore.Set("0xF6", val, 0) err := testStore.Set("0xF6", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get("0xF6") result, err := testStore.Get("0xF6")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
} }
func Test_MYSQL_Close(t *testing.T) { func Test_MYSQL_Close(t *testing.T) {
utils.AssertEqual(t, nil, testStore.Close()) require.Nil(t, testStore.Close())
} }
func Test_MYSQL_Conn(t *testing.T) { func Test_MYSQL_Conn(t *testing.T) {
utils.AssertEqual(t, true, testStore.Conn() != nil) require.True(t, testStore.Conn() != nil)
} }

View File

@@ -4,7 +4,7 @@ go 1.19
require ( require (
github.com/cockroachdb/pebble v0.0.0-20230529170040-f235f568816e github.com/cockroachdb/pebble v0.0.0-20230529170040-f235f568816e
github.com/gofiber/utils v1.1.0 github.com/stretchr/testify v1.7.0
) )
require ( require (
@@ -15,6 +15,7 @@ require (
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f // indirect github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f // indirect
github.com/cockroachdb/redact v1.0.8 // indirect github.com/cockroachdb/redact v1.0.8 // indirect
github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2 // indirect github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect github.com/golang/snappy v0.0.4 // indirect
@@ -23,6 +24,7 @@ require (
github.com/kr/text v0.2.0 // indirect github.com/kr/text v0.2.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/pkg/errors v0.9.1 // indirect github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.12.0 // indirect github.com/prometheus/client_golang v1.12.0 // indirect
github.com/prometheus/client_model v0.2.1-0.20210607210712-147c58e9608a // indirect github.com/prometheus/client_model v0.2.1-0.20210607210712-147c58e9608a // indirect
github.com/prometheus/common v0.32.1 // indirect github.com/prometheus/common v0.32.1 // indirect
@@ -30,4 +32,5 @@ require (
golang.org/x/exp v0.0.0-20200513190911-00229845015e // indirect golang.org/x/exp v0.0.0-20200513190911-00229845015e // indirect
golang.org/x/sys v0.3.0 // indirect golang.org/x/sys v0.3.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
) )

View File

@@ -120,8 +120,6 @@ github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/me
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo=
github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM=
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0=
github.com/gogo/googleapis v0.0.0-20180223154316-0cd9801be74a/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= github.com/gogo/googleapis v0.0.0-20180223154316-0cd9801be74a/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
@@ -325,6 +323,7 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4= github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
@@ -632,6 +631,7 @@ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
@@ -645,7 +645,9 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

View File

@@ -46,7 +46,6 @@ func (s *Storage) Get(key string) ([]byte, error) {
return nil, nil return nil, nil
} }
data, closer, err := s.db.Get([]byte(key)) data, closer, err := s.db.Get([]byte(key))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -126,8 +125,7 @@ func isValid(fp string) bool {
// Attempt to create it // Attempt to create it
var d []byte var d []byte
err := os.WriteFile(fp, d, 0600) err := os.WriteFile(fp, d, 0o600)
if err != nil { if err != nil {
return false return false
} }

View File

@@ -4,7 +4,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/gofiber/utils" "github.com/stretchr/testify/require"
) )
var testStore = New(Config{ var testStore = New(Config{
@@ -19,7 +19,7 @@ func Test_Pebble_Set(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_Pebble_Set_Override(t *testing.T) { func Test_Pebble_Set_Override(t *testing.T) {
@@ -29,10 +29,10 @@ func Test_Pebble_Set_Override(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set(key, val, 0) err = testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_Pebble_Get(t *testing.T) { func Test_Pebble_Get(t *testing.T) {
@@ -42,11 +42,11 @@ func Test_Pebble_Get(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
} }
func Test_Pebble_Set_Expiration(t *testing.T) { func Test_Pebble_Set_Expiration(t *testing.T) {
@@ -57,7 +57,7 @@ func Test_Pebble_Set_Expiration(t *testing.T) {
) )
err := testStore.Set(key, val, exp) err := testStore.Set(key, val, exp)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
time.Sleep(1100 * time.Millisecond) time.Sleep(1100 * time.Millisecond)
} }
@@ -69,41 +69,40 @@ func Test_Pebble_Delete(t *testing.T) {
) )
err := testStore.Set(key, val, 20) err := testStore.Set(key, val, 20)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Delete(key) err = testStore.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
require.Err
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, "pebble: not found", err.Error()) require.Equal(t, "pebble: not found", err.Error())
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Pebble_Reset(t *testing.T) { func Test_Pebble_Reset(t *testing.T) {
var ( val := []byte("doe")
val = []byte("doe")
)
err := testStore.Set("john1", val, 0) err := testStore.Set("john1", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set("john2", val, 0) err = testStore.Set("john2", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Reset() err = testStore.Reset()
utils.AssertEqual(t, nil, err) require.Nil(t, err)
_, err = testStore.Get("john1") _, err = testStore.Get("john1")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
_, err = testStore.Get("john2") _, err = testStore.Get("john2")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_Pebble_Close(t *testing.T) { func Test_Pebble_Close(t *testing.T) {
utils.AssertEqual(t, nil, testStore.Close()) require.Nil(t, testStore.Close())
} }
func Test_Pebble_Conn(t *testing.T) { func Test_Pebble_Conn(t *testing.T) {
utils.AssertEqual(t, true, testStore.Conn() != nil) require.True(t, testStore.Conn() != nil)
} }

View File

@@ -3,15 +3,20 @@ module github.com/gofiber/storage/postgres/v2
go 1.19 go 1.19
require ( require (
github.com/gofiber/utils v1.1.0
github.com/jackc/pgx/v5 v5.4.3 github.com/jackc/pgx/v5 v5.4.3
github.com/stretchr/testify v1.8.1
) )
require ( require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
golang.org/x/crypto v0.9.0 // indirect golang.org/x/crypto v0.9.0 // indirect
golang.org/x/sync v0.1.0 // indirect golang.org/x/sync v0.1.0 // indirect
golang.org/x/text v0.9.0 // indirect golang.org/x/text v0.9.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
) )

View File

@@ -1,7 +1,7 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
@@ -10,12 +10,22 @@ github.com/jackc/pgx/v5 v5.4.3 h1:cxFyXhxlvAifxnkKKdlxv8XqUf59tDlYjnV5YYfsJJY=
github.com/jackc/pgx/v5 v5.4.3/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA= github.com/jackc/pgx/v5 v5.4.3/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA=
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
@@ -23,5 +33,7 @@ golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -6,8 +6,8 @@ import (
"testing" "testing"
"time" "time"
"github.com/gofiber/utils"
"github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5"
"github.com/stretchr/testify/require"
) )
var testStore = New(Config{ var testStore = New(Config{
@@ -24,7 +24,7 @@ func Test_Postgres_Set(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_Postgres_Set_Override(t *testing.T) { func Test_Postgres_Set_Override(t *testing.T) {
@@ -34,10 +34,10 @@ func Test_Postgres_Set_Override(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set(key, val, 0) err = testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_Postgres_Get(t *testing.T) { func Test_Postgres_Get(t *testing.T) {
@@ -47,11 +47,11 @@ func Test_Postgres_Get(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
} }
func Test_Postgres_Set_Expiration(t *testing.T) { func Test_Postgres_Set_Expiration(t *testing.T) {
@@ -62,26 +62,23 @@ func Test_Postgres_Set_Expiration(t *testing.T) {
) )
err := testStore.Set(key, val, exp) err := testStore.Set(key, val, exp)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
time.Sleep(1100 * time.Millisecond) time.Sleep(1100 * time.Millisecond)
} }
func Test_Postgres_Get_Expired(t *testing.T) { func Test_Postgres_Get_Expired(t *testing.T) {
var ( key := "john"
key = "john"
)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Postgres_Get_NotExist(t *testing.T) { func Test_Postgres_Get_NotExist(t *testing.T) {
result, err := testStore.Get("notexist") result, err := testStore.Get("notexist")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Postgres_Delete(t *testing.T) { func Test_Postgres_Delete(t *testing.T) {
@@ -91,79 +88,74 @@ func Test_Postgres_Delete(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Delete(key) err = testStore.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Postgres_Reset(t *testing.T) { func Test_Postgres_Reset(t *testing.T) {
var ( val := []byte("doe")
val = []byte("doe")
)
err := testStore.Set("john1", val, 0) err := testStore.Set("john1", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set("john2", val, 0) err = testStore.Set("john2", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Reset() err = testStore.Reset()
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get("john1") result, err := testStore.Get("john1")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
result, err = testStore.Get("john2") result, err = testStore.Get("john2")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Postgres_GC(t *testing.T) { func Test_Postgres_GC(t *testing.T) {
var ( testVal := []byte("doe")
testVal = []byte("doe")
)
// This key should expire // This key should expire
err := testStore.Set("john", testVal, time.Nanosecond) err := testStore.Set("john", testVal, time.Nanosecond)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
testStore.gc(time.Now()) testStore.gc(time.Now())
row := testStore.db.QueryRow(context.Background(), testStore.sqlSelect, "john") row := testStore.db.QueryRow(context.Background(), testStore.sqlSelect, "john")
err = row.Scan(nil, nil) err = row.Scan(nil, nil)
utils.AssertEqual(t, pgx.ErrNoRows, err) require.Equal(t, pgx.ErrNoRows, err)
// This key should not expire // This key should not expire
err = testStore.Set("john", testVal, 0) err = testStore.Set("john", testVal, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
testStore.gc(time.Now()) testStore.gc(time.Now())
val, err := testStore.Get("john") val, err := testStore.Get("john")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, testVal, val) require.Equal(t, testVal, val)
} }
func Test_Postgres_Non_UTF8(t *testing.T) { func Test_Postgres_Non_UTF8(t *testing.T) {
val := []byte("0xF5") val := []byte("0xF5")
err := testStore.Set("0xF6", val, 0) err := testStore.Set("0xF6", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get("0xF6") result, err := testStore.Get("0xF6")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
} }
func Test_SslRequiredMode(t *testing.T) { func Test_SslRequiredMode(t *testing.T) {
defer func() { defer func() {
if recover() == nil { if recover() == nil {
utils.AssertEqual(t, true, nil, "Connection was established with a `require`") require.Equalf(t, true, nil, "Connection was established with a `require`")
} }
}() }()
_ = New(Config{ _ = New(Config{
@@ -172,9 +164,9 @@ func Test_SslRequiredMode(t *testing.T) {
} }
func Test_Postgres_Conn(t *testing.T) { func Test_Postgres_Conn(t *testing.T) {
utils.AssertEqual(t, true, testStore.Conn() != nil) require.True(t, testStore.Conn() != nil)
} }
func Test_Postgres_Close(t *testing.T) { func Test_Postgres_Close(t *testing.T) {
utils.AssertEqual(t, nil, testStore.Close()) require.Nil(t, testStore.Close())
} }

View File

@@ -3,11 +3,14 @@ module github.com/gofiber/storage/redis/v2
go 1.18 go 1.18
require ( require (
github.com/gofiber/utils v1.1.0
github.com/redis/go-redis/v9 v9.1.0 github.com/redis/go-redis/v9 v9.1.0
github.com/stretchr/testify v1.8.4
) )
require ( require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
) )

View File

@@ -2,9 +2,17 @@ github.com/bsm/ginkgo/v2 v2.9.5 h1:rtVBYPs3+TC5iLUVOis1B9tjLTup7Cj5IfzosKtvTJ0=
github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y= github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/redis/go-redis/v9 v9.1.0 h1:137FnGdk+EQdCbye1FW+qOEcY5S+SpY9T0NiuqvtfMY= github.com/redis/go-redis/v9 v9.1.0 h1:137FnGdk+EQdCbye1FW+qOEcY5S+SpY9T0NiuqvtfMY=
github.com/redis/go-redis/v9 v9.1.0/go.mod h1:urWj3He21Dj5k4TK1y59xH8Uj6ATueP8AH1cY3lZl4c= github.com/redis/go-redis/v9 v9.1.0/go.mod h1:urWj3He21Dj5k4TK1y59xH8Uj6ATueP8AH1cY3lZl4c=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -6,7 +6,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/gofiber/utils" "github.com/stretchr/testify/require"
) )
var testStore = New(Config{ var testStore = New(Config{
@@ -20,7 +20,7 @@ func Test_Redis_Set(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_Redis_Set_Override(t *testing.T) { func Test_Redis_Set_Override(t *testing.T) {
@@ -30,10 +30,10 @@ func Test_Redis_Set_Override(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set(key, val, 0) err = testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_Redis_Get(t *testing.T) { func Test_Redis_Get(t *testing.T) {
@@ -43,11 +43,11 @@ func Test_Redis_Get(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
} }
func Test_Redis_Set_Expiration(t *testing.T) { func Test_Redis_Set_Expiration(t *testing.T) {
@@ -58,25 +58,23 @@ func Test_Redis_Set_Expiration(t *testing.T) {
) )
err := testStore.Set(key, val, exp) err := testStore.Set(key, val, exp)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
time.Sleep(1100 * time.Millisecond) time.Sleep(1100 * time.Millisecond)
} }
func Test_Redis_Get_Expired(t *testing.T) { func Test_Redis_Get_Expired(t *testing.T) {
var ( key := "john"
key = "john"
)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Redis_Get_NotExist(t *testing.T) { func Test_Redis_Get_NotExist(t *testing.T) {
result, err := testStore.Get("notexist") result, err := testStore.Get("notexist")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Redis_Delete(t *testing.T) { func Test_Redis_Delete(t *testing.T) {
@@ -86,45 +84,43 @@ func Test_Redis_Delete(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Delete(key) err = testStore.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Redis_Reset(t *testing.T) { func Test_Redis_Reset(t *testing.T) {
var ( val := []byte("doe")
val = []byte("doe")
)
err := testStore.Set("john1", val, 0) err := testStore.Set("john1", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set("john2", val, 0) err = testStore.Set("john2", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Reset() err = testStore.Reset()
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get("john1") result, err := testStore.Get("john1")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
result, err = testStore.Get("john2") result, err = testStore.Get("john2")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Redis_Close(t *testing.T) { func Test_Redis_Close(t *testing.T) {
utils.AssertEqual(t, nil, testStore.Close()) require.Nil(t, testStore.Close())
} }
func Test_Redis_Conn(t *testing.T) { func Test_Redis_Conn(t *testing.T) {
utils.AssertEqual(t, true, testStore.Conn() != nil) require.True(t, testStore.Conn() != nil)
} }
func Test_Redis_Initalize_WithURL(t *testing.T) { func Test_Redis_Initalize_WithURL(t *testing.T) {
@@ -137,16 +133,16 @@ func Test_Redis_Initalize_WithURL(t *testing.T) {
) )
err := testStoreUrl.Set(key, val, 0) err := testStoreUrl.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStoreUrl.Get(key) result, err := testStoreUrl.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
err = testStoreUrl.Delete(key) err = testStoreUrl.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, nil, testStoreUrl.Close()) require.Nil(t, testStoreUrl.Close())
} }
func Test_Redis_Initalize_WithURL_TLS(t *testing.T) { func Test_Redis_Initalize_WithURL_TLS(t *testing.T) {
@@ -180,16 +176,16 @@ func Test_Redis_Initalize_WithURL_TLS(t *testing.T) {
) )
err = testStoreUrl.Set(key, val, 0) err = testStoreUrl.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStoreUrl.Get(key) result, err := testStoreUrl.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
err = testStoreUrl.Delete(key) err = testStoreUrl.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, nil, testStoreUrl.Close()) require.Nil(t, testStoreUrl.Close())
} }
func Test_Redis_Universal_Addrs(t *testing.T) { func Test_Redis_Universal_Addrs(t *testing.T) {
@@ -204,16 +200,16 @@ func Test_Redis_Universal_Addrs(t *testing.T) {
) )
err := testStoreUniversal.Set(key, val, 0) err := testStoreUniversal.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStoreUniversal.Get(key) result, err := testStoreUniversal.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
err = testStoreUniversal.Delete(key) err = testStoreUniversal.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, nil, testStoreUniversal.Close()) require.Nil(t, testStoreUniversal.Close())
} }
func Test_Redis_Universal_With_URL_Undefined(t *testing.T) { func Test_Redis_Universal_With_URL_Undefined(t *testing.T) {
@@ -230,16 +226,16 @@ func Test_Redis_Universal_With_URL_Undefined(t *testing.T) {
) )
err := testStoreUniversal.Set(key, val, 0) err := testStoreUniversal.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStoreUniversal.Get(key) result, err := testStoreUniversal.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
err = testStoreUniversal.Delete(key) err = testStoreUniversal.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, nil, testStoreUniversal.Close()) require.Nil(t, testStoreUniversal.Close())
} }
func Test_Redis_Universal_With_URL_Defined(t *testing.T) { func Test_Redis_Universal_With_URL_Defined(t *testing.T) {
@@ -256,16 +252,16 @@ func Test_Redis_Universal_With_URL_Defined(t *testing.T) {
) )
err := testStoreUniversal.Set(key, val, 0) err := testStoreUniversal.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStoreUniversal.Get(key) result, err := testStoreUniversal.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
err = testStoreUniversal.Delete(key) err = testStoreUniversal.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, nil, testStoreUniversal.Close()) require.Nil(t, testStoreUniversal.Close())
} }
func Test_Redis_Universal_With_HostPort(t *testing.T) { func Test_Redis_Universal_With_HostPort(t *testing.T) {
@@ -283,16 +279,16 @@ func Test_Redis_Universal_With_HostPort(t *testing.T) {
) )
err := testStoreUniversal.Set(key, val, 0) err := testStoreUniversal.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStoreUniversal.Get(key) result, err := testStoreUniversal.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
err = testStoreUniversal.Delete(key) err = testStoreUniversal.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, nil, testStoreUniversal.Close()) require.Nil(t, testStoreUniversal.Close())
} }
func Test_Redis_Universal_With_HostPort_And_URL(t *testing.T) { func Test_Redis_Universal_With_HostPort_And_URL(t *testing.T) {
@@ -311,16 +307,16 @@ func Test_Redis_Universal_With_HostPort_And_URL(t *testing.T) {
) )
err := testStoreUniversal.Set(key, val, 0) err := testStoreUniversal.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStoreUniversal.Get(key) result, err := testStoreUniversal.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
err = testStoreUniversal.Delete(key) err = testStoreUniversal.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, nil, testStoreUniversal.Close()) require.Nil(t, testStoreUniversal.Close())
} }
func Test_Redis_Cluster(t *testing.T) { func Test_Redis_Cluster(t *testing.T) {
@@ -341,14 +337,14 @@ func Test_Redis_Cluster(t *testing.T) {
) )
err := testStoreUniversal.Set(key, val, 0) err := testStoreUniversal.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStoreUniversal.Get(key) result, err := testStoreUniversal.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
err = testStoreUniversal.Delete(key) err = testStoreUniversal.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, nil, testStoreUniversal.Close()) require.Nil(t, testStoreUniversal.Close())
} }

View File

@@ -4,13 +4,16 @@ go 1.18
require ( require (
github.com/dgraph-io/ristretto v0.1.1 github.com/dgraph-io/ristretto v0.1.1
github.com/gofiber/utils v1.1.0 github.com/stretchr/testify v1.4.0
) )
require ( require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect github.com/dustin/go-humanize v1.0.0 // indirect
github.com/golang/glog v1.0.0 // indirect github.com/golang/glog v1.0.0 // indirect
github.com/pkg/errors v0.9.1 // indirect github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.2.0 // indirect golang.org/x/sys v0.2.0 // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
) )

View File

@@ -10,8 +10,6 @@ github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczC
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM=
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ= github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ=
github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4= github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
@@ -25,6 +23,7 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A= golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View File

@@ -20,7 +20,6 @@ func New(config ...Config) *Storage {
MaxCost: cfg.MaxCost, MaxCost: cfg.MaxCost,
BufferItems: cfg.BufferItems, BufferItems: cfg.BufferItems,
}) })
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@@ -5,7 +5,7 @@ import (
"time" "time"
"github.com/gofiber/storage/ristretto" "github.com/gofiber/storage/ristretto"
"github.com/gofiber/utils" "github.com/stretchr/testify/require"
) )
var testStore = ristretto.New() var testStore = ristretto.New()
@@ -17,7 +17,7 @@ func Test_Ristretto_Set(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_Ristretto_Set_Override(t *testing.T) { func Test_Ristretto_Set_Override(t *testing.T) {
@@ -27,10 +27,10 @@ func Test_Ristretto_Set_Override(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set(key, val, 0) err = testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_Ristretto_Get(t *testing.T) { func Test_Ristretto_Get(t *testing.T) {
@@ -45,7 +45,7 @@ func Test_Ristretto_Get(t *testing.T) {
// Set the value in a goroutine // Set the value in a goroutine
go func() { go func() {
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
// Send a value on the channel to signal that the value has been set // Send a value on the channel to signal that the value has been set
done <- struct{}{} done <- struct{}{}
@@ -56,8 +56,8 @@ func Test_Ristretto_Get(t *testing.T) {
case <-done: case <-done:
// The value has been set, proceed with the test // The value has been set, proceed with the test
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
case <-time.After(1 * time.Second): case <-time.After(1 * time.Second):
// The value was not set within 1 second, fail the test // The value was not set within 1 second, fail the test
t.Errorf("timed out waiting for value to be set") t.Errorf("timed out waiting for value to be set")
@@ -72,26 +72,23 @@ func Test_Ristretto_Set_Expiration(t *testing.T) {
) )
err := testStore.Set(key, val, exp) err := testStore.Set(key, val, exp)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
testStore.Reset() testStore.Reset()
} }
func Test_Ristretto_Get_Expired(t *testing.T) { func Test_Ristretto_Get_Expired(t *testing.T) {
var ( key := "john"
key = "john"
)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Ristretto_Get_NotExist(t *testing.T) { func Test_Ristretto_Get_NotExist(t *testing.T) {
result, err := testStore.Get("notexist") result, err := testStore.Get("notexist")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Ristretto_Delete(t *testing.T) { func Test_Ristretto_Delete(t *testing.T) {
@@ -106,7 +103,7 @@ func Test_Ristretto_Delete(t *testing.T) {
// Set the value in a goroutine // Set the value in a goroutine
go func() { go func() {
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
// Send a value on the channel to signal that the value has been set // Send a value on the channel to signal that the value has been set
done <- struct{}{} done <- struct{}{}
@@ -117,11 +114,11 @@ func Test_Ristretto_Delete(t *testing.T) {
case <-done: case <-done:
// The value has been set, proceed with the test // The value has been set, proceed with the test
err := testStore.Delete(key) err := testStore.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
case <-time.After(1 * time.Second): case <-time.After(1 * time.Second):
// The value was not set within 1 second, fail the test // The value was not set within 1 second, fail the test
t.Errorf("timed out waiting for value to be set") t.Errorf("timed out waiting for value to be set")
@@ -129,32 +126,30 @@ func Test_Ristretto_Delete(t *testing.T) {
} }
func Test_Ristretto_Reset(t *testing.T) { func Test_Ristretto_Reset(t *testing.T) {
var ( val := []byte("doe")
val = []byte("doe")
)
err := testStore.Set("john1", val, 0) err := testStore.Set("john1", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set("john2", val, 0) err = testStore.Set("john2", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Reset() err = testStore.Reset()
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get("john1") result, err := testStore.Get("john1")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
result, err = testStore.Get("john2") result, err = testStore.Get("john2")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_Ristretto_Close(t *testing.T) { func Test_Ristretto_Close(t *testing.T) {
utils.AssertEqual(t, nil, testStore.Close()) require.Nil(t, testStore.Close())
} }
func Test_Ristretto_Conn(t *testing.T) { func Test_Ristretto_Conn(t *testing.T) {
utils.AssertEqual(t, true, testStore.Conn() != nil) require.True(t, testStore.Conn() != nil)
} }

View File

@@ -8,7 +8,7 @@ require (
github.com/aws/aws-sdk-go-v2/credentials v1.13.32 github.com/aws/aws-sdk-go-v2/credentials v1.13.32
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.77 github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.77
github.com/aws/aws-sdk-go-v2/service/s3 v1.38.2 github.com/aws/aws-sdk-go-v2/service/s3 v1.38.2
github.com/gofiber/utils v1.0.1 github.com/stretchr/testify v1.8.4
) )
require ( require (
@@ -26,5 +26,8 @@ require (
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.15.2 // indirect github.com/aws/aws-sdk-go-v2/service/ssooidc v1.15.2 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.21.2 // indirect github.com/aws/aws-sdk-go-v2/service/sts v1.21.2 // indirect
github.com/aws/smithy-go v1.14.1 // indirect github.com/aws/smithy-go v1.14.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
) )

View File

@@ -36,10 +36,9 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.21.2 h1:ympg1+Lnq33XLhcK/xTG4yZHPs1O
github.com/aws/aws-sdk-go-v2/service/sts v1.21.2/go.mod h1:FQ/DQcOfESELfJi5ED+IPPAjI5xC6nxtSolVVB773jM= github.com/aws/aws-sdk-go-v2/service/sts v1.21.2/go.mod h1:FQ/DQcOfESELfJi5ED+IPPAjI5xC6nxtSolVVB773jM=
github.com/aws/smithy-go v1.14.1 h1:EFKMUmH/iHMqLiwoEDx2rRjRQpI1YCn5jTysoaDujFs= github.com/aws/smithy-go v1.14.1 h1:EFKMUmH/iHMqLiwoEDx2rRjRQpI1YCn5jTysoaDujFs=
github.com/aws/smithy-go v1.14.1/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/aws/smithy-go v1.14.1/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gofiber/utils v1.0.1 h1:knct4cXwBipWQqFrOy1Pv6UcgPM+EXo9jDgc66V1Qio= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/gofiber/utils v1.0.1/go.mod h1:pacRFtghAE3UoknMOUiXh2Io/nLWSUHtQCi/3QASsOc= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
@@ -49,6 +48,11 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfC
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -3,7 +3,7 @@ package s3
import ( import (
"testing" "testing"
"github.com/gofiber/utils" "github.com/stretchr/testify/require"
) )
var testStore = New( var testStore = New(
@@ -25,7 +25,7 @@ func Test_S3_Set(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_S3_Set_Override(t *testing.T) { func Test_S3_Set_Override(t *testing.T) {
@@ -35,10 +35,10 @@ func Test_S3_Set_Override(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set(key, val, 0) err = testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_S3_Get(t *testing.T) { func Test_S3_Get(t *testing.T) {
@@ -48,18 +48,17 @@ func Test_S3_Get(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
} }
func Test_S3_Get_NotExist(t *testing.T) { func Test_S3_Get_NotExist(t *testing.T) {
result, err := testStore.Get("notexist") result, err := testStore.Get("notexist")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_S3_Delete(t *testing.T) { func Test_S3_Delete(t *testing.T) {
@@ -69,43 +68,41 @@ func Test_S3_Delete(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Delete(key) err = testStore.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_S3_Reset(t *testing.T) { func Test_S3_Reset(t *testing.T) {
var ( val := []byte("doe")
val = []byte("doe")
)
err := testStore.Set("john1", val, 0) err := testStore.Set("john1", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set("john2", val, 0) err = testStore.Set("john2", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Reset() err = testStore.Reset()
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get("john1") result, err := testStore.Get("john1")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
result, err = testStore.Get("john2") result, err = testStore.Get("john2")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_S3_Close(t *testing.T) { func Test_S3_Close(t *testing.T) {
utils.AssertEqual(t, nil, testStore.Close()) require.Nil(t, testStore.Close())
} }
func Test_S3_Conn(t *testing.T) { func Test_S3_Conn(t *testing.T) {
utils.AssertEqual(t, true, testStore.Conn() != nil) require.True(t, testStore.Conn() != nil)
} }

View File

@@ -3,6 +3,12 @@ module github.com/gofiber/storage/sqlite3
go 1.18 go 1.18
require ( require (
github.com/gofiber/utils v1.1.0
github.com/mattn/go-sqlite3 v1.14.17 github.com/mattn/go-sqlite3 v1.14.17
github.com/stretchr/testify v1.8.4
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
) )

View File

@@ -1,4 +1,12 @@
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM= github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -5,8 +5,8 @@ import (
"testing" "testing"
"time" "time"
"github.com/gofiber/utils"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"github.com/stretchr/testify/require"
) )
var testStore = New(Config{ var testStore = New(Config{
@@ -20,7 +20,7 @@ func Test_SQLite3_Set(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_SQLite3_Set_Override(t *testing.T) { func Test_SQLite3_Set_Override(t *testing.T) {
@@ -30,10 +30,10 @@ func Test_SQLite3_Set_Override(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set(key, val, 0) err = testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
} }
func Test_SQLite3_Get(t *testing.T) { func Test_SQLite3_Get(t *testing.T) {
@@ -43,11 +43,11 @@ func Test_SQLite3_Get(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
} }
func Test_SQLite3_Set_Expiration(t *testing.T) { func Test_SQLite3_Set_Expiration(t *testing.T) {
@@ -58,26 +58,23 @@ func Test_SQLite3_Set_Expiration(t *testing.T) {
) )
err := testStore.Set(key, val, exp) err := testStore.Set(key, val, exp)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
time.Sleep(1100 * time.Millisecond) time.Sleep(1100 * time.Millisecond)
} }
func Test_SQLite3_Get_Expired(t *testing.T) { func Test_SQLite3_Get_Expired(t *testing.T) {
var ( key := "john"
key = "john"
)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_SQLite3_Get_NotExist(t *testing.T) { func Test_SQLite3_Get_NotExist(t *testing.T) {
result, err := testStore.Get("notexist") result, err := testStore.Get("notexist")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_SQLite3_Delete(t *testing.T) { func Test_SQLite3_Delete(t *testing.T) {
@@ -87,79 +84,74 @@ func Test_SQLite3_Delete(t *testing.T) {
) )
err := testStore.Set(key, val, 0) err := testStore.Set(key, val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Delete(key) err = testStore.Delete(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get(key) result, err := testStore.Get(key)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_SQLite3_Reset(t *testing.T) { func Test_SQLite3_Reset(t *testing.T) {
var ( val := []byte("doe")
val = []byte("doe")
)
err := testStore.Set("john1", val, 0) err := testStore.Set("john1", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Set("john2", val, 0) err = testStore.Set("john2", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
err = testStore.Reset() err = testStore.Reset()
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get("john1") result, err := testStore.Get("john1")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
result, err = testStore.Get("john2") result, err = testStore.Get("john2")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, true, len(result) == 0) require.Zero(t, len(result))
} }
func Test_SQLite3_GC(t *testing.T) { func Test_SQLite3_GC(t *testing.T) {
var ( testVal := []byte("doe")
testVal = []byte("doe")
)
// This key should expire // This key should expire
err := testStore.Set("john", testVal, time.Nanosecond) err := testStore.Set("john", testVal, time.Nanosecond)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
testStore.gc(time.Now()) testStore.gc(time.Now())
row := testStore.db.QueryRow(testStore.sqlSelect, "john") row := testStore.db.QueryRow(testStore.sqlSelect, "john")
err = row.Scan(nil, nil) err = row.Scan(nil, nil)
utils.AssertEqual(t, sql.ErrNoRows, err) require.Equal(t, sql.ErrNoRows, err)
// This key should not expire // This key should not expire
err = testStore.Set("john", testVal, 0) err = testStore.Set("john", testVal, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
testStore.gc(time.Now()) testStore.gc(time.Now())
val, err := testStore.Get("john") val, err := testStore.Get("john")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, testVal, val) require.Equal(t, testVal, val)
} }
func Test_SQLite3_Non_UTF8(t *testing.T) { func Test_SQLite3_Non_UTF8(t *testing.T) {
val := []byte("0xF5") val := []byte("0xF5")
err := testStore.Set("0xF6", val, 0) err := testStore.Set("0xF6", val, 0)
utils.AssertEqual(t, nil, err) require.Nil(t, err)
result, err := testStore.Get("0xF6") result, err := testStore.Get("0xF6")
utils.AssertEqual(t, nil, err) require.Nil(t, err)
utils.AssertEqual(t, val, result) require.Equal(t, val, result)
} }
func Test_SQLite3_Close(t *testing.T) { func Test_SQLite3_Close(t *testing.T) {
utils.AssertEqual(t, nil, testStore.Close()) require.Nil(t, testStore.Close())
} }
func Test_SQLite3_Conn(t *testing.T) { func Test_SQLite3_Conn(t *testing.T) {
utils.AssertEqual(t, true, testStore.Conn() != nil) require.True(t, testStore.Conn() != nil)
} }