MCPcopy Create free account
hub / github.com/github/gh-aw / TestResolveSecretValueForSet

Function TestResolveSecretValueForSet

pkg/cli/secret_set_command_test.go:15–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestResolveSecretValueForSet(t *testing.T) {
16 tests := []struct {
17 name string
18 fromEnv string
19 fromFlag string
20 envValue string
21 wantErr bool
22 wantValue string
23 errContains string
24 }{
25 {
26 name: "from flag",
27 fromFlag: "secret123",
28 wantValue: "secret123",
29 },
30 {
31 name: "from env var - set",
32 fromEnv: "TEST_SECRET",
33 envValue: "envvalue123",
34 wantValue: "envvalue123",
35 },
36 {
37 name: "from env var - empty",
38 fromEnv: "TEST_SECRET_MISSING",
39 wantErr: true,
40 errContains: "not set or empty",
41 },
42 }
43
44 for _, tt := range tests {
45 t.Run(tt.name, func(t *testing.T) {
46 // Set up environment
47 if tt.envValue != "" {
48 t.Setenv(tt.fromEnv, tt.envValue)
49 }
50
51 got, err := resolveSecretValueForSet(tt.fromEnv, tt.fromFlag)
52 if (err != nil) != tt.wantErr {
53 t.Errorf("resolveSecretValueForSet() error = %v, wantErr %v", err, tt.wantErr)
54 return
55 }
56 if tt.wantErr && tt.errContains != "" {
57 if err == nil || !strings.Contains(err.Error(), tt.errContains) {
58 t.Errorf("expected error containing %q, got %v", tt.errContains, err)
59 }
60 }
61 if !tt.wantErr && got != tt.wantValue {
62 t.Errorf("resolveSecretValueForSet() = %v, want %v", got, tt.wantValue)
63 }
64 })
65 }
66}
67
68func TestEncryptWithPublicKey(t *testing.T) {
69 // Valid 32-byte public key in base64

Callers

nothing calls this directly

Calls 5

resolveSecretValueForSetFunction · 0.85
SetenvMethod · 0.80
RunMethod · 0.45
ErrorfMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected