(t *testing.T)
| 19 | ) |
| 20 | |
| 21 | func 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) |
nothing calls this directly
no test coverage detected