This commit is contained in:
@@ -28,7 +28,7 @@ func waitForSyncCompletion(t *testing.T, e *echo.Echo, maxAttempts int) bool {
|
||||
if err == nil && progress.Progress != "" {
|
||||
// Successfully parsed as ProgressResponse with non-empty progress
|
||||
t.Logf("Sync progress: %s%%", progress.Progress)
|
||||
if progress.Progress == "100" {
|
||||
if progress.Progress == "100" {
|
||||
t.Log("Sync completed!")
|
||||
// Wait for Syncing flag to be updated
|
||||
for j := 0; j < 50; j++ {
|
||||
@@ -61,7 +61,7 @@ func waitForSyncCompletion(t *testing.T, e *echo.Echo, maxAttempts int) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// TestSyncPopulatesDatabase verifies that sync populates the database with games
|
||||
// TestSyncPopulatesDatabase verifies that sync populates the database with soundtracks
|
||||
func TestSyncPopulatesDatabase(t *testing.T) {
|
||||
db.TestSetupDB(t)
|
||||
defer db.TestTearDownDB(t)
|
||||
@@ -74,12 +74,12 @@ func TestSyncPopulatesDatabase(t *testing.T) {
|
||||
// Clear any existing data first
|
||||
db.TestClearDatabase(t)
|
||||
|
||||
// Before sync - should have no games
|
||||
// Before sync - should have no soundtracks
|
||||
repo := repository.New(backend.BackendPool())
|
||||
gamesBefore, err := repo.FindAllSoundtracks(backend.BackendCtx())
|
||||
soundtracksBefore, err := repo.FindAllSoundtracks(backend.BackendCtx())
|
||||
assert.NoError(t, err)
|
||||
beforeCount := len(gamesBefore)
|
||||
t.Logf("Games before sync: %d", beforeCount)
|
||||
beforeCount := len(soundtracksBefore)
|
||||
t.Logf("Soundtracks before sync: %d", beforeCount)
|
||||
assert.Equal(t, 0, beforeCount, "Database should be empty after clear")
|
||||
|
||||
// Run sync
|
||||
@@ -91,14 +91,14 @@ func TestSyncPopulatesDatabase(t *testing.T) {
|
||||
t.Error("Sync did not complete within timeout")
|
||||
}
|
||||
|
||||
// After sync - should have games
|
||||
gamesAfter, err := repo.FindAllSoundtracks(backend.BackendCtx())
|
||||
// After sync - should have soundtracks
|
||||
soundtracksAfter, err := repo.FindAllSoundtracks(backend.BackendCtx())
|
||||
assert.NoError(t, err)
|
||||
afterCount := len(gamesAfter)
|
||||
t.Logf("Games after sync: %d", afterCount)
|
||||
afterCount := len(soundtracksAfter)
|
||||
t.Logf("Soundtracks after sync: %d", afterCount)
|
||||
|
||||
// Should have more games than before (unless database was already populated)
|
||||
assert.True(t, afterCount > 0, "Database should have games after sync")
|
||||
// Should have more soundtracks than before (unless database was already populated)
|
||||
assert.True(t, afterCount > 0, "Database should have soundtracks after sync")
|
||||
}
|
||||
|
||||
// TestSyncMakesDifference verifies that sync actually changes the database state
|
||||
@@ -111,11 +111,11 @@ func TestSyncMakesDifference(t *testing.T) {
|
||||
// Clear any existing data first
|
||||
db.TestClearDatabase(t)
|
||||
|
||||
// Before sync - should have no games
|
||||
// Before sync - should have no soundtracks
|
||||
repo := repository.New(backend.BackendPool())
|
||||
gamesBefore, err := repo.FindAllSoundtracks(backend.BackendCtx())
|
||||
soundtracksBefore, err := repo.FindAllSoundtracks(backend.BackendCtx())
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 0, len(gamesBefore), "Should have no games before sync")
|
||||
assert.Equal(t, 0, len(soundtracksBefore), "Should have no soundtracks before sync")
|
||||
|
||||
// Run sync
|
||||
resp := MakeTestRequest(t, e, "GET", "/sync/full")
|
||||
@@ -126,10 +126,10 @@ func TestSyncMakesDifference(t *testing.T) {
|
||||
t.Error("Sync did not complete within timeout")
|
||||
}
|
||||
|
||||
// After sync - should have games
|
||||
gamesAfter, err := repo.FindAllSoundtracks(backend.BackendCtx())
|
||||
// After sync - should have soundtracks
|
||||
soundtracksAfter, err := repo.FindAllSoundtracks(backend.BackendCtx())
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, len(gamesAfter) > 0, "Should have games after sync")
|
||||
assert.True(t, len(soundtracksAfter) > 0, "Should have soundtracks after sync")
|
||||
}
|
||||
|
||||
// TestSyncProgress verifies the sync progress endpoint
|
||||
@@ -183,8 +183,8 @@ func TestSyncProgress(t *testing.T) {
|
||||
assert.True(t, foundComplete, "Should have seen completion")
|
||||
}
|
||||
|
||||
// TestSyncGamesNewOnlyChanges verifies the incremental sync endpoint
|
||||
func TestSyncGamesNewOnlyChanges(t *testing.T) {
|
||||
// TestSyncSoundtracksNewOnlyChanges verifies the incremental sync endpoint
|
||||
func TestSyncSoundtracksNewOnlyChanges(t *testing.T) {
|
||||
db.TestSetupDB(t)
|
||||
defer db.TestTearDownDB(t)
|
||||
|
||||
@@ -200,8 +200,8 @@ func TestSyncGamesNewOnlyChanges(t *testing.T) {
|
||||
|
||||
// Get initial count
|
||||
repo := repository.New(backend.BackendPool())
|
||||
gamesBefore, _ := repo.FindAllSoundtracks(backend.BackendCtx())
|
||||
beforeCount := len(gamesBefore)
|
||||
soundtracksBefore, _ := repo.FindAllSoundtracks(backend.BackendCtx())
|
||||
beforeCount := len(soundtracksBefore)
|
||||
|
||||
// Run incremental sync (should not change count if nothing changed)
|
||||
resp := MakeTestRequest(t, e, "GET", "/sync/new")
|
||||
@@ -211,16 +211,16 @@ func TestSyncGamesNewOnlyChanges(t *testing.T) {
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
// Count should be the same
|
||||
gamesAfter, _ := repo.FindAllSoundtracks(backend.BackendCtx())
|
||||
afterCount := len(gamesAfter)
|
||||
soundtracksAfter, _ := repo.FindAllSoundtracks(backend.BackendCtx())
|
||||
afterCount := len(soundtracksAfter)
|
||||
|
||||
// Note: This might not be exactly equal due to timing, but should be close
|
||||
t.Logf("Games before incremental sync: %d, after: %d", beforeCount, afterCount)
|
||||
t.Logf("Soundtracks before incremental sync: %d, after: %d", beforeCount, afterCount)
|
||||
}
|
||||
|
||||
// TestResetGames verifies the reset endpoint clears the database
|
||||
// TestResetSoundtracks verifies the reset endpoint clears the database
|
||||
// RUN THIS LAST
|
||||
func TestResetGames(t *testing.T) {
|
||||
func TestResetSoundtracks(t *testing.T) {
|
||||
db.TestSetupDB(t)
|
||||
defer db.TestTearDownDB(t)
|
||||
|
||||
@@ -228,8 +228,8 @@ func TestResetGames(t *testing.T) {
|
||||
|
||||
// First ensure we have data
|
||||
repo := repository.New(backend.BackendPool())
|
||||
gamesBefore, _ := repo.FindAllSoundtracks(backend.BackendCtx())
|
||||
beforeCount := len(gamesBefore)
|
||||
soundtracksBefore, _ := repo.FindAllSoundtracks(backend.BackendCtx())
|
||||
beforeCount := len(soundtracksBefore)
|
||||
|
||||
if beforeCount == 0 {
|
||||
// Run sync to populate
|
||||
@@ -238,12 +238,12 @@ func TestResetGames(t *testing.T) {
|
||||
t.Error("Sync did not complete within timeout")
|
||||
return
|
||||
}
|
||||
gamesBefore, _ = repo.FindAllSoundtracks(backend.BackendCtx())
|
||||
beforeCount = len(gamesBefore)
|
||||
soundtracksBefore, _ = repo.FindAllSoundtracks(backend.BackendCtx())
|
||||
beforeCount = len(soundtracksBefore)
|
||||
}
|
||||
|
||||
t.Logf("Games before reset: %d", beforeCount)
|
||||
assert.True(t, beforeCount > 0, "Should have games to reset")
|
||||
t.Logf("Soundtracks before reset: %d", beforeCount)
|
||||
assert.True(t, beforeCount > 0, "Should have soundtracks to reset")
|
||||
|
||||
// Call reset
|
||||
resp := MakeTestRequest(t, e, "GET", "/sync/reset")
|
||||
@@ -253,16 +253,16 @@ func TestResetGames(t *testing.T) {
|
||||
// Note: reset might take a moment to propagate
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
gamesAfter, _ := repo.FindAllSoundtracks(backend.BackendCtx())
|
||||
afterCount := len(gamesAfter)
|
||||
soundtracksAfter, _ := repo.FindAllSoundtracks(backend.BackendCtx())
|
||||
afterCount := len(soundtracksAfter)
|
||||
|
||||
t.Logf("Games after reset: %d", afterCount)
|
||||
t.Logf("Soundtracks after reset: %d", afterCount)
|
||||
assert.Equal(t, 0, afterCount, "Database should be empty after reset")
|
||||
}
|
||||
|
||||
// TestSyncGamesNewFull verifies the full sync endpoint
|
||||
// RUN THIS LAST (before TestResetGames)
|
||||
func TestSyncGamesNewFull(t *testing.T) {
|
||||
// TestSyncSoundtracksNewFull verifies the full sync endpoint
|
||||
// RUN THIS LAST (before TestResetSoundtracks)
|
||||
func TestSyncSoundtracksNewFull(t *testing.T) {
|
||||
db.TestSetupDB(t)
|
||||
defer db.TestTearDownDB(t)
|
||||
|
||||
@@ -282,8 +282,8 @@ func TestSyncGamesNewFull(t *testing.T) {
|
||||
|
||||
// Verify database is populated
|
||||
repo := repository.New(backend.BackendPool())
|
||||
games, err := repo.FindAllSoundtracks(backend.BackendCtx())
|
||||
soundtracks, err := repo.FindAllSoundtracks(backend.BackendCtx())
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, len(games) > 0, "Database should be populated after full sync")
|
||||
t.Logf("Full sync populated %d games", len(games))
|
||||
assert.True(t, len(soundtracks) > 0, "Database should be populated after full sync")
|
||||
t.Logf("Full sync populated %d soundtracks", len(soundtracks))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user