(t *testing.T)
| 729 | } |
| 730 | |
| 731 | func TestBackupDatabase(t *testing.T) { |
| 732 | t.Parallel() |
| 733 | |
| 734 | t.Run("backs up existing database file", func(t *testing.T) { |
| 735 | tempDir := t.TempDir() |
| 736 | dbPath := filepath.Join(tempDir, "test.db") |
| 737 | backupPath := dbPath + ".bak" |
| 738 | |
| 739 | // Create a file to backup |
| 740 | err := os.WriteFile(dbPath, []byte("test content"), 0o644) |
| 741 | require.NoError(t, err) |
| 742 | |
| 743 | // Also create WAL and SHM files |
| 744 | err = os.WriteFile(dbPath+"-wal", []byte("wal content"), 0o644) |
| 745 | require.NoError(t, err) |
| 746 | err = os.WriteFile(dbPath+"-shm", []byte("shm content"), 0o644) |
| 747 | require.NoError(t, err) |
| 748 | |
| 749 | // Backup the database |
| 750 | err = backupDatabase(dbPath) |
| 751 | require.NoError(t, err) |
| 752 | |
| 753 | // Original should be gone |
| 754 | _, err = os.Stat(dbPath) |
| 755 | assert.True(t, os.IsNotExist(err), "original file should be moved") |
| 756 | |
| 757 | // WAL and SHM should also be gone |
| 758 | _, err = os.Stat(dbPath + "-wal") |
| 759 | assert.True(t, os.IsNotExist(err), "WAL file should be moved") |
| 760 | _, err = os.Stat(dbPath + "-shm") |
| 761 | assert.True(t, os.IsNotExist(err), "SHM file should be moved") |
| 762 | |
| 763 | // Check backup files exist |
| 764 | _, err = os.Stat(backupPath) |
| 765 | require.NoError(t, err, "main backup should exist") |
| 766 | _, err = os.Stat(backupPath + "-wal") |
| 767 | require.NoError(t, err, "WAL backup should exist") |
| 768 | _, err = os.Stat(backupPath + "-shm") |
| 769 | require.NoError(t, err, "SHM backup should exist") |
| 770 | }) |
| 771 | |
| 772 | t.Run("handles nonexistent file gracefully", func(t *testing.T) { |
| 773 | tempDir := t.TempDir() |
| 774 | dbPath := filepath.Join(tempDir, "nonexistent.db") |
| 775 | |
| 776 | // Backup should succeed (nothing to backup) |
| 777 | err := backupDatabase(dbPath) |
| 778 | require.NoError(t, err) |
| 779 | }) |
| 780 | } |
| 781 | |
| 782 | // TestOrphanedSubsessionReference verifies that loading sessions gracefully |
| 783 | // handles orphaned subsession references (where the subsession was deleted |
nothing calls this directly
no test coverage detected