mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-23 15:37:50 -08:00
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:
@@ -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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user