chore(cli): add linter to detect potential spurious usage of owner user in cli tests (#10133)

* Detects the following pattern where the CLI is initialized with a client authenticated as the "first user":

    client := coderdtest.New(t, ...)
    [...]
    user := coderdtest.CreateFirstUser(t, client)
    [...]
    clitest.SetupConfig(t, client, root)

* Updates documentation regarding role permissions on workspaces.
This commit is contained in:
Cian Johnston
2023-10-10 11:14:20 +01:00
committed by GitHub
parent 017d7e9dad
commit c83af5e627
28 changed files with 684 additions and 521 deletions
+6 -4
View File
@@ -9,6 +9,7 @@ import (
"github.com/coder/coder/v2/cli/clitest"
"github.com/coder/coder/v2/coderd/coderdtest"
"github.com/coder/coder/v2/coderd/rbac"
"github.com/coder/coder/v2/codersdk"
)
@@ -35,13 +36,14 @@ func TestUserStatus(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, nil)
admin := coderdtest.CreateFirstUser(t, client)
other, _ := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
owner := coderdtest.CreateFirstUser(t, client)
userAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleUserAdmin())
other, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
otherUser, err := other.User(context.Background(), codersdk.Me)
require.NoError(t, err, "fetch user")
inv, root := clitest.New(t, "users", "suspend", otherUser.Username)
clitest.SetupConfig(t, client, root)
clitest.SetupConfig(t, userAdmin, root)
// Yes to the prompt
inv.Stdin = bytes.NewReader([]byte("yes\n"))
err = inv.Run()
@@ -54,7 +56,7 @@ func TestUserStatus(t *testing.T) {
// Set back to active. Try using a uuid as well
inv, root = clitest.New(t, "users", "activate", otherUser.ID.String())
clitest.SetupConfig(t, client, root)
clitest.SetupConfig(t, userAdmin, root)
// Yes to the prompt
inv.Stdin = bytes.NewReader([]byte("yes\n"))
err = inv.Run()