Skip to content

Commit 80ceded

Browse files
lucasmelinctrombley
authored andcommitted
Test case for unlocking a workspace when it has been locked by a team
1 parent 4eb4137 commit 80ceded

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

workspace_integration_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,6 +2029,40 @@ func TestWorkspacesUnlock(t *testing.T) {
20292029
assert.Equal(t, ErrWorkspaceLockedByRun, err)
20302030
})
20312031

2032+
t.Run("when a workspace is locked by a team", func(t *testing.T) {
2033+
wTest2, wTest2Cleanup := createWorkspace(t, client, orgTest)
2034+
t.Cleanup(wTest2Cleanup)
2035+
2036+
// Create a new team to lock the workspace
2037+
tmTest, tmTestCleanup := createTeam(t, client, orgTest)
2038+
defer tmTestCleanup()
2039+
ta, err := client.TeamAccess.Add(ctx, TeamAccessAddOptions{
2040+
Access: Access(AccessAdmin),
2041+
Team: tmTest,
2042+
Workspace: wTest2,
2043+
})
2044+
defer func() {
2045+
err := client.TeamAccess.Remove(ctx, ta.ID)
2046+
if err != nil {
2047+
t.Logf("error removing team access (%s): %s", ta.ID, err)
2048+
}
2049+
}()
2050+
tt, ttTestCleanup := createTeamToken(t, client, tmTest)
2051+
defer ttTestCleanup()
2052+
2053+
// Create a new client with the team token
2054+
teamClient := testClient(t)
2055+
teamClient.token = tt.Token
2056+
2057+
// Lock the workspace with the team client
2058+
_, err = teamClient.Workspaces.Lock(ctx, wTest2.ID, WorkspaceLockOptions{})
2059+
assert.Nil(t, err)
2060+
2061+
// Attempt to unlock the workspace with the original client
2062+
_, err = client.Workspaces.Unlock(ctx, wTest2.ID)
2063+
assert.Equal(t, ErrWorkspaceLockedByTeam, err)
2064+
})
2065+
20322066
t.Run("without a valid workspace ID", func(t *testing.T) {
20332067
w, err := client.Workspaces.Unlock(ctx, badIdentifier)
20342068
assert.Nil(t, w)

0 commit comments

Comments
 (0)