2016-09-15 06:41:57 +05:30
|
|
|
package sql
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
2016-11-23 05:05:46 +05:30
|
|
|
"os"
|
2016-09-15 06:41:57 +05:30
|
|
|
"testing"
|
2016-11-23 05:05:46 +05:30
|
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
2016-09-15 06:41:57 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
func TestMigrate(t *testing.T) {
|
|
|
|
db, err := sql.Open("sqlite3", ":memory:")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer db.Close()
|
|
|
|
|
2016-11-23 05:05:46 +05:30
|
|
|
logger := &logrus.Logger{
|
|
|
|
Out: os.Stderr,
|
|
|
|
Formatter: &logrus.TextFormatter{DisableColors: true},
|
|
|
|
Level: logrus.DebugLevel,
|
|
|
|
}
|
|
|
|
|
|
|
|
c := &conn{db, flavorSQLite3, logger}
|
2016-09-15 06:41:57 +05:30
|
|
|
for _, want := range []int{len(migrations), 0} {
|
|
|
|
got, err := c.migrate()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if got != want {
|
|
|
|
t.Errorf("expected %d migrations, got %d", want, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|