rados: improve clean up of temporary file used in test

Clean up the temporary file using a defer and make sure that the
errors returned by the functions in the defer func are checked.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2020-04-08 16:40:41 -04:00 committed by John Mulligan
parent c4f8f0445a
commit a1de43cd5d
1 changed files with 5 additions and 4 deletions

View File

@ -193,7 +193,11 @@ func (suite *RadosTestSuite) TestReadConfigFile() {
// create conf file that changes log_file conf option
file, err := ioutil.TempFile("/tmp", "go-rados")
assert.NoError(suite.T(), err)
require.NoError(suite.T(), err)
defer func() {
assert.NoError(suite.T(), file.Close())
assert.NoError(suite.T(), os.Remove(file.Name()))
}()
next_val := prev_val + 1
conf := fmt.Sprintf("[global]\nlog_max_new = %d\n", next_val)
@ -213,9 +217,6 @@ func (suite *RadosTestSuite) TestReadConfigFile() {
assert.NotEqual(suite.T(), prev_str, curr_str)
assert.Equal(suite.T(), curr_val, prev_val+1)
file.Close()
os.Remove(file.Name())
}
func (suite *RadosTestSuite) TestGetClusterStats() {