fix(report): close the file (#4842)

* fix(report): close the file

* refactor: add the format type

* fix: return errors in version printing

* fix: lint issues

* fix: do not fail on bogus cache dir

---------

Co-authored-by: DmitriyLewen <dmitriy.lewen@smartforce.io>
This commit is contained in:
Teppei Fukuda
2023-07-23 16:37:18 +03:00
committed by GitHub
parent 24a3e547d9
commit 20c2246a61
38 changed files with 352 additions and 362 deletions

View File

@@ -1,7 +1,6 @@
package commands
import (
"bytes"
"context"
"os"
"path/filepath"
@@ -1243,8 +1242,8 @@ Summary Report for compliance: my-custom-spec
}()
}
buffer := new(bytes.Buffer)
test.options.Output = buffer
output := filepath.Join(t.TempDir(), "output")
test.options.Output = output
test.options.Debug = true
test.options.GlobalOptions.Timeout = time.Minute
if test.options.Format == "" {
@@ -1283,10 +1282,13 @@ Summary Report for compliance: my-custom-spec
err := Run(context.Background(), test.options)
if test.expectErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
assert.Equal(t, test.want, buffer.String())
return
}
assert.NoError(t, err)
b, err := os.ReadFile(output)
require.NoError(t, err)
assert.Equal(t, test.want, string(b))
})
}
}