first commit
This commit is contained in:
32
internal/db/db_test.go
Normal file
32
internal/db/db_test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOpenAndMigrate(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "test.db")
|
||||
d, err := Open(path)
|
||||
if err != nil {
|
||||
t.Fatalf("open: %v", err)
|
||||
}
|
||||
defer d.Close()
|
||||
|
||||
if err := d.Migrate(context.Background()); err != nil {
|
||||
t.Fatalf("migrate: %v", err)
|
||||
}
|
||||
// Idempotent.
|
||||
if err := d.Migrate(context.Background()); err != nil {
|
||||
t.Fatalf("migrate twice: %v", err)
|
||||
}
|
||||
row := d.QueryRow(`SELECT COUNT(*) FROM schema_migrations`)
|
||||
var n int
|
||||
if err := row.Scan(&n); err != nil {
|
||||
t.Fatalf("scan: %v", err)
|
||||
}
|
||||
if n < 1 {
|
||||
t.Fatalf("expected migrations applied, got %d", n)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user