-
Notifications
You must be signed in to change notification settings - Fork 41
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
Showing
10 changed files
with
354 additions
and
216 deletions.
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
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
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
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,45 @@ | ||
package client | ||
|
||
import ( | ||
"io" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestReadStdPipeWithLongString(t *testing.T) { | ||
// Create a string with a million characters ('a'). | ||
longString := strings.Repeat("a", 1000000) | ||
|
||
// Use an io.Pipe to simulate the stdout or stderr pipe. | ||
reader, writer := io.Pipe() | ||
|
||
// Channel to communicate errors from the writing goroutine. | ||
errChan := make(chan error, 1) | ||
|
||
// Write the long string to the pipe in a goroutine. | ||
go func() { | ||
_, err := writer.Write([]byte(longString)) | ||
if err != nil { | ||
// Send any errors to the main test goroutine via the channel. | ||
errChan <- err | ||
} | ||
writer.Close() | ||
errChan <- nil // Send nil to indicate successful write. | ||
}() | ||
|
||
// Variable to store the output from the readStdPipe function. | ||
var output string | ||
outputFunction := func(s string) { | ||
output = s | ||
} | ||
|
||
// Call the readStdPipe function with the reader part of the pipe. | ||
readStdPipe(reader, outputFunction) | ||
|
||
// Check for errors from the write goroutine. | ||
err := <-errChan | ||
require.NoError(t, err, "Failed to write to pipe") | ||
require.Equal(t, longString, output, "Output did not match the input long string") | ||
} |
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
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
Oops, something went wrong.