test: add unit test that deletes abandoned workspace (#7990)

* test: add unit test that deletes abandoned workspace

This is to ensure we do not break this functionality in future.
This is important incase this edge case happens, an admin can
clean up the abandoned resources.
This commit is contained in:
Steven Masley
2023-06-13 10:42:18 -05:00
committed by GitHub
parent c916a9e67f
commit 9cf3c582cb
2 changed files with 58 additions and 1 deletions
+9 -1
View File
@@ -4646,11 +4646,19 @@ func (q *fakeQuerier) UpdateUserDeletedByID(_ context.Context, params database.U
u.Deleted = params.Deleted
q.users[i] = u
// NOTE: In the real world, this is done by a trigger.
for i, k := range q.apiKeys {
i := 0
for {
if i >= len(q.apiKeys) {
break
}
k := q.apiKeys[i]
if k.UserID == u.ID {
q.apiKeys[i] = q.apiKeys[len(q.apiKeys)-1]
q.apiKeys = q.apiKeys[:len(q.apiKeys)-1]
// We removed an element, so decrement
i--
}
i++
}
return nil
}