[TF-20366] Return correct error message when workspace is locked by a Team or User #975
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR aims to close #971 where the tfe client would return an incorrect error message whenever a user attempted to unlock a workspace that was already locked by a team or a different user.
The current implementation of this client defaults to "workspaces already unlocked" whenever a status 409 is received from the workspace unlock endpoint. A matcher function
errorPayloadHasMatch
currently parses the the error detail and searches for the "locked by Run" substring that indicates the workspace was locked by a run.This pattern was extended for the two other instances in which a status 409 is returned. The "locked by Team" substring indicates the workspace was locked by a Team, and similarly the "locked by User" substring indicates that the workspace was locked by a different User.
Testing plan
To run the integration test:
go test -run TestWorkspacesUnlock -v ./... -tags=integration
Because I've modified tfe.go, it's always good to verify those tests as well:
go test -run TestClient -v ./... -tags=integration
I wasn't able to find a way to create a secondary user in the integration tests to test the "locked by User" scenario in a automated fashion. Any suggestions on how to accomplish this would be appreciated.
External links
Output from tests
Including output from tests may require access to a TFE instance. Ignore this section if you have no environment to test against.
For
TestWorkspacesUnlock
:For
TestClient
: