test(database): improve
continuous-integration/drone the build failed
Details
continuous-integration/drone the build failed
Details
This commit is contained in:
parent
95b99107f5
commit
a0fe660f97
|
@ -0,0 +1,12 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrNotConnected - database is not connected
|
||||
ErrNotConnected = errors.New("database is not connected")
|
||||
// ErrNothingToMigrate if nothing has to be migrated
|
||||
ErrNothingToMigrate = errors.New("there is nothing to migrate")
|
||||
)
|
|
@ -40,6 +40,9 @@ func (config *Database) Run() error {
|
|||
|
||||
// Status get status - is database pingable
|
||||
func (config *Database) Status() error {
|
||||
if config.DB == nil {
|
||||
return ErrNotConnected
|
||||
}
|
||||
sqlDB, err := config.DB.DB()
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -1 +1,35 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var (
|
||||
// DBConnection - url to database on setting up default WebService for webtest
|
||||
DBConnection = "user=root password=root dbname=defaultdb host=localhost port=26257 sslmode=disable"
|
||||
)
|
||||
|
||||
func TestStatus(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
d := Database{
|
||||
Debug: true,
|
||||
}
|
||||
err := d.Status()
|
||||
assert.Error(err)
|
||||
assert.Equal(ErrNotConnected, err)
|
||||
|
||||
err = d.Run()
|
||||
assert.Error(err)
|
||||
assert.Contains(err.Error(), "dial error")
|
||||
|
||||
d.Connection = DBConnection
|
||||
err = d.Run()
|
||||
assert.Error(err)
|
||||
assert.Equal(ErrNothingToMigrate, err)
|
||||
|
||||
err = d.Status()
|
||||
assert.NoError(err)
|
||||
}
|
||||
|
|
|
@ -1,18 +1,12 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sort"
|
||||
|
||||
"github.com/bdlm/log"
|
||||
gormigrate "github.com/go-gormigrate/gormigrate/v2"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrNothingToMigrate if nothing has to be migrated
|
||||
ErrNothingToMigrate = errors.New("there is nothing to migrate")
|
||||
)
|
||||
|
||||
func (config *Database) sortedMigration(testdata bool) []*gormigrate.Migration {
|
||||
var migrations []*gormigrate.Migration
|
||||
for _, v := range config.migrations {
|
||||
|
|
Loading…
Reference in New Issue