Skip to content

Commit 078e184

Browse files
authored
Exclude invariant/no_drift/alert on cloud; Support filter by cloud in EnvMatrixExclude (#4406)
## Changes - Add support to EnvMatrixExclude to exclude certain combinations only for cloud tests. - Use this functionality to disable acceptance.TestAccept/bundle/invariant/no_drift/direct/alert.yml.tmpl ## Why It times outs due to know alert quota issue and each attempt takes 15min: ``` FAIL acceptance.TestAccept/bundle/invariant/no_drift/DATABRICKS_BUNDLE_ENGINE=direct/INPUT_CONFIG=alert.yml.tmpl (re-run 1) (912.04s) FAIL acceptance.TestAccept/bundle/invariant/no_drift (re-run 1) (0.00s) FAIL acceptance.TestAccept (re-run 1) (3.63s) FAIL Package acceptance (15m15.674s) ``` ## Tests Manually checked that the test is present when run locally but not when ran on cloud.
1 parent e46c3fb commit 078e184

File tree

4 files changed

+72
-8
lines changed

4 files changed

+72
-8
lines changed

acceptance/acceptance_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,13 @@ func testAccept(t *testing.T, inprocessMode bool, singleTest string) int {
337337
t.Parallel()
338338
}
339339

340-
expanded := internal.ExpandEnvMatrix(config.EnvMatrix, config.EnvMatrixExclude)
340+
// Build extra vars for exclusion matching (config state as env vars)
341+
var extraVars []string
342+
if cloudEnv != "" {
343+
extraVars = append(extraVars, "CONFIG_Cloud=true")
344+
}
345+
346+
expanded := internal.ExpandEnvMatrix(config.EnvMatrix, config.EnvMatrixExclude, extraVars)
341347

342348
if len(expanded) == 1 {
343349
// env vars aren't part of the test case name, so log them for debugging

acceptance/bundle/invariant/test.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ EnvMatrix.INPUT_CONFIG = [
3636
"volume.yml.tmpl",
3737
]
3838

39+
[EnvMatrixExclude]
40+
no_alert_on_cloud = ["CONFIG_Cloud=true", "INPUT_CONFIG=alert.yml.tmpl"]
41+
3942
# Fake SQL endpoint for local tests
4043
[[Server]]
4144
Pattern = "POST /api/2.0/sql/statements/"

acceptance/internal/config.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ type TestConfig struct {
102102

103103
// Environment variables matrix exclusion list.
104104
// Exclude certain configuration from the grid generated by EnvMatrix.
105-
// They key is arbitrary string and the value is a list of KEY=value pairs to exclude.
105+
// The key is arbitrary string and the value is a list of KEY=value pairs to exclude.
106106
// For example:
107107
// EnvMatrixExclude.noplantf = ["READPLAN=1", "DATABRICKS_BUNDLE_ENGINE=terraform"]
108+
// Special pseudo-var CONFIG_Cloud=true is available for excluding combinations on cloud runs.
108109
EnvMatrixExclude map[string][]string
109110

110111
// List of keys for which to do string replacement value -> [KEY]. If not set, defaults to true.
@@ -262,7 +263,9 @@ func (t mapTransformer) Transformer(typ reflect.Type) func(dst, src reflect.Valu
262263
//
263264
// If any entries is an empty list, that variable is dropped from the matrix before processing.
264265
// The exclude parameter specifies combinations to exclude from the result.
265-
func ExpandEnvMatrix(matrix, exclude map[string][]string) [][]string {
266+
// The extraVars parameter specifies additional env vars to include for exclusion matching only;
267+
// they are stripped from the final result.
268+
func ExpandEnvMatrix(matrix, exclude map[string][]string, extraVars []string) [][]string {
266269
result := [][]string{{}}
267270

268271
if len(matrix) == 0 {
@@ -307,11 +310,35 @@ func ExpandEnvMatrix(matrix, exclude map[string][]string) [][]string {
307310
result = newResult
308311
}
309312

313+
// Add extraVars to each envset for exclusion matching
314+
if len(extraVars) > 0 {
315+
for i := range result {
316+
result[i] = append(result[i], extraVars...)
317+
}
318+
}
319+
310320
// Filter out excluded combinations
311321
if len(exclude) > 0 {
312322
result = filterExcludedEnvSets(result, exclude)
313323
}
314324

325+
// Strip extraVars from the final result
326+
if len(extraVars) > 0 {
327+
extraSet := make(map[string]bool, len(extraVars))
328+
for _, v := range extraVars {
329+
extraSet[v] = true
330+
}
331+
for i, envset := range result {
332+
filtered := envset[:0]
333+
for _, kv := range envset {
334+
if !extraSet[kv] {
335+
filtered = append(filtered, kv)
336+
}
337+
}
338+
result[i] = filtered
339+
}
340+
}
341+
315342
return result
316343
}
317344

acceptance/internal/config_test.go

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import (
88

99
func TestExpandEnvMatrix(t *testing.T) {
1010
tests := []struct {
11-
name string
12-
matrix map[string][]string
13-
exclude map[string][]string
14-
expected [][]string
11+
name string
12+
matrix map[string][]string
13+
exclude map[string][]string
14+
extraVars []string
15+
expected [][]string
1516
}{
1617
{
1718
name: "empty matrix",
@@ -160,11 +161,38 @@ func TestExpandEnvMatrix(t *testing.T) {
160161
{"KEY1=A"},
161162
},
162163
},
164+
{
165+
name: "extraVars used for exclusion matching but stripped from result",
166+
matrix: map[string][]string{
167+
"KEY": {"A", "B"},
168+
},
169+
exclude: map[string][]string{
170+
"rule1": {"KEY=A", "CONFIG_Cloud=true"},
171+
},
172+
extraVars: []string{"CONFIG_Cloud=true"},
173+
expected: [][]string{
174+
{"KEY=B"},
175+
},
176+
},
177+
{
178+
name: "extraVars not matching exclusion rule",
179+
matrix: map[string][]string{
180+
"KEY": {"A", "B"},
181+
},
182+
exclude: map[string][]string{
183+
"rule1": {"KEY=A", "CONFIG_Cloud=true"},
184+
},
185+
extraVars: nil,
186+
expected: [][]string{
187+
{"KEY=A"},
188+
{"KEY=B"},
189+
},
190+
},
163191
}
164192

165193
for _, tt := range tests {
166194
t.Run(tt.name, func(t *testing.T) {
167-
result := ExpandEnvMatrix(tt.matrix, tt.exclude)
195+
result := ExpandEnvMatrix(tt.matrix, tt.exclude, tt.extraVars)
168196
assert.Equal(t, tt.expected, result)
169197
})
170198
}

0 commit comments

Comments
 (0)