add TestMain for a few storages and update benchmark workflow

This commit is contained in:
Muhammed Efe Cetin
2023-09-15 10:58:04 +03:00
parent 55eca1c7b2
commit 36dd674d93
17 changed files with 305 additions and 227 deletions

View File

@@ -19,6 +19,64 @@ name: Benchmark
jobs:
Compare:
runs-on: ubuntu-latest
services:
arangodb:
image: 'arangodb:latest'
env:
ARANGO_NO_AUTH: 1
ports:
- '8529:8529'
dynamodb:
image: 'amazon/dynamodb-local:latest'
ports:
- '8000:8000'
memcached:
image: 'memcached:latest'
ports:
- '11211:11211'
mongo:
image: 'mongo:latest'
ports:
- '27017:27017'
mssql:
image: 'mcmoe/mssqldocker:latest'
ports:
- '1433:1433'
env:
ACCEPT_EULA: Y
SA_PASSWORD: MsSql!1234
MSSQL_DB: master
MSSQL_USER: sa
MSSQL_PASSWORD: MsSql!1234
options: >-
--health-cmd "/opt/mssql-tools/bin/sqlcmd -U sa -P $SA_PASSWORD -Q 'select 1' -b -o /dev/null"
--health-interval 1s
--health-timeout 30s
--health-start-period 10s
--health-retries 20
mysql:
image: 'mysql:latest'
env:
MYSQL_DATABASE: fiber
MYSQL_USER: username
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
ports:
- '3306:3306'
options: >-
--health-cmd "mysqladmin ping" --health-interval 10s --health-timeout
5s --health-retries 5
postgres:
image: 'postgres:latest'
ports:
- '5432:5432'
env:
POSTGRES_DB: fiber
POSTGRES_USER: username
POSTGRES_PASSWORD: "pass#w%rd"
options: >-
--health-cmd pg_isready --health-interval 10s --health-timeout 5s
--health-retries 5
steps:
- name: Fetch Repository
uses: actions/checkout@v4
@@ -29,6 +87,53 @@ jobs:
# NOTE: Keep this in sync with the version from go.mod
go-version: "1.20.x"
- name: Install Azurite
run: |
docker run -d -p 10000:10000 mcr.microsoft.com/azure-storage/azurite azurite-blob --blobHost 0.0.0.0 --blobPort 10000
- name: Install Coherence
run: |
docker run -d -p 1408:1408 -p 30000:30000 ghcr.io/oracle/coherence-ce:22.06.5
sleep 30
- name: Install couchbase
run: |
docker run --name couchbase -d -p 8091-8097:8091-8097 -p 9123:9123 -p 11207:11207 -p 11210:11210 -p 11280:11280 -p 18091-18097:18091-18097 couchbase:enterprise-7.1.1
sleep 10
docker exec --tty couchbase couchbase-cli cluster-init -c localhost:8091 --cluster-username admin --cluster-password 123456 --cluster-ramsize 256 --services data
sleep 10
docker exec --tty couchbase couchbase-cli bucket-create -c localhost:8091 --username admin --password 123456 --bucket fiber_storage --bucket-type couchbase --bucket-ramsize 100 --enable-flush 1
- name: Install etcd
run: |
docker run -d --name Etcd-server \
--publish 2379:2379 \
--publish 2380:2380 \
--env ALLOW_NONE_AUTHENTICATION=yes \
--env ETCD_ADVERTISE_CLIENT_URLS=http://etcd-server:2379 \
bitnami/etcd:latest
- name: Install MinIO
run: |
docker run -d --restart always -p 9000:9000 --name storage-minio -e MINIO_ROOT_USER='minio-user' -e MINIO_ROOT_PASSWORD='minio-password' minio/minio server /data
- name: Generate TLS certs
run: ./.github/scripts/gen-test-certs.sh
- name: Add Custom CA cert
run: sudo cp /home/runner/work/storage/storage/tls/ca.crt /usr/local/share/ca-certificates/custom.crt
- name: Trust Custom CA Cert
run: sudo update-ca-certificates
- name: Setup Redis
uses: shogo82148/actions-setup-redis@v1
with:
redis-version: '7.x'
auto-start: 'false'
- name: Run Redis
run: |
redis-server --tls-port 6380 --port 6379 \
--tls-cert-file /home/runner/work/storage/storage/tls/redis.crt \
--tls-key-file /home/runner/work/storage/storage/tls/redis.key \
--tls-ca-cert-file /home/runner/work/storage/storage/tls/ca.crt &
- name: Run Benchmarks
run: |
set -o pipefail

View File

@@ -20,7 +20,7 @@ jobs:
- 1.21.x
steps:
- name: Install MinIO
run: docker run -d -p 9000:9000 --name minio minio/minio server /data
run: docker run -d --restart always -p 9000:9000 --name storage-minio -e MINIO_ROOT_USER='minio-user' -e MINIO_ROOT_PASSWORD='minio-password' minio/minio server /data
- name: Fetch Repository
uses: actions/checkout@v4
- name: Install Go

View File

@@ -1,14 +1,17 @@
package azureblob
import (
"os"
"testing"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/bloberror"
"github.com/stretchr/testify/require"
)
func newStore() *Storage {
return New(Config{
var testStore *Storage
func TestMain(m *testing.M) {
testStore = New(Config{
Account: "devstoreaccount1",
Container: "test",
Endpoint: "http://127.0.0.1:10000/devstoreaccount1",
@@ -16,7 +19,13 @@ func newStore() *Storage {
Account: "devstoreaccount1",
Key: "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==",
},
Reset: true,
})
code := m.Run()
_ = testStore.Close()
os.Exit(code)
}
func Test_AzureBlob_Get(t *testing.T) {
@@ -24,7 +33,6 @@ func Test_AzureBlob_Get(t *testing.T) {
key = "john"
val = []byte("doe")
)
testStore := newStore()
err := testStore.Set(key, val, 0)
require.NoError(t, err)
@@ -40,7 +48,6 @@ func Test_AzureBlob_Set(t *testing.T) {
val = []byte("doe")
)
testStore := newStore()
err := testStore.Set(key, val, 0)
require.NoError(t, err)
}
@@ -50,7 +57,6 @@ func Test_AzureBlob_Delete(t *testing.T) {
key = "john"
val = []byte("doe")
)
testStore := newStore()
err := testStore.Set(key, val, 0)
require.NoError(t, err)
@@ -73,7 +79,6 @@ func Test_AzureBlob_Override(t *testing.T) {
key = "john"
val = []byte("doe")
)
testStore := newStore()
err := testStore.Set(key, val, 0)
require.NoError(t, err)
@@ -83,7 +88,6 @@ func Test_AzureBlob_Override(t *testing.T) {
}
func Test_AzureBlob_Get_NotExist(t *testing.T) {
testStore := newStore()
result, err := testStore.Get("notexist")
if err != nil {
if bloberror.HasCode(err, bloberror.BlobNotFound) {
@@ -96,7 +100,6 @@ func Test_AzureBlob_Get_NotExist(t *testing.T) {
func Test_AzureBlob_Reset(t *testing.T) {
val := []byte("doe")
testStore := newStore()
err := testStore.Set("john1", val, 0)
require.NoError(t, err)
@@ -127,18 +130,14 @@ func Test_AzureBlob_Reset(t *testing.T) {
}
func Test_S3_Conn(t *testing.T) {
testStore := newStore()
require.True(t, testStore.Conn() != nil)
}
func Test_AzureBlob_Close(t *testing.T) {
testStore := newStore()
require.Nil(t, testStore.Close())
}
func Benchmark_AzureBlob_Set(b *testing.B) {
testStore := newStore()
b.ReportAllocs()
b.ResetTimer()
@@ -151,7 +150,6 @@ func Benchmark_AzureBlob_Set(b *testing.B) {
}
func Benchmark_AzureBlob_Get(b *testing.B) {
testStore := newStore()
err := testStore.Set("john", []byte("doe"), 0)
require.NoError(b, err)
@@ -166,7 +164,6 @@ func Benchmark_AzureBlob_Get(b *testing.B) {
}
func Benchmark_AzureBlob_Delete(b *testing.B) {
testStore := newStore()
err := testStore.Set("john", []byte("doe"), 0)
require.NoError(b, err)

View File

@@ -7,7 +7,9 @@ import (
"github.com/stretchr/testify/require"
)
var testStore = New()
var testStore = New(Config{
Reset: true,
})
func Test_Badger_Set(t *testing.T) {
var (

View File

@@ -1,12 +1,25 @@
package bbolt
import (
"os"
"testing"
"github.com/stretchr/testify/require"
)
var testStore = New()
var testStore *Storage
func TestMain(m *testing.M) {
testStore = New(Config{
Bucket: "fiber-bucket",
Reset: true,
})
code := m.Run()
_ = testStore.Close()
os.Exit(code)
}
func Test_Bbolt_Set(t *testing.T) {
var (

View File

@@ -1,6 +1,7 @@
package bbolt
import (
"errors"
"github.com/gofiber/utils/v2"
"go.etcd.io/bbolt"
)
@@ -15,6 +16,11 @@ func createBucket(cfg Config, conn *bbolt.DB) error {
func removeBucket(cfg Config, conn *bbolt.DB) error {
return conn.Update(func(tx *bbolt.Tx) error {
return tx.DeleteBucket(utils.UnsafeBytes(cfg.Bucket))
err := tx.DeleteBucket(utils.UnsafeBytes(cfg.Bucket))
if errors.Is(err, bbolt.ErrBucketNotFound) {
return nil
}
return err
})
}

View File

@@ -5,6 +5,7 @@ package coherence
*/
import (
"github.com/stretchr/testify/require"
"os"
"testing"
"time"
)
@@ -17,6 +18,19 @@ var (
value2 = []byte("value2")
)
var testStore *Storage
func TestMain(m *testing.M) {
testStore, _ = New(Config{
Reset: true,
})
code := m.Run()
_ = testStore.Close()
os.Exit(code)
}
// newTestStore returns a new Coherence Store and ensures it is reset.
func newTestStore(t testing.TB, config ...Config) (*Storage, error) {
t.Helper()
@@ -32,10 +46,7 @@ func newTestStore(t testing.TB, config ...Config) (*Storage, error) {
func Test_Coherence_Set_And_Get(t *testing.T) {
var val []byte
testStore, err := newTestStore(t)
require.NoError(t, err)
err = testStore.Set(key1, value1, 0)
err := testStore.Set(key1, value1, 0)
require.NoError(t, err)
val, err = testStore.Get(key1)
@@ -43,16 +54,12 @@ func Test_Coherence_Set_And_Get(t *testing.T) {
require.Equal(t, value1, val)
require.NotNil(t, testStore.Conn())
require.Equal(t, nil, testStore.Close())
}
func Test_Coherence_Set_Override(t *testing.T) {
var val []byte
testStore, err := newTestStore(t)
require.NoError(t, err)
err = testStore.Set(key1, value1, 0)
err := testStore.Set(key1, value1, 0)
require.NoError(t, err)
err = testStore.Set(key1, value2, 0)
@@ -61,17 +68,12 @@ func Test_Coherence_Set_Override(t *testing.T) {
val, err = testStore.Get(key1)
require.NoError(t, err)
require.Equal(t, value2, val)
require.Equal(t, nil, testStore.Close())
}
func Test_Coherence_Set_With_Reset(t *testing.T) {
var val []byte
testStore, err := newTestStore(t)
require.NoError(t, err)
err = testStore.Set(key1, value1, 0)
err := testStore.Set(key1, value1, 0)
require.NoError(t, err)
val, err = testStore.Get(key1)
@@ -79,24 +81,21 @@ func Test_Coherence_Set_With_Reset(t *testing.T) {
require.Equal(t, value1, val)
// get a new store but reset it, so the subsequent Get will return nil
testStore, err = newTestStore(t, Config{Reset: true})
testStore2, err := newTestStore(t, Config{Reset: true})
require.NoError(t, err)
val, err = testStore.Get(key1)
val, err = testStore2.Get(key1)
require.NoError(t, err)
require.True(t, len(val) == 0)
require.Equal(t, nil, testStore.Close())
require.Equal(t, nil, testStore2.Close())
}
func Test_Coherence_Set_With_Expiry(t *testing.T) {
var val []byte
testStore, err := newTestStore(t)
require.NoError(t, err)
// set with an expiry of 5 seconds
err = testStore.Set(key1, value1, time.Duration(5)*time.Second)
err := testStore.Set(key1, value1, time.Duration(5)*time.Second)
require.NoError(t, err)
time.Sleep(time.Duration(6) * time.Second)
@@ -104,29 +103,20 @@ func Test_Coherence_Set_With_Expiry(t *testing.T) {
require.NoError(t, err)
require.True(t, len(val) == 0)
require.Equal(t, nil, testStore.Close())
}
func Test_Coherence_Get_Missing(t *testing.T) {
var val []byte
testStore, err := newTestStore(t)
require.NoError(t, err)
val, err = testStore.Get(missingKey)
val, err := testStore.Get(missingKey)
require.NoError(t, err)
require.True(t, len(val) == 0)
require.Equal(t, nil, testStore.Close())
}
func Test_Coherence_Reset(t *testing.T) {
var val []byte
testStore, err := newTestStore(t)
require.NoError(t, err)
err = testStore.Set(key1, value1, 0)
err := testStore.Set(key1, value1, 0)
require.NoError(t, err)
err = testStore.Set(key2, value2, 0)
@@ -152,17 +142,12 @@ func Test_Coherence_Reset(t *testing.T) {
val, err = testStore.Get(key2)
require.NoError(t, err)
require.True(t, len(val) == 0)
require.Equal(t, nil, testStore.Close())
}
func Test_Coherence_Set_And_Delete(t *testing.T) {
var val []byte
testStore, err := newTestStore(t)
require.NoError(t, err)
err = testStore.Set(key1, value1, 0)
err := testStore.Set(key1, value1, 0)
require.NoError(t, err)
err = testStore.Delete(key1)
@@ -172,8 +157,6 @@ func Test_Coherence_Set_And_Delete(t *testing.T) {
val, err = testStore.Get(key1)
require.NoError(t, err)
require.True(t, len(val) == 0)
require.Equal(t, nil, testStore.Close())
}
// TestCoherenceWithScope ensures we can create multiple session stores with multiple scopes.
@@ -208,12 +191,10 @@ func Test_Coherence_With_Scope(t *testing.T) {
}
func Benchmark_Coherence_Set(b *testing.B) {
testStore, err := newTestStore(b)
require.NoError(b, err)
b.ReportAllocs()
b.ResetTimer()
var err error
for i := 0; i < b.N; i++ {
err = testStore.Set("john", []byte("doe"), 0)
}
@@ -222,10 +203,7 @@ func Benchmark_Coherence_Set(b *testing.B) {
}
func Benchmark_Coherence_Get(b *testing.B) {
testStore, err := newTestStore(b)
require.NoError(b, err)
err = testStore.Set("john", []byte("doe"), 0)
err := testStore.Set("john", []byte("doe"), 0)
require.NoError(b, err)
b.ReportAllocs()
@@ -239,10 +217,7 @@ func Benchmark_Coherence_Get(b *testing.B) {
}
func Benchmark_Coherence_Delete(b *testing.B) {
testStore, err := newTestStore(b)
require.NoError(b, err)
err = testStore.Set("john", []byte("doe"), 0)
err := testStore.Set("john", []byte("doe"), 0)
require.NoError(b, err)
b.ReportAllocs()

View File

@@ -7,134 +7,100 @@ import (
"github.com/stretchr/testify/require"
)
func TestSetCouchbase_ShouldReturnNoError(t *testing.T) {
testStorage := New(Config{
func newTestStore(t testing.TB) *Storage {
t.Helper()
return New(Config{
Username: "admin",
Password: "123456",
Host: "127.0.0.1:8091",
Bucket: "fiber_storage",
})
}
err := testStorage.Set("test", []byte("test"), 0)
func TestSetCouchbase_ShouldReturnNoError(t *testing.T) {
testStore := newTestStore(t)
err := testStore.Set("test", []byte("test"), 0)
require.NoError(t, err)
}
func TestGetCouchbase_ShouldReturnNil_WhenDocumentNotFound(t *testing.T) {
testStorage := New(Config{
Username: "admin",
Password: "123456",
Host: "127.0.0.1:8091",
Bucket: "fiber_storage",
})
testStore := newTestStore(t)
val, err := testStorage.Get("not_found_key")
val, err := testStore.Get("not_found_key")
require.NoError(t, err)
require.Zero(t, len(val))
}
func TestSetAndGet_GetShouldReturn_SettedValueWithoutError(t *testing.T) {
testStorage := New(Config{
Username: "admin",
Password: "123456",
Host: "127.0.0.1:8091",
Bucket: "fiber_storage",
})
func TestSetAndGet_GetShouldReturn_SetValueWithoutError(t *testing.T) {
testStore := newTestStore(t)
err := testStorage.Set("test", []byte("fiber_test_value"), 0)
err := testStore.Set("test", []byte("fiber_test_value"), 0)
require.NoError(t, err)
val, err := testStorage.Get("test")
val, err := testStore.Get("test")
require.NoError(t, err)
require.Equal(t, val, []byte("fiber_test_value"))
}
func TestSetAndGet_GetShouldReturnNil_WhenTTLExpired(t *testing.T) {
testStorage := New(Config{
Username: "admin",
Password: "123456",
Host: "127.0.0.1:8091",
Bucket: "fiber_storage",
})
testStore := newTestStore(t)
err := testStorage.Set("test", []byte("fiber_test_value"), 3*time.Second)
err := testStore.Set("test", []byte("fiber_test_value"), 3*time.Second)
require.NoError(t, err)
time.Sleep(6 * time.Second)
val, err := testStorage.Get("test")
val, err := testStore.Get("test")
require.NoError(t, err)
require.Zero(t, len(val))
}
func TestSetAndDelete_DeleteShouldReturn_NoError(t *testing.T) {
testStorage := New(Config{
Username: "admin",
Password: "123456",
Host: "127.0.0.1:8091",
Bucket: "fiber_storage",
})
testStore := newTestStore(t)
err := testStorage.Set("test", []byte("fiber_test_value"), 0)
err := testStore.Set("test", []byte("fiber_test_value"), 0)
require.NoError(t, err)
err = testStorage.Delete("test")
err = testStore.Delete("test")
require.NoError(t, err)
_, err = testStorage.Get("test")
_, err = testStore.Get("test")
require.NoError(t, err)
}
func TestSetAndReset_ResetShouldReturn_NoError(t *testing.T) {
testStorage := New(Config{
Username: "admin",
Password: "123456",
Host: "127.0.0.1:8091",
Bucket: "fiber_storage",
})
testStore := newTestStore(t)
err := testStorage.Set("test", []byte("fiber_test_value"), 0)
err := testStore.Set("test", []byte("fiber_test_value"), 0)
require.NoError(t, err)
err = testStorage.Reset()
err = testStore.Reset()
require.NoError(t, err)
_, err = testStorage.Get("test")
_, err = testStore.Get("test")
require.NoError(t, err)
}
func TestClose_CloseShouldReturn_NoError(t *testing.T) {
testStorage := New(Config{
Username: "admin",
Password: "123456",
Host: "127.0.0.1:8091",
Bucket: "fiber_storage",
})
testStore := newTestStore(t)
err := testStorage.Close()
err := testStore.Close()
require.NoError(t, err)
}
func TestGetConn_ReturnsNotNill(t *testing.T) {
testStorage := New(Config{
Username: "admin",
Password: "123456",
Host: "127.0.0.1:8091",
Bucket: "fiber_storage",
})
require.True(t, testStorage.Conn() != nil)
func TestGetConn_ReturnsNotNil(t *testing.T) {
testStore := newTestStore(t)
require.True(t, testStore.Conn() != nil)
}
func Benchmark_Couchbase_Set(b *testing.B) {
testStore := New(Config{
Username: "admin",
Password: "123456",
Host: "127.0.0.1:8091",
Bucket: "fiber_storage",
})
testStore := newTestStore(b)
b.ReportAllocs()
b.ResetTimer()
@@ -148,12 +114,7 @@ func Benchmark_Couchbase_Set(b *testing.B) {
}
func Benchmark_Couchbase_Get(b *testing.B) {
testStore := New(Config{
Username: "admin",
Password: "123456",
Host: "127.0.0.1:8091",
Bucket: "fiber_storage",
})
testStore := newTestStore(b)
err := testStore.Set("john", []byte("doe"), 0)
require.NoError(b, err)
@@ -169,12 +130,7 @@ func Benchmark_Couchbase_Get(b *testing.B) {
}
func Benchmark_Couchbase_Delete(b *testing.B) {
testStore := New(Config{
Username: "admin",
Password: "123456",
Host: "127.0.0.1:8091",
Bucket: "fiber_storage",
})
testStore := newTestStore(b)
err := testStore.Set("john", []byte("doe"), 0)
require.NoError(b, err)

View File

@@ -1,13 +1,16 @@
package dynamodb
import (
"os"
"testing"
"github.com/stretchr/testify/require"
)
var testStore = New(
Config{
var testStore *Storage
func TestMain(m *testing.M) {
testStore = New(Config{
Table: "fiber_storage",
Endpoint: "http://localhost:8000/",
Region: "us-east-1",
@@ -15,8 +18,14 @@ var testStore = New(
AccessKey: "dummy",
SecretAccessKey: "dummy",
},
},
)
Reset: true,
})
code := m.Run()
_ = testStore.Close()
os.Exit(code)
}
func Test_DynamoDB_Set(t *testing.T) {
var (

View File

@@ -1,119 +1,98 @@
package etcd
import (
"os"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestSetEtcd_ShouldReturnNoError(t *testing.T) {
testStorage := New(Config{
var testStore *Storage
func TestMain(m *testing.M) {
testStore = New(Config{
Endpoints: []string{"localhost:2379"},
})
code := m.Run()
_ = testStore.Reset()
_ = testStore.Close()
os.Exit(code)
}
func TestSetEtcd_ShouldReturnNoError(t *testing.T) {
var (
key = "john"
val = []byte("doe")
)
err := testStorage.Set(key, val, 0)
err := testStore.Set(key, val, 0)
require.NoError(t, err)
}
func TestGetEtcd_ShouldReturnNil_WhenDocumentNotFound(t *testing.T) {
testStorage := New(Config{
Endpoints: []string{"localhost:2379"},
})
val, err := testStorage.Get("not_found_key")
val, err := testStore.Get("not_found_key")
require.NoError(t, err)
require.Zero(t, len(val))
}
func TestSetAndGet_GetShouldReturn_SettedValueWithoutError(t *testing.T) {
testStorage := New(Config{
Endpoints: []string{"localhost:2379"},
})
err := testStorage.Set("test", []byte("fiber_test_value"), 0)
err := testStore.Set("test", []byte("fiber_test_value"), 0)
require.NoError(t, err)
val, err := testStorage.Get("test")
val, err := testStore.Get("test")
require.NoError(t, err)
require.Equal(t, val, []byte("fiber_test_value"))
}
func TestSetAndGet_GetShouldReturnNil_WhenTTLExpired(t *testing.T) {
testStorage := New(Config{
Endpoints: []string{"localhost:2379"},
})
err := testStorage.Set("test", []byte("fiber_test_value"), 3*time.Second)
err := testStore.Set("test", []byte("fiber_test_value"), 3*time.Second)
require.NoError(t, err)
time.Sleep(6 * time.Second)
val, err := testStorage.Get("test")
val, err := testStore.Get("test")
require.NoError(t, err)
require.Zero(t, len(val))
}
func TestSetAndDelete_DeleteShouldReturn_NoError(t *testing.T) {
testStorage := New(Config{
Endpoints: []string{"localhost:2379"},
})
err := testStorage.Set("test", []byte("fiber_test_value"), 0)
err := testStore.Set("test", []byte("fiber_test_value"), 0)
require.NoError(t, err)
err = testStorage.Delete("test")
err = testStore.Delete("test")
require.NoError(t, err)
_, err = testStorage.Get("test")
_, err = testStore.Get("test")
require.NoError(t, err)
}
func TestSetAndReset_ResetShouldReturn_NoError(t *testing.T) {
testStorage := New(Config{
Endpoints: []string{"localhost:2379"},
})
err := testStorage.Set("test", []byte("fiber_test_value"), 0)
err := testStore.Set("test", []byte("fiber_test_value"), 0)
require.NoError(t, err)
err = testStorage.Reset()
err = testStore.Reset()
require.NoError(t, err)
_, err = testStorage.Get("test")
_, err = testStore.Get("test")
require.NoError(t, err)
}
func TestClose_CloseShouldReturn_NoError(t *testing.T) {
testStorage := New(Config{
Endpoints: []string{"localhost:2379"},
})
err := testStorage.Close()
err := testStore.Close()
require.NoError(t, err)
}
func TestGetConn_ReturnsNotNill(t *testing.T) {
testStorage := New(Config{
Endpoints: []string{"localhost:2379"},
})
require.True(t, testStorage.Conn() != nil)
require.True(t, testStore.Conn() != nil)
}
func Benchmark_Etcd_Set(b *testing.B) {
testStore := New(Config{
Endpoints: []string{"localhost:2379"},
})
b.ReportAllocs()
b.ResetTimer()
@@ -126,10 +105,6 @@ func Benchmark_Etcd_Set(b *testing.B) {
}
func Benchmark_Etcd_Get(b *testing.B) {
testStore := New(Config{
Endpoints: []string{"localhost:2379"},
})
err := testStore.Set("john", []byte("doe"), 0)
require.NoError(b, err)
@@ -144,10 +119,6 @@ func Benchmark_Etcd_Get(b *testing.B) {
}
func Benchmark_Etcd_Delete(b *testing.B) {
testStore := New(Config{
Endpoints: []string{"localhost:2379"},
})
err := testStore.Set("john", []byte("doe"), 0)
require.NoError(b, err)

View File

@@ -1,13 +1,25 @@
package memcache
import (
"os"
"testing"
"time"
"github.com/stretchr/testify/require"
)
var testStore = New()
var testStore *Storage
func TestMain(m *testing.M) {
testStore = New(Config{
Reset: true,
})
code := m.Run()
_ = testStore.Close()
os.Exit(code)
}
func Test_Memcache_Set(t *testing.T) {
var (

View File

@@ -1,6 +1,7 @@
package minio
import (
"os"
"strconv"
"testing"
"time"
@@ -8,7 +9,10 @@ import (
"github.com/stretchr/testify/require"
)
var testStore = New(
var testStore *Storage
func TestMain(m *testing.M) {
testStore = New(
Config{
Bucket: "fiber-bucket",
Endpoint: "localhost:9000",
@@ -16,9 +20,16 @@ var testStore = New(
AccessKeyID: "minio-user",
SecretAccessKey: "minio-password",
},
Reset: true,
},
)
code := m.Run()
_ = testStore.Close()
os.Exit(code)
}
func Test_Get(t *testing.T) {
var (
key = "john"

View File

@@ -1,16 +1,26 @@
package mongodb
import (
"os"
"testing"
"time"
"github.com/stretchr/testify/require"
)
var testStore = New(Config{
var testStore *Storage
func TestMain(m *testing.M) {
testStore = New(Config{
Reset: true,
})
code := m.Run()
_ = testStore.Close()
os.Exit(code)
}
func Test_MongoDB_Set(t *testing.T) {
var (
key = "john"

View File

@@ -26,7 +26,7 @@ func Test_MYSQL_New(t *testing.T) {
})
require.True(t, newConfigStore.db != nil)
newConfigStore.Close()
require.NoError(t, 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"))
newConfigStore = New(Config{

View File

@@ -8,8 +8,8 @@ import (
)
var testStore = New(Config{
"test.db",
nil,
Path: "test.db",
WriteOptions: nil,
})
func Test_Pebble_Set(t *testing.T) {

View File

@@ -1,13 +1,24 @@
package ristretto
import (
"os"
"testing"
"time"
"github.com/stretchr/testify/require"
)
var testStore = New()
var testStore *Storage
func TestMain(m *testing.M) {
testStore = New()
code := m.Run()
_ = testStore.Reset()
_ = testStore.Close()
os.Exit(code)
}
func Test_Ristretto_Set(t *testing.T) {
var (

View File

@@ -19,8 +19,8 @@ func TestMain(m *testing.M) {
Endpoint: "http://127.0.0.1:9000/",
Region: "us-east-1",
Credentials: Credentials{
AccessKey: "minioadmin",
SecretAccessKey: "minioadmin",
AccessKey: "minio-user",
SecretAccessKey: "minio-password",
},
RequestTimeout: 3 * time.Second,
},