TestCacheKeyRunIDValidationObject tests that github.run_id in a cache key raises a compilation error (object notation).
(t *testing.T)
| 12 | // TestCacheKeyRunIDValidationObject tests that github.run_id in a cache key raises |
| 13 | // a compilation error (object notation). |
| 14 | func TestCacheKeyRunIDValidationObject(t *testing.T) { |
| 15 | tests := []struct { |
| 16 | name string |
| 17 | key string |
| 18 | wantError bool |
| 19 | errorText string |
| 20 | }{ |
| 21 | { |
| 22 | name: "key without run_id is accepted", |
| 23 | key: "trending-data-${{ env.GH_AW_WORKFLOW_ID_SANITIZED }}", |
| 24 | wantError: false, |
| 25 | }, |
| 26 | { |
| 27 | name: "key with run_id is rejected", |
| 28 | key: "trending-data-${{ env.GH_AW_WORKFLOW_ID_SANITIZED }}-${{ github.run_id }}", |
| 29 | wantError: true, |
| 30 | errorText: "cache key must not reference github.run_id", |
| 31 | }, |
| 32 | { |
| 33 | name: "key with only run_id is rejected", |
| 34 | key: "${{ github.run_id }}", |
| 35 | wantError: true, |
| 36 | errorText: "cache key must not reference github.run_id", |
| 37 | }, |
| 38 | { |
| 39 | name: "plain key without expressions is accepted", |
| 40 | key: "my-stable-cache-key", |
| 41 | wantError: false, |
| 42 | }, |
| 43 | { |
| 44 | name: "key with github.run_identifier is not a false positive", |
| 45 | key: "my-cache-${{ github.run_identifier }}", |
| 46 | wantError: false, |
| 47 | }, |
| 48 | { |
| 49 | name: "key with github.run_id_backup suffix is not a false positive", |
| 50 | key: "my-cache-github.run_id_backup", |
| 51 | wantError: false, |
| 52 | }, |
| 53 | } |
| 54 | |
| 55 | for _, tt := range tests { |
| 56 | t.Run(tt.name, func(t *testing.T) { |
| 57 | toolsMap := map[string]any{ |
| 58 | "cache-memory": map[string]any{ |
| 59 | "key": tt.key, |
| 60 | }, |
| 61 | } |
| 62 | |
| 63 | toolsConfig, err := ParseToolsConfig(toolsMap) |
| 64 | require.NoError(t, err, "Should parse tools config") |
| 65 | |
| 66 | compiler := NewCompiler() |
| 67 | _, err = compiler.extractCacheMemoryConfig(toolsConfig) |
| 68 | |
| 69 | if tt.wantError { |
| 70 | require.Error(t, err, "Should return error for key containing run_id") |
| 71 | assert.ErrorContains(t, err, tt.errorText, "Error should contain expected message") |
nothing calls this directly
no test coverage detected