@@ -314,35 +314,59 @@ func TestCreateGamePlayLog(t *testing.T) {
314314
315315 // 並列実行対応のため,テストケースごとにレコード単位で削除
316316 t .Cleanup (func () {
317+ var playLogIDs []uuid.UUID
317318 if testCase .playLog != nil {
318- db .Session (& gorm.Session {}).Unscoped ().
319- Where ("id = ?" , uuid .UUID (testCase .playLog .GetID ())).
320- Delete (& schema.GamePlayLogTable {})
319+ playLogIDs = append (playLogIDs , uuid .UUID (testCase .playLog .GetID ()))
321320 }
322321 for _ , log := range testCase .beforeGamePlayLogs {
322+ playLogIDs = append (playLogIDs , log .ID )
323+ }
324+
325+ var versionIDs , imageIDs , videoIDs []uuid.UUID
326+ for _ , version := range testCase .gameVersions {
327+ versionIDs = append (versionIDs , version .ID )
328+ imageIDs = append (imageIDs , version .GameImageID )
329+ videoIDs = append (videoIDs , version .GameVideoID )
330+ }
331+
332+ var gameIDs []uuid.UUID
333+ for _ , game := range testCase .games {
334+ gameIDs = append (gameIDs , game .ID )
335+ }
336+
337+ var editionIDs []uuid.UUID
338+ for _ , edition := range testCase .editions {
339+ editionIDs = append (editionIDs , edition .ID )
340+ }
341+
342+ if len (playLogIDs ) > 0 {
323343 db .Session (& gorm.Session {}).Unscoped ().
324- Where ("id = ?" , log . ID ).
344+ Where ("id IN ?" , playLogIDs ).
325345 Delete (& schema.GamePlayLogTable {})
326346 }
327- for _ , version := range testCase . gameVersions {
347+ if len ( versionIDs ) > 0 {
328348 db .Session (& gorm.Session {}).Unscoped ().
329- Where ("id = ?" , version . ID ).
349+ Where ("id IN ?" , versionIDs ).
330350 Delete (& schema.GameVersionTable2 {})
351+ }
352+ if len (imageIDs ) > 0 {
331353 db .Session (& gorm.Session {}).Unscoped ().
332- Where ("id = ?" , version . GameImageID ).
354+ Where ("id IN ?" , imageIDs ).
333355 Delete (& schema.GameImageTable2 {})
356+ }
357+ if len (videoIDs ) > 0 {
334358 db .Session (& gorm.Session {}).Unscoped ().
335- Where ("id = ?" , version . GameVideoID ).
359+ Where ("id IN ?" , videoIDs ).
336360 Delete (& schema.GameVideoTable2 {})
337361 }
338- for _ , game := range testCase . games {
362+ if len ( gameIDs ) > 0 {
339363 db .Session (& gorm.Session {}).Unscoped ().
340- Where ("id = ?" , game . ID ).
364+ Where ("id IN ?" , gameIDs ).
341365 Delete (& schema.GameTable2 {})
342366 }
343- for _ , edition := range testCase . editions {
367+ if len ( editionIDs ) > 0 {
344368 db .Session (& gorm.Session {}).Unscoped ().
345- Where ("id = ?" , edition . ID ).
369+ Where ("id IN ?" , editionIDs ).
346370 Delete (& schema.EditionTable {})
347371 }
348372 })
@@ -366,30 +390,42 @@ func TestCreateGamePlayLog(t *testing.T) {
366390 }
367391
368392 if len (testCase .gameVersions ) != 0 {
393+ // Collect all images and videos for batch creation
394+ var images []schema.GameImageTable2
395+ var videos []schema.GameVideoTable2
396+
369397 for _ , version := range testCase .gameVersions {
370- image := schema.GameImageTable2 {
398+ images = append ( images , schema.GameImageTable2 {
371399 ID : version .GameImageID ,
372400 GameID : version .GameID ,
373401 ImageTypeID : gameImageType .ID ,
374402 CreatedAt : now ,
375- }
376- err := db .Session (& gorm.Session {}).Create (& image ).Error
377- if err != nil {
378- t .Fatalf ("create game image: %+v\n " , err )
379- }
380-
381- video := schema.GameVideoTable2 {
403+ })
404+ videos = append (videos , schema.GameVideoTable2 {
382405 ID : version .GameVideoID ,
383406 GameID : version .GameID ,
384407 VideoTypeID : gameVideoType .ID ,
385408 CreatedAt : now ,
409+ })
410+ }
411+
412+ // Batch create images
413+ if len (images ) > 0 {
414+ err := db .Session (& gorm.Session {}).Create (& images ).Error
415+ if err != nil {
416+ t .Fatalf ("create game images: %+v\n " , err )
386417 }
387- err = db .Session (& gorm.Session {}).Create (& video ).Error
418+ }
419+
420+ // Batch create videos
421+ if len (videos ) > 0 {
422+ err := db .Session (& gorm.Session {}).Create (& videos ).Error
388423 if err != nil {
389- t .Fatalf ("create game video : %+v\n " , err )
424+ t .Fatalf ("create game videos : %+v\n " , err )
390425 }
391426 }
392427
428+ // Create versions
393429 err := db .
394430 Session (& gorm.Session {}).
395431 Create (& testCase .gameVersions ).Error
0 commit comments