33 lines
508 B
Go
33 lines
508 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"database/sql"
|
||
|
"testing"
|
||
|
|
||
|
_ "github.com/mattn/go-sqlite3"
|
||
|
)
|
||
|
|
||
|
func TestMigrations(t *testing.T) {
|
||
|
db, err := sql.Open("sqlite3", ":memory:")
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
defer db.Close()
|
||
|
|
||
|
err = InitDatabase(db)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
err = MigrateDatabase(db)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
var count int
|
||
|
row := db.QueryRow("select count(name) from migrations")
|
||
|
row.Scan(&count)
|
||
|
if count != 1 {
|
||
|
t.Fatalf("Unexpected migration count: %d", count)
|
||
|
}
|
||
|
}
|