Refactor snapshot parent updates: replace full metadata reload with UpdateSnapshotParentID method, enhance functional test logging, and add CleanOnRestore option.
This commit is contained in:
@ -20,7 +20,8 @@ func TestFullWorkflow(t *testing.T) {
|
||||
|
||||
// Create Agate options
|
||||
options := AgateOptions{
|
||||
WorkDir: tempDir,
|
||||
WorkDir: tempDir,
|
||||
CleanOnRestore: true,
|
||||
}
|
||||
|
||||
// Create Agate instance
|
||||
@ -123,12 +124,20 @@ func TestFullWorkflow(t *testing.T) {
|
||||
}
|
||||
if string(content) != expectedContent {
|
||||
t.Errorf("Restored file %s has wrong content: got %s, want %s", path, string(content), expectedContent)
|
||||
} else {
|
||||
t.Logf("SUCCESS: Restored file %s has correct content after restoring first snapshot", path)
|
||||
}
|
||||
}
|
||||
|
||||
// Check that file4.txt doesn't exist
|
||||
if _, err := os.Stat(filepath.Join(dataDir, "file4.txt")); !os.IsNotExist(err) {
|
||||
file4Path := filepath.Join(dataDir, "file4.txt")
|
||||
_, err = os.Stat(file4Path)
|
||||
if err == nil {
|
||||
t.Errorf("File4.txt should not exist after restoring first snapshot")
|
||||
} else if !os.IsNotExist(err) {
|
||||
t.Errorf("Unexpected error checking if File4.txt exists: %v", err)
|
||||
} else {
|
||||
t.Logf("SUCCESS: File4.txt correctly does not exist after restoring first snapshot")
|
||||
}
|
||||
|
||||
// Step 9: Restore the third snapshot
|
||||
@ -152,12 +161,20 @@ func TestFullWorkflow(t *testing.T) {
|
||||
}
|
||||
if string(content) != expectedContent {
|
||||
t.Errorf("Restored file %s has wrong content: got %s, want %s", path, string(content), expectedContent)
|
||||
} else {
|
||||
t.Logf("SUCCESS: Restored file %s has correct content after restoring third snapshot", path)
|
||||
}
|
||||
}
|
||||
|
||||
// Check that file2.txt doesn't exist
|
||||
if _, err := os.Stat(filepath.Join(dataDir, "file2.txt")); !os.IsNotExist(err) {
|
||||
file2Path := filepath.Join(dataDir, "file2.txt")
|
||||
_, err = os.Stat(file2Path)
|
||||
if err == nil {
|
||||
t.Errorf("File2.txt should not exist after restoring third snapshot")
|
||||
} else if !os.IsNotExist(err) {
|
||||
t.Errorf("Unexpected error checking if File2.txt exists: %v", err)
|
||||
} else {
|
||||
t.Logf("SUCCESS: File2.txt correctly does not exist after restoring third snapshot")
|
||||
}
|
||||
|
||||
// Step 11: Delete a snapshot
|
||||
@ -190,17 +207,26 @@ func TestFullWorkflow(t *testing.T) {
|
||||
// Verify that snapshot 3's parent ID has been updated to point to snapshot 1
|
||||
if snapshot3 != nil && snapshot3.ParentID != snapshot1ID {
|
||||
t.Errorf("Snapshot 3's parent ID should be updated to point to Snapshot 1 after Snapshot 2 is deleted. Got ParentID=%s, want ParentID=%s", snapshot3.ParentID, snapshot1ID)
|
||||
} else {
|
||||
t.Logf("SUCCESS: Snapshot 3's parent ID has been correctly updated to point to Snapshot 1: %s", snapshot3.ParentID)
|
||||
}
|
||||
|
||||
if len(snapshots) != 2 {
|
||||
t.Errorf("Expected 2 snapshots after deletion, got %d", len(snapshots))
|
||||
} else {
|
||||
t.Logf("SUCCESS: Found correct number of snapshots after deletion: %d", len(snapshots))
|
||||
}
|
||||
|
||||
foundDeletedSnapshot := false
|
||||
for _, snap := range snapshots {
|
||||
if snap.ID == snapshot2ID {
|
||||
foundDeletedSnapshot = true
|
||||
t.Errorf("Snapshot 2 (ID=%s) should have been deleted", snapshot2ID)
|
||||
}
|
||||
}
|
||||
if !foundDeletedSnapshot {
|
||||
t.Logf("SUCCESS: Snapshot 2 (ID=%s) was correctly deleted", snapshot2ID)
|
||||
}
|
||||
}
|
||||
|
||||
// TestLargeFiles tests creating and restoring snapshots with large files
|
||||
@ -219,7 +245,8 @@ func TestLargeFiles(t *testing.T) {
|
||||
|
||||
// Create Agate options
|
||||
options := AgateOptions{
|
||||
WorkDir: tempDir,
|
||||
WorkDir: tempDir,
|
||||
CleanOnRestore: true,
|
||||
OpenFunc: func(dir string) error {
|
||||
return nil
|
||||
},
|
||||
|
Reference in New Issue
Block a user