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

Function TestSecretUpdate

cli/secret_test.go:187–332  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

185}
186
187func TestSecretUpdate(t *testing.T) {
188 t.Parallel()
189
190 t.Run("ServerValidationError", func(t *testing.T) {
191 t.Parallel()
192
193 client := coderdtest.New(t, nil)
194 _ = coderdtest.CreateFirstUser(t, client)
195
196 setupCtx := testutil.Context(t, testutil.WaitMedium)
197 _, err := client.CreateUserSecret(setupCtx, codersdk.Me, codersdk.CreateUserSecretRequest{
198 Name: "my-secret",
199 Value: "original-value",
200 })
201 require.NoError(t, err)
202
203 inv, root := clitest.New(t, "secret", "update", "my-secret")
204 clitest.SetupConfig(t, client, root)
205
206 ctx := testutil.Context(t, testutil.WaitMedium)
207 err = inv.WithContext(ctx).Run()
208 require.ErrorContains(t, err, "At least one field must be provided")
209 })
210
211 t.Run("AllowsClearingFields", func(t *testing.T) {
212 t.Parallel()
213
214 client := coderdtest.New(t, nil)
215 _ = coderdtest.CreateFirstUser(t, client)
216
217 setupCtx := testutil.Context(t, testutil.WaitMedium)
218 _, err := client.CreateUserSecret(setupCtx, codersdk.Me, codersdk.CreateUserSecretRequest{
219 Name: "my-secret",
220 Value: "original-value",
221 Description: "original description",
222 EnvName: "MY_SECRET",
223 FilePath: "~/.my-secret",
224 })
225 require.NoError(t, err)
226
227 inv, root := clitest.New(
228 t,
229 "secret",
230 "update",
231 "my-secret",
232 "--value", "rotated-secret",
233 "--description", "",
234 "--env", "",
235 "--file", "",
236 )
237 output := clitest.Capture(inv)
238 clitest.SetupConfig(t, client, root)
239
240 ctx := testutil.Context(t, testutil.WaitMedium)
241 err = inv.WithContext(ctx).Run()
242 require.NoError(t, err)
243 require.Contains(t, output.Stdout(), "my-secret")
244

Callers

nothing calls this directly

Calls 13

NewFunction · 0.92
CreateFirstUserFunction · 0.92
ContextFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
CaptureFunction · 0.92
WithContextMethod · 0.80
StdoutMethod · 0.80
UserSecretByNameMethod · 0.80
RunMethod · 0.65
CreateUserSecretMethod · 0.65
ContainsMethod · 0.45

Tested by

no test coverage detected