cli: remove state on terminate (#2359)

This commit is contained in:
3u13r 2023-09-25 18:06:44 +02:00 committed by GitHub
parent 4680882708
commit 36467bf084
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -88,6 +88,10 @@ func terminate(cmd *cobra.Command, terminator cloudTerminator, fileHandler file.
removeErr = errors.Join(err, fmt.Errorf("failed to remove file: '%s', please remove it manually", pf.PrefixPrintablePath(constants.ClusterIDsFilename)))
}
if err := fileHandler.Remove(constants.StateFilename); err != nil && !errors.Is(err, fs.ErrNotExist) {
removeErr = errors.Join(err, fmt.Errorf("failed to remove file: '%s', please remove it manually", pf.PrefixPrintablePath(constants.StateFilename)))
}
return removeErr
}

View File

@ -52,6 +52,7 @@ func TestTerminate(t *testing.T) {
fileHandler := file.NewHandler(fs)
require.NoError(fileHandler.Write(constants.AdminConfFilename, []byte{1, 2}, file.OptNone))
require.NoError(fileHandler.WriteJSON(constants.ClusterIDsFilename, idFile, file.OptNone))
require.NoError(fileHandler.Write(constants.StateFilename, []byte{3, 4}, file.OptNone))
return fs
}
someErr := errors.New("failed")
@ -160,6 +161,8 @@ func TestTerminate(t *testing.T) {
assert.Error(err)
_, err = fileHandler.Stat(constants.ClusterIDsFilename)
assert.Error(err)
_, err = fileHandler.Stat(constants.StateFilename)
assert.Error(err)
}
}
})