mirror of
https://github.com/gofiber/storage.git
synced 2025-10-05 16:48:25 +08:00
Add test case for MYSQL New method
This commit is contained in:
@@ -2,11 +2,13 @@ package mysql
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
var testStore = New(Config{
|
||||
@@ -16,6 +18,32 @@ var testStore = New(Config{
|
||||
Reset: true,
|
||||
})
|
||||
|
||||
func Test_MYSQL_New(t *testing.T) {
|
||||
newConfigStore := New(Config{
|
||||
Database: os.Getenv("MYSQL_DATABASE"),
|
||||
Username: os.Getenv("MYSQL_USERNAME"),
|
||||
Password: os.Getenv("MYSQL_PASSWORD"),
|
||||
Reset: true,
|
||||
})
|
||||
utils.AssertEqual(t, reflect.TypeOf(newConfigStore.db).String(), "*sql.DB")
|
||||
|
||||
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{
|
||||
ConnectionURI: dsn,
|
||||
Reset: true,
|
||||
})
|
||||
utils.AssertEqual(t, reflect.TypeOf(newConfigStore.db).String(), "*sql.DB")
|
||||
|
||||
db, _ := sql.Open("mysql", dsn)
|
||||
|
||||
newConfigStore = New(Config{
|
||||
Db: db,
|
||||
Reset: true,
|
||||
})
|
||||
utils.AssertEqual(t, reflect.TypeOf(newConfigStore.db).String(), "*sql.DB")
|
||||
}
|
||||
|
||||
func Test_MYSQL_Set(t *testing.T) {
|
||||
var (
|
||||
key = "john"
|
||||
|
Reference in New Issue
Block a user