MCPcopy Create free account
hub / github.com/docker/docker-agent / TestBackupDatabase

Function TestBackupDatabase

pkg/session/store_test.go:731–780  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

729}
730
731func 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

Callers

nothing calls this directly

Calls 2

backupDatabaseFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected