package sql
import (
"database/sql"
"os"
"testing"
sqlite3 "github.com/mattn/go-sqlite3"
"github.com/sirupsen/logrus"
"github.com/dexidp/dex/pkg/log"
)
func TestMigrate(t *testing.T) {
db, err := sql.Open("sqlite3", ":memory:")
if err != nil {
t.Fatal(err)
}
defer db.Close()
logger := log.NewLogrusLogger(&logrus.Logger{
Out: os.Stderr,
Formatter: &logrus.TextFormatter{DisableColors: true},
Level: logrus.DebugLevel,
})
errCheck := func(err error) bool {
sqlErr, ok := err.(sqlite3.Error)
if !ok {
return false
return sqlErr.ExtendedCode == sqlite3.ErrConstraintUnique
c := &conn{db, flavorSQLite3, logger, errCheck}
for _, want := range []int{len(migrations), 0} {
got, err := c.migrate()
if got != want {
t.Errorf("expected %d migrations, got %d", want, got)