From 1cca30c5321b05f2803d4e06108655e7dae616f6 Mon Sep 17 00:00:00 2001 From: Tiwei Bie Date: Fri, 3 Nov 2023 12:40:45 +0800 Subject: [PATCH] runsc/container_test: fix executeCombinedOutput's output When ws is not zero (i.e. the app in container exited with a non-zero status), executeCombinedOutput should still read and return app's output, because it may contain the contents that app sent to stdout/stderr which can be helpful for diagnosing the failures. Signed-off-by: Tiwei Bie --- runsc/container/container_test.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/runsc/container/container_test.go b/runsc/container/container_test.go index 4aa46d8b2..7b4bbae75 100644 --- a/runsc/container/container_test.go +++ b/runsc/container/container_test.go @@ -98,11 +98,13 @@ func executeCombinedOutput(conf *config.Config, cont *Container, execFile *os.Fi if err != nil { return nil, err } - if ws != 0 { - return nil, fmt.Errorf("exec failed, status: %v", ws) - } - out, err := ioutil.ReadAll(r) + switch { + case ws != 0 && err != nil: + err = fmt.Errorf("exec failed, status: %v, ioutil.ReadAll failed: %v", ws, err) + case ws != 0: + err = fmt.Errorf("exec failed, status: %v", ws) + } return out, err }