From e6700b39ca2dce7749dc1546afbd6c4eade92065 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 +++++++- 4 files changed, 15 insertions(+), 28 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 }) }