From 3deb24e5de6369263fa8e353a16e934baf6a412a Mon Sep 17 00:00:00 2001 From: Peng Tao Date: Wed, 25 Dec 2019 00:46:01 -0800 Subject: [PATCH] cli: flush coverage report in defer function Do not flush it atexit(), where the test report file might be already closed and it causes go test failure like: PASS testing: can't write /tmp/go-build146132196/b001/testlog.txt: close /tmp/go-build146132196/b001/testlog.txt: file already closed FAIL github.com/kata-containers/runtime/cli 4.256s Signed-off-by: Peng Tao --- cli/main_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cli/main_test.go b/cli/main_test.go index bcb613a7be..796d426479 100644 --- a/cli/main_test.go +++ b/cli/main_test.go @@ -160,7 +160,9 @@ func TestMain(m *testing.M) { // Make sure we have the opportunity to flush the coverage report to disk when // terminating the process. - atexit(cover.FlushProfiles) + defer func() { + cover.FlushProfiles() + }() // If the test binary name is kata-runtime.coverage, we've are being asked to // run the coverage-instrumented kata-runtime.