Skip to content

Commit

Permalink
cli: remove state on terminate (#2359)
Browse files Browse the repository at this point in the history
  • Loading branch information
3u13r authored Sep 25, 2023
1 parent 4680882 commit 36467bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cli/internal/cmd/terminate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions cli/internal/cmd/terminate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
}
}
})
Expand Down

0 comments on commit 36467bf

Please sign in to comment.