Delete cluster IDs file on terminate

This commit is contained in:
Nils Hanke 2022-07-05 13:59:46 +02:00 committed by Nils Hanke
parent 259c88fa1a
commit bc5471e9b3
2 changed files with 7 additions and 0 deletions

View File

@ -62,5 +62,9 @@ func terminate(cmd *cobra.Command, terminator cloudTerminator, fileHandler file.
retErr = multierr.Append(err, fmt.Errorf("failed to remove file: '%s', please remove it manually", constants.WGQuickConfigFilename))
}
if err := fileHandler.Remove(constants.ClusterIDsFileName); err != nil && !errors.Is(err, fs.ErrNotExist) {
retErr = multierr.Append(err, fmt.Errorf("failed to remove file: '%s', please remove it manually", constants.ClusterIDsFileName))
}
return retErr
}

View File

@ -45,6 +45,7 @@ func TestTerminate(t *testing.T) {
fileHandler := file.NewHandler(fs)
require.NoError(fileHandler.Write(constants.AdminConfFilename, []byte{1, 2}, file.OptNone))
require.NoError(fileHandler.Write(constants.WGQuickConfigFilename, []byte{1, 2}, file.OptNone))
require.NoError(fileHandler.Write(constants.ClusterIDsFileName, []byte{1, 2}, file.OptNone))
require.NoError(fileHandler.WriteJSON(constants.StateFilename, state, file.OptNone))
return fs
}
@ -125,6 +126,8 @@ func TestTerminate(t *testing.T) {
assert.Error(err)
_, err = fileHandler.Stat(constants.WGQuickConfigFilename)
assert.Error(err)
_, err = fileHandler.Stat(constants.ClusterIDsFileName)
assert.Error(err)
}
})
}