Add a dry run flag

This commit is contained in:
2025-11-20 15:29:27 +01:00
parent 079fc82ab9
commit 1eda2fcc82
4 changed files with 262 additions and 12 deletions

View File

@@ -394,6 +394,35 @@ func TestLinkInstruction_RunAsync(t *testing.T) {
assert.Contains(t, err.Error(), "files=true")
assert.True(t, FileExists(targetDir))
})
t.Run("Dry run does not modify filesystem", func(t *testing.T) {
originalFS := filesystem
filesystem = NewDryRunFileSystem()
defer func() {
filesystem = originalFS
}()
target := filepath.Join(testDir, "dryrun-link.txt")
instruction := LinkInstruction{
Source: srcFile,
Target: target,
Force: true,
Delete: true,
}
status := make(chan error)
go instruction.RunAsync(status)
err := <-status
assert.NoError(t, err)
assert.False(t, FileExists(target))
summary := filesystem.SummaryLines()
assert.Equal(t, 1, len(summary))
assert.Contains(t, summary[0], "DRY-RUN")
assert.Contains(t, summary[0], srcFile)
assert.Contains(t, summary[0], target)
})
}
func TestLinkInstruction_Undo(t *testing.T) {