From 36467bf0845d109a12810869b9a5c8be64a04ea0 Mon Sep 17 00:00:00 2001 From: 3u13r Date: Mon, 25 Sep 2023 18:06:44 +0200 Subject: [PATCH] cli: remove state on terminate (#2359) --- cli/internal/cmd/terminate.go | 4 ++++ cli/internal/cmd/terminate_test.go | 3 +++ 2 files changed, 7 insertions(+) diff --git a/cli/internal/cmd/terminate.go b/cli/internal/cmd/terminate.go index ceb7f758a0..4ae9c56cd2 100644 --- a/cli/internal/cmd/terminate.go +++ b/cli/internal/cmd/terminate.go @@ -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 } diff --git a/cli/internal/cmd/terminate_test.go b/cli/internal/cmd/terminate_test.go index 1f47b14561..9fdcf222a2 100644 --- a/cli/internal/cmd/terminate_test.go +++ b/cli/internal/cmd/terminate_test.go @@ -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) } } })