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

Function TestSecretCreate

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

Source from the content-addressed store, hash-verified

19)
20
21func TestSecretCreate(t *testing.T) {
22 t.Parallel()
23
24 t.Run("MissingValue", func(t *testing.T) {
25 t.Parallel()
26
27 client := coderdtest.New(t, nil)
28 _ = coderdtest.CreateFirstUser(t, client)
29
30 inv, root := clitest.New(t, "secret", "create", "api-key")
31 clitest.SetupConfig(t, client, root)
32
33 ctx := testutil.Context(t, testutil.WaitMedium)
34 err := inv.WithContext(ctx).Run()
35 require.ErrorContains(t, err, "secret value must be provided by exactly one of --value or non-interactive stdin (pipe or redirect)")
36 })
37
38 t.Run("MissingValueOnTTY", func(t *testing.T) {
39 t.Parallel()
40
41 client := coderdtest.New(t, nil)
42 _ = coderdtest.CreateFirstUser(t, client)
43
44 inv, root := clitest.New(t, "--force-tty", "secret", "create", "api-key")
45 clitest.SetupConfig(t, client, root)
46
47 ctx := testutil.Context(t, testutil.WaitMedium)
48 err := inv.WithContext(ctx).Run()
49 require.ErrorContains(t, err, "secret value must be provided with --value or stdin via pipe or redirect")
50 })
51
52 t.Run("SuccessWithValueFlag", func(t *testing.T) {
53 t.Parallel()
54
55 client := coderdtest.New(t, nil)
56 _ = coderdtest.CreateFirstUser(t, client)
57
58 inv, root := clitest.New(
59 t,
60 "secret",
61 "create",
62 "api-key",
63 "--value", "super-secret-value",
64 "--description", "API key for workspace tools",
65 "--env", "API_KEY",
66 "--file", "~/.api-key",
67 )
68 output := clitest.Capture(inv)
69 clitest.SetupConfig(t, client, root)
70
71 ctx := testutil.Context(t, testutil.WaitMedium)
72 err := inv.WithContext(ctx).Run()
73 require.NoError(t, err)
74 require.Contains(t, output.Stdout(), "api-key")
75
76 secret, err := client.UserSecretByName(ctx, codersdk.Me, "api-key")
77 require.NoError(t, err)
78 require.Equal(t, "api-key", secret.Name)

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
CreateFirstUserFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
ContextFunction · 0.92
CaptureFunction · 0.92
NewWithDatabaseFunction · 0.92
CreateAnotherUserFunction · 0.92
AsSystemRestrictedFunction · 0.92
WithContextMethod · 0.80
StdoutMethod · 0.80
UserSecretByNameMethod · 0.80

Tested by

no test coverage detected