MCPcopy Index your code
hub / github.com/coder/coder / TestUserDelete

Function TestUserDelete

cli/user_delete_test.go:18–160  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func TestUserDelete(t *testing.T) {
19 t.Parallel()
20 t.Run("Username", func(t *testing.T) {
21 t.Parallel()
22 ctx := context.Background()
23 client := coderdtest.New(t, nil)
24 owner := coderdtest.CreateFirstUser(t, client)
25 userAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleUserAdmin())
26
27 pw, err := cryptorand.String(16)
28 require.NoError(t, err)
29
30 _, err = client.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{
31 Email: "colin5@coder.com",
32 Username: "coolin",
33 Password: pw,
34 UserLoginType: codersdk.LoginTypePassword,
35 OrganizationIDs: []uuid.UUID{owner.OrganizationID},
36 })
37 require.NoError(t, err)
38
39 inv, root := clitest.New(t, "users", "delete", "coolin")
40 clitest.SetupConfig(t, userAdmin, root)
41 pty := ptytest.New(t).Attach(inv)
42 errC := make(chan error)
43 go func() {
44 errC <- inv.Run()
45 }()
46 require.NoError(t, <-errC)
47 pty.ExpectMatch("coolin")
48 })
49
50 t.Run("UserID", func(t *testing.T) {
51 t.Parallel()
52 ctx := context.Background()
53 client := coderdtest.New(t, nil)
54 owner := coderdtest.CreateFirstUser(t, client)
55 userAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleUserAdmin())
56
57 pw, err := cryptorand.String(16)
58 require.NoError(t, err)
59
60 user, err := client.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{
61 Email: "colin5@coder.com",
62 Username: "coolin",
63 Password: pw,
64 UserLoginType: codersdk.LoginTypePassword,
65 OrganizationIDs: []uuid.UUID{owner.OrganizationID},
66 })
67 require.NoError(t, err)
68
69 inv, root := clitest.New(t, "users", "delete", user.ID.String())
70 clitest.SetupConfig(t, userAdmin, root)
71 pty := ptytest.New(t).Attach(inv)
72 errC := make(chan error)
73 go func() {
74 errC <- inv.Run()
75 }()

Callers

nothing calls this directly

Calls 13

NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
RoleUserAdminFunction · 0.92
StringFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
NewFunction · 0.92
CreateUserWithOrgsMethod · 0.80
RunMethod · 0.65
AttachMethod · 0.65
ExpectMatchMethod · 0.45

Tested by

no test coverage detected