优化申诉仲裁流程和证据展示

This commit is contained in:
yml2213
2026-06-13 21:26:38 +08:00
parent 529ad1e433
commit 3ef7705776
22 changed files with 1455 additions and 138 deletions
+24 -8
View File
@@ -281,7 +281,7 @@ func openE2EDB(t *testing.T) *gorm.DB {
t.Fatalf("连接测试库失败: %v", err)
}
t.Cleanup(func() { _ = sqlDB.Close() })
applyInitMigration(t, sqlDB)
applyMigrations(t, sqlDB)
gormDB, err := gorm.Open(mysql.New(mysql.Config{Conn: sqlDB}), &gorm.Config{
Logger: logger.Default.LogMode(logger.Silent),
@@ -306,20 +306,36 @@ func assertSafeTestDBName(t *testing.T, dbName string) {
}
}
func applyInitMigration(t *testing.T, db *sql.DB) {
func applyMigrations(t *testing.T, db *sql.DB) {
t.Helper()
_, currentFile, _, ok := runtime.Caller(0)
if !ok {
t.Fatal("无法定位当前测试文件")
}
migrationPath := filepath.Join(filepath.Dir(currentFile), "..", "..", "migrations", "000001_init.sql")
raw, err := os.ReadFile(migrationPath)
if err != nil {
t.Fatalf("读取初始化迁移失败: %v", err)
migrationDir := filepath.Join(filepath.Dir(currentFile), "..", "..", "migrations")
for _, name := range []string{"000001_init.sql", "000002_dispute_cancel_snapshot.sql"} {
migrationPath := filepath.Join(migrationDir, name)
raw, err := os.ReadFile(migrationPath)
if err != nil {
t.Fatalf("读取迁移 %s 失败: %v", name, err)
}
sqlText := gooseUpSQL(string(raw))
if _, err := db.Exec(sqlText); err != nil {
t.Fatalf("执行迁移 %s 失败: %v", name, err)
}
}
if _, err := db.Exec(string(raw)); err != nil {
t.Fatalf("执行初始化迁移失败: %v", err)
}
func gooseUpSQL(raw string) string {
upIndex := strings.Index(raw, "-- +goose Up")
if upIndex >= 0 {
raw = raw[upIndex+len("-- +goose Up"):]
}
downIndex := strings.Index(raw, "-- +goose Down")
if downIndex >= 0 {
raw = raw[:downIndex]
}
return raw
}
func seedUsers(t *testing.T, db *gorm.DB) (model.User, model.User, uint64) {