progress: tweak progress error reporting
This commit adds catpure of os.Std{out,err} when running osbuild so
that we capture the error log and can display it as part of
an error from osbuild, e.g. when osbuild itself crashes.
This gives us more accurate error reporting if anything fails
during the osbuild building.
This commit is contained in:
parent
9ac654a7b1
commit
655b6bbd0f
3 changed files with 41 additions and 14 deletions
|
|
@ -3,6 +3,8 @@ package progress_test
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
|
|
@ -130,3 +132,27 @@ func TestProgressNewAutoselect(t *testing.T) {
|
|||
assert.Equal(t, reflect.TypeOf(pb), reflect.TypeOf(tc.expected), fmt.Sprintf("[%v] %T not the expected %T", tc.onTerm, pb, tc.expected))
|
||||
}
|
||||
}
|
||||
|
||||
func makeFakeOsbuild(t *testing.T, content string) string {
|
||||
p := filepath.Join(t.TempDir(), "fake-osbuild")
|
||||
err := os.WriteFile(p, []byte("#!/bin/sh\n"+content), 0755)
|
||||
assert.NoError(t, err)
|
||||
return p
|
||||
}
|
||||
|
||||
func TestRunOSBuildWithProgress(t *testing.T) {
|
||||
restore := progress.MockOsbuildCmd(makeFakeOsbuild(t, `echo osbuild-stdout-output
|
||||
>&2 echo osbuild-stderr-output
|
||||
exit 112
|
||||
`))
|
||||
defer restore()
|
||||
|
||||
pbar, err := progress.New("debug")
|
||||
assert.NoError(t, err)
|
||||
err = progress.RunOSBuild(pbar, []byte(`{"fake":"manifest"}`), "", "", nil, nil)
|
||||
assert.EqualError(t, err, `error running osbuild: exit status 112
|
||||
Output:
|
||||
osbuild-stdout-output
|
||||
osbuild-stderr-output
|
||||
`)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue