TestSharedExtractSecretsFromValue tests the shared ExtractSecretsFromValue utility function
(t *testing.T)
| 69 | |
| 70 | // TestSharedExtractSecretsFromValue tests the shared ExtractSecretsFromValue utility function |
| 71 | func TestSharedExtractSecretsFromValue(t *testing.T) { |
| 72 | tests := []struct { |
| 73 | name string |
| 74 | value string |
| 75 | expected map[string]string |
| 76 | }{ |
| 77 | { |
| 78 | name: "simple secret", |
| 79 | value: "${{ secrets.DD_API_KEY }}", |
| 80 | expected: map[string]string{ |
| 81 | "DD_API_KEY": "${{ secrets.DD_API_KEY }}", |
| 82 | }, |
| 83 | }, |
| 84 | { |
| 85 | name: "secret with default value", |
| 86 | value: "${{ secrets.DD_SITE || 'datadoghq.com' }}", |
| 87 | expected: map[string]string{ |
| 88 | "DD_SITE": "${{ secrets.DD_SITE || 'datadoghq.com' }}", |
| 89 | }, |
| 90 | }, |
| 91 | { |
| 92 | name: "bearer token", |
| 93 | value: "Bearer ${{ secrets.TAVILY_API_KEY }}", |
| 94 | expected: map[string]string{ |
| 95 | "TAVILY_API_KEY": "${{ secrets.TAVILY_API_KEY }}", |
| 96 | }, |
| 97 | }, |
| 98 | { |
| 99 | name: "multiple secrets in one value", |
| 100 | value: "${{ secrets.KEY1 }} and ${{ secrets.KEY2 }}", |
| 101 | expected: map[string]string{ |
| 102 | "KEY1": "${{ secrets.KEY1 }}", |
| 103 | "KEY2": "${{ secrets.KEY2 }}", |
| 104 | }, |
| 105 | }, |
| 106 | { |
| 107 | name: "no secrets", |
| 108 | value: "plain value", |
| 109 | expected: map[string]string{}, |
| 110 | }, |
| 111 | { |
| 112 | name: "empty value", |
| 113 | value: "", |
| 114 | expected: map[string]string{}, |
| 115 | }, |
| 116 | { |
| 117 | name: "secret with complex default", |
| 118 | value: "${{ secrets.CONFIG || 'default-config-value' }}", |
| 119 | expected: map[string]string{ |
| 120 | "CONFIG": "${{ secrets.CONFIG || 'default-config-value' }}", |
| 121 | }, |
| 122 | }, |
| 123 | { |
| 124 | name: "sub-expression: github.workflow && secrets.TOKEN", |
| 125 | value: "${{ github.workflow && secrets.TOKEN }}", |
| 126 | expected: map[string]string{ |
| 127 | "TOKEN": "${{ github.workflow && secrets.TOKEN }}", |
| 128 | }, |
nothing calls this directly
no test coverage detected