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

Function TestUserShow

cli/userlist_test.go:96–150  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

94}
95
96func TestUserShow(t *testing.T) {
97 t.Parallel()
98
99 t.Run("Table", func(t *testing.T) {
100 t.Parallel()
101 client := coderdtest.New(t, nil)
102 owner := coderdtest.CreateFirstUser(t, client)
103 userAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleUserAdmin())
104 _, otherUser := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
105 inv, root := clitest.New(t, "users", "show", otherUser.Username)
106 clitest.SetupConfig(t, userAdmin, root)
107 doneChan := make(chan struct{})
108 pty := ptytest.New(t).Attach(inv)
109 go func() {
110 defer close(doneChan)
111 err := inv.Run()
112 assert.NoError(t, err)
113 }()
114 pty.ExpectMatch(otherUser.Email)
115 <-doneChan
116 })
117
118 t.Run("JSON", func(t *testing.T) {
119 t.Parallel()
120
121 ctx := context.Background()
122 client := coderdtest.New(t, nil)
123 owner := coderdtest.CreateFirstUser(t, client)
124 userAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleUserAdmin())
125 other, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
126 otherUser, err := other.User(ctx, codersdk.Me)
127 require.NoError(t, err, "fetch other user")
128 inv, root := clitest.New(t, "users", "show", otherUser.Username, "-o", "json")
129 clitest.SetupConfig(t, userAdmin, root)
130 doneChan := make(chan struct{})
131
132 buf := bytes.NewBuffer(nil)
133 inv.Stdout = buf
134 go func() {
135 defer close(doneChan)
136 err := inv.Run()
137 assert.NoError(t, err)
138 }()
139
140 <-doneChan
141
142 var newUser codersdk.User
143 err = json.Unmarshal(buf.Bytes(), &newUser)
144 require.NoError(t, err, "unmarshal JSON output")
145 require.Equal(t, otherUser.ID, newUser.ID)
146 require.Equal(t, otherUser.Username, newUser.Username)
147 require.Equal(t, otherUser.Email, newUser.Email)
148 require.Equal(t, otherUser.Name, newUser.Name)
149 })
150}

Callers

nothing calls this directly

Calls 14

NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
RoleUserAdminFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
NewFunction · 0.92
RunMethod · 0.65
AttachMethod · 0.65
UserMethod · 0.65
ExpectMatchMethod · 0.45
UnmarshalMethod · 0.45

Tested by

no test coverage detected