fix: closing stdout

pack client was closing stdout
this commit prevents that

Signed-off-by: Matej Vasek <mvasek@redhat.com>
This commit is contained in:
Matej Vasek 2021-06-24 14:30:01 +02:00 committed by GitHub
parent e7b0c375d4
commit 6f40b29d3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -95,7 +95,9 @@ func (builder *Builder) Build(ctx context.Context, f fn.Function) (err error) {
// log output is either STDOUt or kept in a buffer to be printed on error.
var logWriter io.Writer
if builder.Verbose {
logWriter = os.Stdout
// pass stdout as non-closeable writer
// otherwise pack client would close it which is bad
logWriter = stdoutWrapper{os.Stdout}
} else {
logWriter = &bytes.Buffer{}
}
@ -129,6 +131,15 @@ func (builder *Builder) Build(ctx context.Context, f fn.Function) (err error) {
return
}
// hack this makes stdout non-closeable
type stdoutWrapper struct {
impl io.Writer
}
func (s stdoutWrapper) Write(p []byte) (n int, err error) {
return s.impl.Write(p)
}
type clientWrapper struct {
impl dockerClient.CommonAPIClient
}

View File

@ -153,8 +153,6 @@ func TestRemove(t *testing.T) {
// newClient creates an instance of the func client whose concrete impls
// match those created by the kn func plugin CLI.
func newClient(verbose bool) *boson.Client {
// TODO: Forcing verbose to false in order to pass integration tests
verbose = false
builder := buildpacks.NewBuilder()
builder.Verbose = verbose