golang-lib/database/main_test.go

38 lines
779 B
Go
Raw Normal View History

2017-05-17 16:17:02 +02:00
package database
2021-06-02 18:00:53 +02:00
import (
"testing"
"github.com/stretchr/testify/assert"
)
var (
// DBConnection - url to database on setting up default WebService for webtest
// DBConnection = "postgresql://root:root@localhost:26257/defaultdb?sslmode=disable"
DBConnection = "postgresql://root:root@localhost/defaultdb?sslmode=disable"
2021-06-02 18:00:53 +02:00
)
func TestStatus(t *testing.T) {
assert := assert.New(t)
d := Database{
Debug: true,
}
d.Connection.URI = "postgresql://localhost"
2021-06-02 18:00:53 +02:00
err := d.Status()
assert.Error(err)
assert.Equal(ErrNotConnected, err)
err = d.Run()
assert.Error(err)
assert.Contains(err.Error(), "failed to connect")
2021-06-02 18:00:53 +02:00
d.Connection.URI = DBConnection
2021-06-02 18:00:53 +02:00
err = d.Run()
assert.Error(err)
assert.Equal(ErrNothingToMigrate, err)
err = d.Status()
assert.NoError(err)
}