-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
998cb54
commit 36ddbe9
Showing
2 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package shell_test | ||
|
||
import ( | ||
"bytes" | ||
"fmsh/commands" | ||
"io" | ||
"os" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestHandleFind(t *testing.T) { | ||
// Redirect output for testing | ||
var output bytes.Buffer | ||
originalStdout := os.Stdout | ||
defer func() { os.Stdout = originalStdout }() | ||
|
||
// Create a pipe to capture output | ||
r, w, err := os.Pipe() | ||
if err != nil { | ||
t.Fatalf("Failed to create pipe: %v", err) | ||
} | ||
|
||
os.Stdout = w | ||
|
||
// Capture the output in a separate goroutine | ||
done := make(chan error) | ||
go func() { | ||
_, err := io.Copy(&output, r) | ||
r.Close() // Close the read end after copying | ||
done <- err | ||
}() | ||
|
||
// Perform the action to test | ||
args := []string{"./test_directory", "file.txt"} | ||
commands.HandleFind(args) | ||
|
||
// Close the write end of the pipe | ||
w.Close() | ||
|
||
// Wait for the output capture to finish | ||
if err := <-done; err != nil { | ||
t.Fatalf("Failed to copy output: %v", err) | ||
} | ||
|
||
// Validate the captured output | ||
result := output.String() | ||
if !strings.Contains(result, "file.txt") { | ||
t.Errorf("Expected 'file.txt' in output, but got: %s", result) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package fmsh_test | ||
package shell_test | ||
|
||
import ( | ||
"fmsh/commands" | ||
|