-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The getContainerSize() was not using some of the modern go helpers. So let's use `exec.Command().Output()` and introduce a new `util.OutputErr()` helper that will be able to also show stderr to the user if the Output() call returns an error.
- Loading branch information
1 parent
c102e26
commit 2eef394
Showing
3 changed files
with
41 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
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,21 @@ | ||
package util_test | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/osbuild/bootc-image-builder/bib/internal/util" | ||
) | ||
|
||
func TestOutputErrPassthrough(t *testing.T) { | ||
err := fmt.Errorf("boom") | ||
assert.Equal(t, util.OutputErr(err), err) | ||
} | ||
|
||
func TestOutputErrExecError(t *testing.T) { | ||
_, err := exec.Command("bash", "-c", ">&2 echo some-stderr; exit 1").Output() | ||
assert.Equal(t, "exit status 1, stderr:\nsome-stderr\n", util.OutputErr(err).Error()) | ||
} |