|
| 1 | +package main |
| 2 | + |
| 3 | +import "testing" |
| 4 | + |
| 5 | +// Unit tests for rmcmd and mkdircmd |
| 6 | +func TestCommands(t *testing.T) { |
| 7 | + // Test rmcmd on Windows |
| 8 | + os1 := "windows" |
| 9 | + target1 := "C:\\path\\to\\file" |
| 10 | + expected1 := "DEL /F /S " + target1 |
| 11 | + actual1 := rmcmd(os1, target1) |
| 12 | + if actual1 != expected1 { |
| 13 | + t.Errorf("rmcmd(%s, %s) = %s; expected %s", os1, target1, actual1, expected1) |
| 14 | + } |
| 15 | + |
| 16 | + // Test rmcmd on Unix-based system |
| 17 | + os2 := "unix" |
| 18 | + target2 := "/path/to/folder" |
| 19 | + expected2 := "rm -rf " + target2 |
| 20 | + actual2 := rmcmd(os2, target2) |
| 21 | + if actual2 != expected2 { |
| 22 | + t.Errorf("rmcmd(%s, %s) = %s; expected %s", os2, target2, actual2, expected2) |
| 23 | + } |
| 24 | + |
| 25 | + // Test mkdircmd on Windows |
| 26 | + os3 := "windows" |
| 27 | + target3 := "C:\\path\\to\\folder" |
| 28 | + expected3 := "if not exist " + target3 + " mkdir " + target3 |
| 29 | + actual3 := mkdircmd(os3, target3) |
| 30 | + if actual3 != expected3 { |
| 31 | + t.Errorf("mkdircmd(%s, %s) = %s; expected %s", os3, target3, actual3, expected3) |
| 32 | + } |
| 33 | + |
| 34 | + // Test mkdircmd on Unix-based system |
| 35 | + os4 := "unix" |
| 36 | + target4 := "/path/to/folder" |
| 37 | + expected4 := "mkdir -p " + target4 |
| 38 | + actual4 := mkdircmd(os4, target4) |
| 39 | + if actual4 != expected4 { |
| 40 | + t.Errorf("mkdircmd(%s, %s) = %s; expected %s", os4, target4, actual4, expected4) |
| 41 | + } |
| 42 | +} |
0 commit comments