-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix (test/extended/util) : shell doesn't parse command output ending …
…without newline (#4416) ScanPipe should not assume entire line to contain only the exit code token. It should extract exit code token and write remainder output to output buffer. Signed-off-by: Rohan Kumar <[email protected]>
- Loading branch information
1 parent
9b7772d
commit fa728a4
Showing
2 changed files
with
52 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package util | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var testArguments = map[string]struct { | ||
commandOutput string | ||
expectedParsedOutput string | ||
expectedParsedExitCode string | ||
}{ | ||
"When command output line contains additional output along with exit code, then parse output and exit code": { | ||
"remainderOutputexitCodeOfLastCommandInShell=0", "remainderOutput\n", "0", | ||
}, | ||
"When command output line contains only exit code, then parse exit code": { | ||
"exitCodeOfLastCommandInShell=1", "", "1", | ||
}, | ||
} | ||
|
||
func TestScanPipeShouldCorrectlyParseOutputNotEndingWithNewLine(t *testing.T) { | ||
for name, test := range testArguments { | ||
t.Run(name, func(t *testing.T) { | ||
// Given | ||
shell.ConfigureTypeOfShell("bash") | ||
shell.exitCodeChannel = make(chan string, 2) | ||
scanner := bufio.NewScanner(strings.NewReader(test.commandOutput)) | ||
b := &bytes.Buffer{} | ||
// When | ||
shell.ScanPipe(scanner, b, "stdout") | ||
// Then | ||
assert.Equal(t, test.expectedParsedOutput, b.String()) | ||
assert.Equal(t, test.expectedParsedExitCode, <-shell.exitCodeChannel) | ||
}) | ||
} | ||
} |