2020-02-22 19:40:06 +03:00
|
|
|
package postgres_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-02-23 07:39:26 +03:00
|
|
|
"os"
|
2020-02-22 19:40:06 +03:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/jinzhu/gorm"
|
|
|
|
"github.com/jinzhu/gorm/dialects/postgres"
|
|
|
|
"github.com/jinzhu/gorm/tests"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
DB *gorm.DB
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2020-02-23 07:39:26 +03:00
|
|
|
dsn := "user=gorm password=gorm DB.name=gorm port=9920 sslmode=disable"
|
|
|
|
if os.Getenv("GORM_DSN") != "" {
|
|
|
|
dsn = os.Getenv("GORM_DSN")
|
|
|
|
}
|
|
|
|
|
|
|
|
if DB, err = gorm.Open(postgres.Open(dsn), &gorm.Config{}); err != nil {
|
2020-02-22 19:40:06 +03:00
|
|
|
panic(fmt.Sprintf("failed to initialize database, got error %v", err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCURD(t *testing.T) {
|
|
|
|
tests.RunTestsSuit(t, DB)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMigrate(t *testing.T) {
|
|
|
|
tests.TestMigrate(t, DB)
|
|
|
|
}
|