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

Function TestExtractSecretsFromValue

pkg/workflow/mcp_http_headers_test.go:10–67  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestExtractSecretsFromValue(t *testing.T) {
11 tests := []struct {
12 name string
13 value string
14 expected map[string]string
15 }{
16 {
17 name: "Single secret",
18 value: "${{ secrets.DD_API_KEY }}",
19 expected: map[string]string{
20 "DD_API_KEY": "${{ secrets.DD_API_KEY }}",
21 },
22 },
23 {
24 name: "Secret with default value",
25 value: "${{ secrets.DD_SITE || 'datadoghq.com' }}",
26 expected: map[string]string{
27 "DD_SITE": "${{ secrets.DD_SITE || 'datadoghq.com' }}",
28 },
29 },
30 {
31 name: "Multiple secrets in one value",
32 value: "Bearer ${{ secrets.TOKEN1 }} and ${{ secrets.TOKEN2 }}",
33 expected: map[string]string{
34 "TOKEN1": "${{ secrets.TOKEN1 }}",
35 "TOKEN2": "${{ secrets.TOKEN2 }}",
36 },
37 },
38 {
39 name: "No secrets",
40 value: "Just a plain string",
41 expected: map[string]string{},
42 },
43 {
44 name: "Empty string",
45 value: "",
46 expected: map[string]string{},
47 },
48 }
49
50 for _, tt := range tests {
51 t.Run(tt.name, func(t *testing.T) {
52 result := ExtractSecretsFromValue(tt.value)
53
54 if len(result) != len(tt.expected) {
55 t.Errorf("Expected %d secrets, got %d", len(tt.expected), len(result))
56 }
57
58 for key, expectedValue := range tt.expected {
59 if actualValue, exists := result[key]; !exists {
60 t.Errorf("Expected secret %s not found", key)
61 } else if actualValue != expectedValue {
62 t.Errorf("For key %s, expected %q, got %q", key, expectedValue, actualValue)
63 }
64 }
65 })
66 }
67}

Callers

nothing calls this directly

Calls 3

ExtractSecretsFromValueFunction · 0.85
RunMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected