Fix broken rename behavior in tfe_client_mock.go

The delete + assign at the end of `Update` and `UpdateByID` are meant to handle
renaming a workspace — (remove old name), (insert new name).

However, `UpdateByID` was doing (remove new name), (insert new name) and leaving
the old name in place. This commit changes it to match `Update` by grabbing the
original name off the workspace object _before_ potentially renaming it.
This commit is contained in:
Nick Fagerlund 2021-10-26 17:02:28 -07:00 committed by Chris Arcand
parent 50997d9a32
commit fabd8eb0b6
1 changed files with 2 additions and 1 deletions

View File

@ -1255,12 +1255,13 @@ func (m *MockWorkspaces) UpdateByID(ctx context.Context, workspaceID string, opt
return nil, tfe.ErrResourceNotFound
}
originalName := w.Name
err := updateMockWorkspaceAttributes(w, options)
if err != nil {
return nil, err
}
delete(m.workspaceNames, w.Name)
delete(m.workspaceNames, originalName)
m.workspaceNames[w.Name] = w
return w, nil