forked from gruntwork-io/terragrunt
-
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.
Get interleaved output by using goroutines and waitgroups.
Add unit test to verify the behavior.
- Loading branch information
Showing
3 changed files
with
68 additions
and
12 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,37 @@ | ||
// +build linux darwin | ||
|
||
package shell | ||
|
||
import ( | ||
"bufio" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/gruntwork-io/terragrunt/options" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCommandOutputOrder(t *testing.T) { | ||
t.Parallel() | ||
|
||
terragruntOptions, err := options.NewTerragruntOptionsForTest("") | ||
assert.Nil(t, err, "Unexpected error creating NewTerragruntOptionsForTest: %v", err) | ||
terragruntOptions.TerraformCliArgs = append(terragruntOptions.TerraformCliArgs, "same") | ||
out, err := RunShellCommandWithOutput(terragruntOptions, "../testdata/test_outputs.sh", "same") | ||
|
||
assert.NotNil(t, out, "Should get output") | ||
assert.Nil(t, err, "Should have no error") | ||
|
||
scanner := bufio.NewScanner(strings.NewReader(out)) | ||
var outputs = []string{} | ||
for scanner.Scan() { | ||
outputs = append(outputs, scanner.Text()) | ||
} | ||
|
||
assert.True(t, len(outputs) == 5, "Should have 5 entries") | ||
assert.Equal(t, "stdout1", outputs[0], "First one from stdout") | ||
assert.Equal(t, "stderr1", outputs[1], "First one from stderr") | ||
assert.Equal(t, "stdout2", outputs[2], "Second one from stdout") | ||
assert.Equal(t, "stderr2", outputs[3], "Second one from stderr") | ||
assert.Equal(t, "stderr3", outputs[4], "Third one from stderr") | ||
} |
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,10 @@ | ||
#!/bin/sh | ||
echo 'stdout1' | ||
sleep 1 | ||
>&2 echo 'stderr1' | ||
sleep 1 | ||
echo 'stdout2' | ||
sleep 1 | ||
>&2 echo 'stderr2' | ||
sleep 1 | ||
>&2 echo 'stderr3' |