mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-14 02:52:42 +00:00
42 lines
866 B
Go
42 lines
866 B
Go
package database
|
|
|
|
import (
|
|
"embed"
|
|
"testing"
|
|
)
|
|
|
|
var (
|
|
//go:embed testdata/migration1/**
|
|
testMigration1 embed.FS
|
|
//go:embed testdata/migration2/**
|
|
testMigration2 embed.FS
|
|
)
|
|
|
|
func TestMigration(t *testing.T) {
|
|
dbc, err := New("sqlite", ":memory:", testEncryptionPass)
|
|
if err != nil {
|
|
t.Fatalf("creating database connector: %s", err)
|
|
}
|
|
defer dbc.Close()
|
|
|
|
var (
|
|
tm1 = NewEmbedFSMigrator(testMigration1, "testdata")
|
|
tm2 = NewEmbedFSMigrator(testMigration2, "testdata")
|
|
)
|
|
|
|
if err = dbc.Migrate("test", tm1); err != nil {
|
|
t.Errorf("migration 1 take 1: %s", err)
|
|
}
|
|
|
|
if err = dbc.Migrate("test", tm1); err != nil {
|
|
t.Errorf("migration 1 take 2: %s", err)
|
|
}
|
|
|
|
if err = dbc.Migrate("test", tm2); err != nil {
|
|
t.Errorf("migration 2 take 1: %s", err)
|
|
}
|
|
|
|
if err = dbc.Migrate("test", tm2); err != nil {
|
|
t.Errorf("migration 2 take 2: %s", err)
|
|
}
|
|
}
|