fix anwser token and database issus
This commit is contained in:
@@ -12,8 +12,9 @@ import (
|
||||
)
|
||||
|
||||
func TestUploadImages(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// 注意:各子测试都创建 question_id=1 的上传图,cleanup 会 truncate 并 RESTART IDENTITY,
|
||||
// 并行子测试会拿到相同自增 id,撞 upload_image_questions 的复合主键
|
||||
// (upload_image_id, question_id);故顺序执行,使每个子测试独占全表。
|
||||
db, cleanup := newTestDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -29,7 +30,10 @@ func TestUploadImages(t *testing.T) {
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Cleanup(func() {
|
||||
if err := cleanup("upload_images"); err != nil {
|
||||
// 必须一并清链接表:upload_image_questions 无 FK 级联依赖 upload_images,
|
||||
// 仅 truncate upload_images 会残留 (upload_image_id, question_id) 链接行,
|
||||
// 下一个子测试因身份重启拿到相同 id 而撞复合主键。
|
||||
if err := cleanup("upload_images", "upload_image_questions"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user