@@ -2029,6 +2029,41 @@ func TestWorkspacesUnlock(t *testing.T) {
2029
2029
assert .Equal (t , ErrWorkspaceLockedByRun , err )
2030
2030
})
2031
2031
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
+ assert .Nil (t , err )
2045
+ defer func () {
2046
+ err := client .TeamAccess .Remove (ctx , ta .ID )
2047
+ if err != nil {
2048
+ t .Logf ("error removing team access (%s): %s" , ta .ID , err )
2049
+ }
2050
+ }()
2051
+ tt , ttTestCleanup := createTeamToken (t , client , tmTest )
2052
+ defer ttTestCleanup ()
2053
+
2054
+ // Create a new client with the team token
2055
+ teamClient := testClient (t )
2056
+ teamClient .token = tt .Token
2057
+
2058
+ // Lock the workspace with the team client
2059
+ _ , err = teamClient .Workspaces .Lock (ctx , wTest2 .ID , WorkspaceLockOptions {})
2060
+ assert .Nil (t , err )
2061
+
2062
+ // Attempt to unlock the workspace with the original client
2063
+ _ , err = client .Workspaces .Unlock (ctx , wTest2 .ID )
2064
+ assert .Equal (t , ErrWorkspaceLockedByTeam , err )
2065
+ })
2066
+
2032
2067
t .Run ("without a valid workspace ID" , func (t * testing.T ) {
2033
2068
w , err := client .Workspaces .Unlock (ctx , badIdentifier )
2034
2069
assert .Nil (t , w )
0 commit comments