-
Notifications
You must be signed in to change notification settings - Fork 151
acc: Select subset of tests that cover all output #4800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
26e0753
fb4458e
255d9c5
8c9fba2
f65f3d6
7dbc97d
22304e1
569a2a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "hash/fnv" | ||
| "os" | ||
| "path/filepath" | ||
| "reflect" | ||
|
|
@@ -427,17 +428,66 @@ func filterExcludedEnvSets(envSets [][]string, exclude map[string][]string) [][] | |
| return filtered | ||
| } | ||
|
|
||
| // SubsetExpanded selects one variant per DATABRICKS_BUNDLE_ENGINE value (if scriptUsesEngine) | ||
| // or one variant total from an already-expanded and exclusion-filtered list. | ||
| // DATABRICKS_BUNDLE_ENGINE=direct has weight 10; all other variants have weight 1. | ||
| func SubsetExpanded(expanded [][]string, testDir string, scriptUsesEngine bool) [][]string { | ||
| if len(expanded) <= 1 { | ||
| return expanded | ||
| } | ||
| if scriptUsesEngine { | ||
| // Collect candidates per engine key, preserving first-seen order. | ||
| // keyToIdx maps engine value -> index in result/groups slices. | ||
| var result [][]string | ||
| var groups [][][]string | ||
| keyToIdx := make(map[string]int) | ||
| for _, envset := range expanded { | ||
| engine := "" | ||
| for _, kv := range envset { | ||
| if v, ok := strings.CutPrefix(kv, "DATABRICKS_BUNDLE_ENGINE="); ok { | ||
| engine = v | ||
| break | ||
| } | ||
| } | ||
| idx, ok := keyToIdx[engine] | ||
| if !ok { | ||
| idx = len(result) | ||
| keyToIdx[engine] = idx | ||
| result = append(result, nil) | ||
| groups = append(groups, nil) | ||
| } | ||
| groups[idx] = append(groups[idx], envset) | ||
| } | ||
| for i, group := range groups { | ||
| result[i] = weightedSelect(group, testDir) | ||
| } | ||
| return result | ||
| } | ||
| return [][]string{weightedSelect(expanded, testDir)} | ||
| } | ||
|
|
||
| // weightedSelect picks one envset using weighted consistent hashing. | ||
| // DATABRICKS_BUNDLE_ENGINE=direct has weight 10; all other envsets have weight 1. | ||
| func weightedSelect(envsets [][]string, testDir string) []string { | ||
| var weighted [][]string | ||
| for _, envset := range envsets { | ||
| weight := 1 | ||
| if slices.Contains(envset, "DATABRICKS_BUNDLE_ENGINE=direct") { | ||
| weight = 10 | ||
| } | ||
| for range weight { | ||
| weighted = append(weighted, envset) | ||
| } | ||
| } | ||
| h := fnv.New64a() | ||
| h.Write([]byte(testDir)) | ||
| return weighted[h.Sum64()%uint64(len(weighted))] | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [SUGGESTION] // Precondition: envsets must be non-empty.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. panic on unsupported input is okay |
||
| // matchesExclusionRule returns true if envSet contains all KEY=value pairs from excludeRule. | ||
| func matchesExclusionRule(envSet, excludeRule []string) bool { | ||
| for _, excludePair := range excludeRule { | ||
| found := false | ||
| for _, envPair := range envSet { | ||
| if envPair == excludePair { | ||
| found = true | ||
| break | ||
| } | ||
| } | ||
| if !found { | ||
| if !slices.Contains(envSet, excludePair) { | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| echo "engine=$DATABRICKS_BUNDLE_ENGINE" > "out.$DATABRICKS_BUNDLE_ENGINE.txt" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| engine=direct |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| engine=terraform |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # This script does not directly reference $DATABRICKS_BUNDLE_ENGINE. | ||
| # Engine detection happens via the ancestor _script helper, | ||
| # exercising the anyHelperScriptUsesEngine() path in subset selection. | ||
| source "$TESTDIR/../_script" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| EnvVaryOutput = "DATABRICKS_BUNDLE_ENGINE" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[SUGGESTION]
anyHelperScriptUsesEngine()and theSubsetwiring at line 395-400 are new harness control flow, but the unit tests only exerciseSubsetExpanded()in isolation. A regression in the ancestor_scriptscan or the-updateauto-enable path would not be caught. Consider adding a selftest acceptance case whose output varies by engine only through an ancestor_script, run under-subset/-updateso the harness behavior is pinned end-to-end.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea to add self-test as it also serves as documentation. 22304e1