HH-442: isolate runtime processes and harden shutdown (#90)
* HH-442: isolate runtime processes and harden shutdown * HH-442: harden worker shutdown races * HH-442: gate dependency shutdown on active handlers --------- Co-authored-by: Rogee <rogee@ipao.vip>
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func TestMigrationCommandsRejectBlankPath(t *testing.T) {
|
||||
@@ -56,3 +60,23 @@ func TestSanitizePostgresEnvironment(t *testing.T) {
|
||||
require.False(t, exists, "%s should be removed at application startup", key)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLatestVersionAndCheckVersion(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "000001_first.up.sql"), []byte("SELECT 1;"), 0o600))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "000012_latest.up.sql"), []byte("SELECT 1;"), 0o600))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "README"), nil, 0o600))
|
||||
|
||||
latest, err := LatestVersion(dir)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, uint(12), latest)
|
||||
|
||||
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.Exec("CREATE TABLE schema_migrations (version INTEGER NOT NULL, dirty BOOLEAN NOT NULL)").Error)
|
||||
require.NoError(t, db.Exec("INSERT INTO schema_migrations(version, dirty) VALUES (12, false)").Error)
|
||||
require.NoError(t, CheckVersion(context.Background(), db, latest))
|
||||
require.Error(t, CheckVersion(context.Background(), db, 13))
|
||||
require.NoError(t, db.Exec("UPDATE schema_migrations SET dirty = true").Error)
|
||||
require.ErrorContains(t, CheckVersion(context.Background(), db, latest), "dirty")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user