From 8e6e0a143ec67cb559f47df9b3156d38ee3f7e9c Mon Sep 17 00:00:00 2001 From: Muhammed Efe Cetin Date: Fri, 15 Sep 2023 11:30:43 +0300 Subject: [PATCH] update benchmark workflow --- .github/workflows/benchmark.yml | 105 ++++++++++++++++++++++++++++++ .github/workflows/test-s3.yml | 2 +- arangodb/arangodb_test.go | 16 ++++- azureblob/azureblob_test.go | 25 ++++--- badger/badger_test.go | 14 +++- bbolt/bbolt_test.go | 14 +++- couchbase/couchbase_test.go | 112 ++++++++------------------------ dynamodb/dynamodb_test.go | 17 +++-- etcd/etcd_test.go | 83 ++++++++--------------- memcache/memcache_test.go | 14 +++- memory/memory_test.go | 13 +++- minio/minio_test.go | 29 ++++++--- mongodb/mongodb_test.go | 16 ++++- mssql/mssql_test.go | 21 ++++-- mysql/mysql_test.go | 23 +++++-- pebble/pebble_test.go | 19 ++++-- postgres/postgres_test.go | 21 ++++-- redis/redis_test.go | 16 ++++- ristretto/ristretto_test.go | 13 +++- rueidis/rueidis_test.go | 16 ++++- s3/init_test.go | 4 +- sqlite3/sqlite3_test.go | 16 ++++- 22 files changed, 395 insertions(+), 214 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 6cb096583..733c7d4c0 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -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: ${{ matrix.redis }} + 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 diff --git a/.github/workflows/test-s3.yml b/.github/workflows/test-s3.yml index 64c68fadd..23ff9ce19 100644 --- a/.github/workflows/test-s3.yml +++ b/.github/workflows/test-s3.yml @@ -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 diff --git a/arangodb/arangodb_test.go b/arangodb/arangodb_test.go index 9ce6ae67f..e2baa6812 100644 --- a/arangodb/arangodb_test.go +++ b/arangodb/arangodb_test.go @@ -1,15 +1,25 @@ package arangodb import ( + "os" "testing" "time" "github.com/stretchr/testify/require" ) -var testStore = New(Config{ - Reset: true, -}) +var testStore *Storage + +func TestMain(m *testing.M) { + testStore = New(Config{ + Reset: true, + }) + + code := m.Run() + + _ = testStore.Close() + os.Exit(code) +} func Test_ArangoDB_Set(t *testing.T) { var ( diff --git a/azureblob/azureblob_test.go b/azureblob/azureblob_test.go index 9138cb6c7..59da61b9b 100644 --- a/azureblob/azureblob_test.go +++ b/azureblob/azureblob_test.go @@ -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) diff --git a/badger/badger_test.go b/badger/badger_test.go index 8d06861f5..2957f7838 100644 --- a/badger/badger_test.go +++ b/badger/badger_test.go @@ -1,13 +1,25 @@ package badger 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_Badger_Set(t *testing.T) { var ( diff --git a/bbolt/bbolt_test.go b/bbolt/bbolt_test.go index 8a66027ab..87b728110 100644 --- a/bbolt/bbolt_test.go +++ b/bbolt/bbolt_test.go @@ -1,12 +1,24 @@ package bbolt import ( + "os" "testing" "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_Bbolt_Set(t *testing.T) { var ( diff --git a/couchbase/couchbase_test.go b/couchbase/couchbase_test.go index 3877ce1c4..a6d40a864 100644 --- a/couchbase/couchbase_test.go +++ b/couchbase/couchbase_test.go @@ -1,141 +1,97 @@ package couchbase import ( + "os" "testing" "time" "github.com/stretchr/testify/require" ) -func TestSetCouchbase_ShouldReturnNoError(t *testing.T) { - testStorage := New(Config{ +var testStore *Storage + +func TestMain(m *testing.M) { + testStore = New(Config{ Username: "admin", Password: "123456", Host: "127.0.0.1:8091", Bucket: "fiber_storage", }) - err := testStorage.Set("test", []byte("test"), 0) + code := m.Run() + + _ = testStore.Reset() + _ = testStore.Close() + os.Exit(code) +} + +func TestSetCouchbase_ShouldReturnNoError(t *testing.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", - }) - - 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", - }) - - 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", - }) - - 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", - }) - - 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", - }) - - 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", - }) - - 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) + 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", - }) - b.ReportAllocs() b.ResetTimer() @@ -148,13 +104,6 @@ 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", - }) - err := testStore.Set("john", []byte("doe"), 0) require.NoError(b, err) @@ -169,13 +118,6 @@ 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", - }) - err := testStore.Set("john", []byte("doe"), 0) require.NoError(b, err) diff --git a/dynamodb/dynamodb_test.go b/dynamodb/dynamodb_test.go index 55c7c932d..704b344bd 100644 --- a/dynamodb/dynamodb_test.go +++ b/dynamodb/dynamodb_test.go @@ -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 ( diff --git a/etcd/etcd_test.go b/etcd/etcd_test.go index 1ca5b5e03..bcbcf20e8 100644 --- a/etcd/etcd_test.go +++ b/etcd/etcd_test.go @@ -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) diff --git a/memcache/memcache_test.go b/memcache/memcache_test.go index 08035b1f6..5947b0c2b 100644 --- a/memcache/memcache_test.go +++ b/memcache/memcache_test.go @@ -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 ( diff --git a/memory/memory_test.go b/memory/memory_test.go index bcb100e12..c27c3e72e 100644 --- a/memory/memory_test.go +++ b/memory/memory_test.go @@ -1,6 +1,7 @@ package memory import ( + "os" "testing" "time" @@ -8,7 +9,17 @@ import ( "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_Storage_Memory_Set(t *testing.T) { var ( diff --git a/minio/minio_test.go b/minio/minio_test.go index 20848c068..683c985e8 100644 --- a/minio/minio_test.go +++ b/minio/minio_test.go @@ -1,6 +1,7 @@ package minio import ( + "os" "strconv" "testing" "time" @@ -8,16 +9,26 @@ import ( "github.com/stretchr/testify/require" ) -var testStore = New( - Config{ - Bucket: "fiber-bucket", - Endpoint: "localhost:9000", - Credentials: Credentials{ - AccessKeyID: "minio-user", - SecretAccessKey: "minio-password", +var testStore *Storage + +func TestMain(m *testing.M) { + testStore = New( + Config{ + Bucket: "fiber-bucket", + Endpoint: "localhost:9000", + Credentials: Credentials{ + AccessKeyID: "minio-user", + SecretAccessKey: "minio-password", + }, + Reset: true, }, - }, -) + ) + + code := m.Run() + + _ = testStore.Close() + os.Exit(code) +} func Test_Get(t *testing.T) { var ( diff --git a/mongodb/mongodb_test.go b/mongodb/mongodb_test.go index 5b7027e67..36f3fe13f 100644 --- a/mongodb/mongodb_test.go +++ b/mongodb/mongodb_test.go @@ -1,15 +1,25 @@ package mongodb import ( + "os" "testing" "time" "github.com/stretchr/testify/require" ) -var testStore = New(Config{ - Reset: true, -}) +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 ( diff --git a/mssql/mssql_test.go b/mssql/mssql_test.go index 6cdf17830..0af6a34bb 100644 --- a/mssql/mssql_test.go +++ b/mssql/mssql_test.go @@ -9,12 +9,21 @@ import ( "github.com/stretchr/testify/require" ) -var testStore = New(Config{ - Database: os.Getenv("MSSQL_DATABASE"), - Username: os.Getenv("MSSQL_USERNAME"), - Password: os.Getenv("MSSQL_PASSWORD"), - Reset: true, -}) +var testStore *Storage + +func TestMain(m *testing.M) { + testStore = New(Config{ + Database: os.Getenv("MSSQL_DATABASE"), + Username: os.Getenv("MSSQL_USERNAME"), + Password: os.Getenv("MSSQL_PASSWORD"), + Reset: true, + }) + + code := m.Run() + + _ = testStore.Close() + os.Exit(code) +} func Test_MSSQL_Set(t *testing.T) { var ( diff --git a/mysql/mysql_test.go b/mysql/mysql_test.go index 57932fb5a..d9344fda7 100644 --- a/mysql/mysql_test.go +++ b/mysql/mysql_test.go @@ -10,12 +10,21 @@ import ( "github.com/stretchr/testify/require" ) -var testStore = New(Config{ - Database: os.Getenv("MYSQL_DATABASE"), - Username: os.Getenv("MYSQL_USERNAME"), - Password: os.Getenv("MYSQL_PASSWORD"), - Reset: true, -}) +var testStore *Storage + +func TestMain(m *testing.M) { + testStore = New(Config{ + Database: os.Getenv("MYSQL_DATABASE"), + Username: os.Getenv("MYSQL_USERNAME"), + Password: os.Getenv("MYSQL_PASSWORD"), + Reset: true, + }) + + code := m.Run() + + _ = testStore.Close() + os.Exit(code) +} func Test_MYSQL_New(t *testing.T) { newConfigStore := New(Config{ @@ -26,7 +35,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{ diff --git a/pebble/pebble_test.go b/pebble/pebble_test.go index d17ac7081..cbc7bae40 100644 --- a/pebble/pebble_test.go +++ b/pebble/pebble_test.go @@ -1,16 +1,27 @@ package pebble import ( + "os" "testing" "time" "github.com/stretchr/testify/require" ) -var testStore = New(Config{ - "test.db", - nil, -}) +var testStore *Storage + +func TestMain(m *testing.M) { + testStore = New(Config{ + Path: "test.db", + WriteOptions: nil, + }) + + code := m.Run() + + _ = testStore.Reset() + _ = testStore.Close() + os.Exit(code) +} func Test_Pebble_Set(t *testing.T) { var ( diff --git a/postgres/postgres_test.go b/postgres/postgres_test.go index 6057e721d..e0d5f7472 100644 --- a/postgres/postgres_test.go +++ b/postgres/postgres_test.go @@ -10,12 +10,21 @@ import ( "github.com/stretchr/testify/require" ) -var testStore = New(Config{ - Database: os.Getenv("POSTGRES_DATABASE"), - Username: os.Getenv("POSTGRES_USERNAME"), - Password: os.Getenv("POSTGRES_PASSWORD"), - Reset: true, -}) +var testStore *Storage + +func TestMain(m *testing.M) { + testStore = New(Config{ + Database: os.Getenv("POSTGRES_DATABASE"), + Username: os.Getenv("POSTGRES_USERNAME"), + Password: os.Getenv("POSTGRES_PASSWORD"), + Reset: true, + }) + + code := m.Run() + + _ = testStore.Close() + os.Exit(code) +} func Test_Postgres_Set(t *testing.T) { var ( diff --git a/redis/redis_test.go b/redis/redis_test.go index 9ecbb92da..99b312b4d 100644 --- a/redis/redis_test.go +++ b/redis/redis_test.go @@ -3,15 +3,25 @@ package redis import ( "crypto/tls" "log" + "os" "testing" "time" "github.com/stretchr/testify/require" ) -var testStore = New(Config{ - Reset: true, -}) +var testStore *Storage + +func TestMain(m *testing.M) { + testStore = New(Config{ + Reset: true, + }) + + code := m.Run() + + _ = testStore.Close() + os.Exit(code) +} func Test_Redis_Set(t *testing.T) { var ( diff --git a/ristretto/ristretto_test.go b/ristretto/ristretto_test.go index b1a6fc08b..c7bf4c5e5 100644 --- a/ristretto/ristretto_test.go +++ b/ristretto/ristretto_test.go @@ -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 ( diff --git a/rueidis/rueidis_test.go b/rueidis/rueidis_test.go index b78cd9363..f2de8badb 100644 --- a/rueidis/rueidis_test.go +++ b/rueidis/rueidis_test.go @@ -3,15 +3,25 @@ package rueidis import ( "crypto/tls" "log" + "os" "testing" "time" "github.com/stretchr/testify/require" ) -var testStore = New(Config{ - Reset: true, -}) +var testStore *Storage + +func TestMain(m *testing.M) { + testStore = New(Config{ + Reset: true, + }) + + code := m.Run() + + _ = testStore.Close() + os.Exit(code) +} func Test_Rueidis_Set(t *testing.T) { var ( diff --git a/s3/init_test.go b/s3/init_test.go index 7d8d0c210..56b8cd2c5 100644 --- a/s3/init_test.go +++ b/s3/init_test.go @@ -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, }, diff --git a/sqlite3/sqlite3_test.go b/sqlite3/sqlite3_test.go index 6d7906282..64c9a0e96 100644 --- a/sqlite3/sqlite3_test.go +++ b/sqlite3/sqlite3_test.go @@ -2,6 +2,7 @@ package sqlite3 import ( "database/sql" + "os" "testing" "time" @@ -9,9 +10,18 @@ import ( "github.com/stretchr/testify/require" ) -var testStore = New(Config{ - Reset: true, -}) +var testStore *Storage + +func TestMain(m *testing.M) { + testStore = New(Config{ + Reset: true, + }) + + code := m.Run() + + _ = testStore.Close() + os.Exit(code) +} func Test_SQLite3_Set(t *testing.T) { var (