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

Function TestCacheKeyRunIDValidationArray

pkg/workflow/cache_key_validation_test.go:81–126  ·  view source on GitHub ↗

TestCacheKeyRunIDValidationArray tests that github.run_id in a cache key raises a compilation error (array notation).

(t *testing.T)

Source from the content-addressed store, hash-verified

79// TestCacheKeyRunIDValidationArray tests that github.run_id in a cache key raises
80// a compilation error (array notation).
81func TestCacheKeyRunIDValidationArray(t *testing.T) {
82 tests := []struct {
83 name string
84 key string
85 wantError bool
86 errorText string
87 }{
88 {
89 name: "array entry key without run_id is accepted",
90 key: "my-data-${{ env.GH_AW_WORKFLOW_ID_SANITIZED }}",
91 wantError: false,
92 },
93 {
94 name: "array entry key with run_id is rejected",
95 key: "my-data-${{ env.GH_AW_WORKFLOW_ID_SANITIZED }}-${{ github.run_id }}",
96 wantError: true,
97 errorText: "cache key must not reference github.run_id",
98 },
99 }
100
101 for _, tt := range tests {
102 t.Run(tt.name, func(t *testing.T) {
103 toolsMap := map[string]any{
104 "cache-memory": []any{
105 map[string]any{
106 "id": "test-cache",
107 "key": tt.key,
108 },
109 },
110 }
111
112 toolsConfig, err := ParseToolsConfig(toolsMap)
113 require.NoError(t, err, "Should parse tools config")
114
115 compiler := NewCompiler()
116 _, err = compiler.extractCacheMemoryConfig(toolsConfig)
117
118 if tt.wantError {
119 require.Error(t, err, "Should return error for key containing run_id")
120 assert.ErrorContains(t, err, tt.errorText, "Error should contain expected message")
121 } else {
122 assert.NoError(t, err, "Should not return error for valid key")
123 }
124 })
125 }
126}

Callers

nothing calls this directly

Calls 5

ParseToolsConfigFunction · 0.85
NewCompilerFunction · 0.85
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected