Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
efectn committed Sep 15, 2023
1 parent 09e12a7 commit 0f21838
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 126 deletions.
16 changes: 3 additions & 13 deletions arangodb/arangodb_test.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
16 changes: 3 additions & 13 deletions badger/badger_test.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
3 changes: 2 additions & 1 deletion bbolt/bbolt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 7 additions & 1 deletion bbolt/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bbolt

import (
"errors"
"github.com/gofiber/utils/v2"
"go.etcd.io/bbolt"
)
Expand All @@ -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
})
}
13 changes: 1 addition & 12 deletions memory/memory_test.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
package memory

import (
"os"
"testing"
"time"

"github.com/gofiber/utils/v2"
"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 (
Expand Down
21 changes: 6 additions & 15 deletions mssql/mssql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
21 changes: 6 additions & 15 deletions mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
19 changes: 4 additions & 15 deletions pebble/pebble_test.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
21 changes: 6 additions & 15 deletions postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
16 changes: 3 additions & 13 deletions redis/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
16 changes: 3 additions & 13 deletions rueidis/rueidis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 0f21838

Please sign in to comment.