From 0f21838d55bac60a67182579596cfffe943159d9 Mon Sep 17 00:00:00 2001 From: Muhammed Efe Cetin Date: Fri, 15 Sep 2023 12:28:52 +0300 Subject: [PATCH] fix tests --- arangodb/arangodb_test.go | 16 +++------------- badger/badger_test.go | 16 +++------------- bbolt/bbolt_test.go | 3 ++- bbolt/utils.go | 8 +++++++- memory/memory_test.go | 13 +------------ mssql/mssql_test.go | 21 ++++++--------------- mysql/mysql_test.go | 21 ++++++--------------- pebble/pebble_test.go | 19 ++++--------------- postgres/postgres_test.go | 21 ++++++--------------- redis/redis_test.go | 16 +++------------- rueidis/rueidis_test.go | 16 +++------------- 11 files changed, 44 insertions(+), 126 deletions(-) diff --git a/arangodb/arangodb_test.go b/arangodb/arangodb_test.go index e2baa6812..9ce6ae67f 100644 --- a/arangodb/arangodb_test.go +++ b/arangodb/arangodb_test.go @@ -1,25 +1,15 @@ package arangodb import ( - "os" "testing" "time" "github.com/stretchr/testify/require" ) -var testStore *Storage - -func TestMain(m *testing.M) { - testStore = New(Config{ - Reset: true, - }) - - code := m.Run() - - _ = testStore.Close() - os.Exit(code) -} +var testStore = New(Config{ + Reset: true, +}) func Test_ArangoDB_Set(t *testing.T) { var ( diff --git a/badger/badger_test.go b/badger/badger_test.go index 2957f7838..2f471a987 100644 --- a/badger/badger_test.go +++ b/badger/badger_test.go @@ -1,25 +1,15 @@ package badger import ( - "os" "testing" "time" "github.com/stretchr/testify/require" ) -var testStore *Storage - -func TestMain(m *testing.M) { - testStore = New(Config{ - Reset: true, - }) - - code := m.Run() - - _ = testStore.Close() - os.Exit(code) -} +var testStore = New(Config{ + Reset: true, +}) func Test_Badger_Set(t *testing.T) { var ( diff --git a/bbolt/bbolt_test.go b/bbolt/bbolt_test.go index 87b728110..7ac196afb 100644 --- a/bbolt/bbolt_test.go +++ b/bbolt/bbolt_test.go @@ -11,7 +11,8 @@ var testStore *Storage func TestMain(m *testing.M) { testStore = New(Config{ - Reset: true, + Bucket: "fiber-bucket", + Reset: true, }) code := m.Run() diff --git a/bbolt/utils.go b/bbolt/utils.go index d731e529d..e3603e331 100644 --- a/bbolt/utils.go +++ b/bbolt/utils.go @@ -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 }) } diff --git a/memory/memory_test.go b/memory/memory_test.go index c27c3e72e..bcb100e12 100644 --- a/memory/memory_test.go +++ b/memory/memory_test.go @@ -1,7 +1,6 @@ package memory import ( - "os" "testing" "time" @@ -9,17 +8,7 @@ import ( "github.com/stretchr/testify/require" ) -var testStore *Storage - -func TestMain(m *testing.M) { - testStore = New() - - code := m.Run() - - _ = testStore.Reset() - _ = testStore.Close() - os.Exit(code) -} +var testStore = New() func Test_Storage_Memory_Set(t *testing.T) { var ( diff --git a/mssql/mssql_test.go b/mssql/mssql_test.go index 0af6a34bb..6cdf17830 100644 --- a/mssql/mssql_test.go +++ b/mssql/mssql_test.go @@ -9,21 +9,12 @@ import ( "github.com/stretchr/testify/require" ) -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) -} +var testStore = New(Config{ + Database: os.Getenv("MSSQL_DATABASE"), + Username: os.Getenv("MSSQL_USERNAME"), + Password: os.Getenv("MSSQL_PASSWORD"), + Reset: true, +}) func Test_MSSQL_Set(t *testing.T) { var ( diff --git a/mysql/mysql_test.go b/mysql/mysql_test.go index d9344fda7..66a74c34a 100644 --- a/mysql/mysql_test.go +++ b/mysql/mysql_test.go @@ -10,21 +10,12 @@ import ( "github.com/stretchr/testify/require" ) -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) -} +var testStore = New(Config{ + Database: os.Getenv("MYSQL_DATABASE"), + Username: os.Getenv("MYSQL_USERNAME"), + Password: os.Getenv("MYSQL_PASSWORD"), + Reset: true, +}) func Test_MYSQL_New(t *testing.T) { newConfigStore := New(Config{ diff --git a/pebble/pebble_test.go b/pebble/pebble_test.go index cbc7bae40..505645ac9 100644 --- a/pebble/pebble_test.go +++ b/pebble/pebble_test.go @@ -1,27 +1,16 @@ package pebble import ( - "os" "testing" "time" "github.com/stretchr/testify/require" ) -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) -} +var testStore = New(Config{ + Path: "test.db", + WriteOptions: nil, +}) func Test_Pebble_Set(t *testing.T) { var ( diff --git a/postgres/postgres_test.go b/postgres/postgres_test.go index e0d5f7472..6057e721d 100644 --- a/postgres/postgres_test.go +++ b/postgres/postgres_test.go @@ -10,21 +10,12 @@ import ( "github.com/stretchr/testify/require" ) -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) -} +var testStore = New(Config{ + Database: os.Getenv("POSTGRES_DATABASE"), + Username: os.Getenv("POSTGRES_USERNAME"), + Password: os.Getenv("POSTGRES_PASSWORD"), + Reset: true, +}) func Test_Postgres_Set(t *testing.T) { var ( diff --git a/redis/redis_test.go b/redis/redis_test.go index 99b312b4d..9ecbb92da 100644 --- a/redis/redis_test.go +++ b/redis/redis_test.go @@ -3,25 +3,15 @@ package redis import ( "crypto/tls" "log" - "os" "testing" "time" "github.com/stretchr/testify/require" ) -var testStore *Storage - -func TestMain(m *testing.M) { - testStore = New(Config{ - Reset: true, - }) - - code := m.Run() - - _ = testStore.Close() - os.Exit(code) -} +var testStore = New(Config{ + Reset: true, +}) func Test_Redis_Set(t *testing.T) { var ( diff --git a/rueidis/rueidis_test.go b/rueidis/rueidis_test.go index f2de8badb..b78cd9363 100644 --- a/rueidis/rueidis_test.go +++ b/rueidis/rueidis_test.go @@ -3,25 +3,15 @@ package rueidis import ( "crypto/tls" "log" - "os" "testing" "time" "github.com/stretchr/testify/require" ) -var testStore *Storage - -func TestMain(m *testing.M) { - testStore = New(Config{ - Reset: true, - }) - - code := m.Run() - - _ = testStore.Close() - os.Exit(code) -} +var testStore = New(Config{ + Reset: true, +}) func Test_Rueidis_Set(t *testing.T) { var (