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 <bergwolf@hyper.sh>
This commit is contained in:
Peng Tao 2019-12-25 00:46:01 -08:00
parent f56d70ccd6
commit 3deb24e5de

View File

@ -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.