mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
cleanup: address golangci 'errcheck' issues
Many reports are about closing or removing files. In some cases it is possible to report an error in the logs, in other cases the error can be ignored without potential issues. Test cases have been modified to not remove the temporary files. The temporary directory that is provided by the testing package, is removed once the tests are done. Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
committed by
mergify[bot]
parent
0a22e3a186
commit
bc8b1e792f
@ -36,13 +36,13 @@ func GzipLogFile(pathToFile string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer gf.Close() // #nosec:G307, error on close is not critical here
|
||||
defer gf.Close() //nolint:errcheck,nosec // G307, error on close is not critical here
|
||||
|
||||
// Write compressed data.
|
||||
w := gzip.NewWriter(gf)
|
||||
defer w.Close()
|
||||
defer w.Close() //nolint:errcheck // error on close is not critical here
|
||||
if _, err = w.Write(content); err != nil {
|
||||
os.Remove(newExt) // #nosec:G104, not important error to handle
|
||||
os.Remove(newExt) //nolint:errcheck,gosec // G104: not important error to handle
|
||||
|
||||
return err
|
||||
}
|
||||
|
@ -31,7 +31,6 @@ func TestGzipLogFile(t *testing.T) {
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
defer os.Remove(logFile.Name())
|
||||
|
||||
if err = GzipLogFile(logFile.Name()); err != nil {
|
||||
t.Errorf("GzipLogFile failed: %v", err)
|
||||
@ -41,6 +40,4 @@ func TestGzipLogFile(t *testing.T) {
|
||||
if _, err = os.Stat(newExt); errors.Is(err, os.ErrNotExist) {
|
||||
t.Errorf("compressed logFile (%s) not found: %v", newExt, err)
|
||||
}
|
||||
|
||||
os.Remove(newExt)
|
||||
}
|
||||
|
Reference in New Issue
Block a user