|
47 | 47 | UseVersion string |
48 | 48 | WorkspaceTmpDir bool |
49 | 49 | OnlyOutTestToml bool |
| 50 | + Subset bool |
50 | 51 | ) |
51 | 52 |
|
52 | 53 | // In order to debug CLI running under acceptance test, search for TestInprocessMode and update |
@@ -78,6 +79,7 @@ func init() { |
78 | 79 | // to simulate an identical environment. |
79 | 80 | flag.BoolVar(&WorkspaceTmpDir, "workspace-tmp-dir", false, "Run tests on the workspace file system (For DBR testing).") |
80 | 81 | flag.BoolVar(&OnlyOutTestToml, "only-out-test-toml", false, "Only regenerate out.test.toml files without running tests") |
| 82 | + flag.BoolVar(&Subset, "subset", false, "Select a subset of EnvMatrix variants that cover all output files. Auto-enabled on -update.") |
81 | 83 | } |
82 | 84 |
|
83 | 85 | const ( |
@@ -156,7 +158,32 @@ func setReplsForTestEnvVars(t *testing.T, repls *testdiff.ReplacementsContext) { |
156 | 158 | } |
157 | 159 | } |
158 | 160 |
|
| 161 | +// helperScriptUsesEngineCache caches whether a _script helper in a given directory |
| 162 | +// (or any of its ancestors) references $DATABRICKS_BUNDLE_ENGINE. |
| 163 | +// Since _script helpers are shared across many tests, caching avoids redundant reads. |
| 164 | +var helperScriptUsesEngineCache sync.Map |
| 165 | + |
| 166 | +// anyHelperScriptUsesEngine returns true if any _script helper in dir or its ancestors |
| 167 | +// contains $DATABRICKS_BUNDLE_ENGINE. |
| 168 | +func anyHelperScriptUsesEngine(dir string) bool { |
| 169 | + if dir == "" || dir == "." { |
| 170 | + return false |
| 171 | + } |
| 172 | + if v, ok := helperScriptUsesEngineCache.Load(dir); ok { |
| 173 | + return v.(bool) |
| 174 | + } |
| 175 | + content, err := os.ReadFile(filepath.Join(dir, "_script")) |
| 176 | + result := (err == nil && strings.Contains(string(content), "$DATABRICKS_BUNDLE_ENGINE")) || |
| 177 | + anyHelperScriptUsesEngine(filepath.Dir(dir)) |
| 178 | + helperScriptUsesEngineCache.Store(dir, result) |
| 179 | + return result |
| 180 | +} |
| 181 | + |
159 | 182 | func testAccept(t *testing.T, inprocessMode bool, singleTest string) int { |
| 183 | + if testdiff.OverwriteMode { |
| 184 | + Subset = true |
| 185 | + } |
| 186 | + |
160 | 187 | repls := testdiff.ReplacementsContext{} |
161 | 188 | cwd, err := os.Getwd() |
162 | 189 | require.NoError(t, err) |
@@ -366,6 +393,12 @@ func testAccept(t *testing.T, inprocessMode bool, singleTest string) int { |
366 | 393 | } |
367 | 394 |
|
368 | 395 | expanded := internal.ExpandEnvMatrix(config.EnvMatrix, config.EnvMatrixExclude, extraVars) |
| 396 | + if Subset { |
| 397 | + scriptContent, _ := os.ReadFile(filepath.Join(dir, EntryPointScript)) |
| 398 | + scriptUsesEngine := strings.Contains(string(scriptContent), "$DATABRICKS_BUNDLE_ENGINE") || |
| 399 | + anyHelperScriptUsesEngine(dir) |
| 400 | + expanded = internal.SubsetExpanded(expanded, dir, scriptUsesEngine) |
| 401 | + } |
369 | 402 |
|
370 | 403 | for ind, envset := range expanded { |
371 | 404 | envname := strings.Join(envset, "/") |
|
0 commit comments