From 2033a71843e5756aac9e3244708cbdfd27e88a87 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Fri, 30 Jan 2026 15:08:27 +0100 Subject: [PATCH 1/3] wip --- acceptance/acceptance_test.go | 10 +++++- acceptance/bundle/invariant/test.toml | 3 ++ acceptance/internal/config.go | 50 ++++++++++++++++++++++++-- acceptance/internal/config_test.go | 52 ++++++++++++++++++++++++--- 4 files changed, 107 insertions(+), 8 deletions(-) diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index 07a4fc1763..a185cfdcf3 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -337,7 +337,15 @@ func testAccept(t *testing.T, inprocessMode bool, singleTest string) int { t.Parallel() } - expanded := internal.ExpandEnvMatrix(config.EnvMatrix, config.EnvMatrixExclude) + // Build extra vars for exclusion matching (config state as env vars) + var extraVars []string + if cloudEnv != "" { + extraVars = append(extraVars, "CONFIG_Cloud=true") + } else { + extraVars = append(extraVars, "CONFIG_Local=true") + } + + expanded := internal.ExpandEnvMatrix(config.EnvMatrix, config.EnvMatrixExclude, extraVars) if len(expanded) == 1 { // env vars aren't part of the test case name, so log them for debugging diff --git a/acceptance/bundle/invariant/test.toml b/acceptance/bundle/invariant/test.toml index 01c885b02e..93282bda60 100644 --- a/acceptance/bundle/invariant/test.toml +++ b/acceptance/bundle/invariant/test.toml @@ -36,6 +36,9 @@ EnvMatrix.INPUT_CONFIG = [ "volume.yml.tmpl", ] +[EnvMatrixExclude] +no_alert_on_cloud = ["CONFIG_Cloud=true", "INPUT_CONFIG=alert.yml.tmpl"] + # Fake SQL endpoint for local tests [[Server]] Pattern = "POST /api/2.0/sql/statements/" diff --git a/acceptance/internal/config.go b/acceptance/internal/config.go index afa13a0d8e..f93709d4ce 100644 --- a/acceptance/internal/config.go +++ b/acceptance/internal/config.go @@ -102,9 +102,12 @@ type TestConfig struct { // Environment variables matrix exclusion list. // Exclude certain configuration from the grid generated by EnvMatrix. - // They key is arbitrary string and the value is a list of KEY=value pairs to exclude. + // The key is arbitrary string and the value is a list of KEY=value pairs to exclude. // For example: // EnvMatrixExclude.noplantf = ["READPLAN=1", "DATABRICKS_BUNDLE_ENGINE=terraform"] + // Special pseudo-vars are available for matching test config state: + // CONFIG_Cloud=true - matches when running in cloud mode (CLOUD_ENV is set) + // CONFIG_Local=true - matches when running in local mode (CLOUD_ENV is not set) EnvMatrixExclude map[string][]string // List of keys for which to do string replacement value -> [KEY]. If not set, defaults to true. @@ -262,10 +265,22 @@ func (t mapTransformer) Transformer(typ reflect.Type) func(dst, src reflect.Valu // // If any entries is an empty list, that variable is dropped from the matrix before processing. // The exclude parameter specifies combinations to exclude from the result. -func ExpandEnvMatrix(matrix, exclude map[string][]string) [][]string { +// The extraVars parameter specifies additional env vars to include for exclusion matching only; +// they are stripped from the final result. +func ExpandEnvMatrix(matrix, exclude map[string][]string, extraVars []string) [][]string { result := [][]string{{}} if len(matrix) == 0 { + if len(exclude) > 0 && len(extraVars) > 0 { + // Even with empty matrix, we need to check if the single empty result + // should be excluded based on extraVars + result[0] = append(result[0], extraVars...) + result = filterExcludedEnvSets(result, exclude) + // Strip extraVars from result + for i := range result { + result[i] = []string{} + } + } return result } @@ -278,6 +293,13 @@ func ExpandEnvMatrix(matrix, exclude map[string][]string) [][]string { } if len(filteredMatrix) == 0 { + if len(exclude) > 0 && len(extraVars) > 0 { + result[0] = append(result[0], extraVars...) + result = filterExcludedEnvSets(result, exclude) + for i := range result { + result[i] = []string{} + } + } return result } @@ -307,11 +329,35 @@ func ExpandEnvMatrix(matrix, exclude map[string][]string) [][]string { result = newResult } + // Add extraVars to each envset for exclusion matching + if len(extraVars) > 0 { + for i := range result { + result[i] = append(result[i], extraVars...) + } + } + // Filter out excluded combinations if len(exclude) > 0 { result = filterExcludedEnvSets(result, exclude) } + // Strip extraVars from the final result + if len(extraVars) > 0 { + extraSet := make(map[string]bool, len(extraVars)) + for _, v := range extraVars { + extraSet[v] = true + } + for i, envset := range result { + filtered := envset[:0] + for _, kv := range envset { + if !extraSet[kv] { + filtered = append(filtered, kv) + } + } + result[i] = filtered + } + } + return result } diff --git a/acceptance/internal/config_test.go b/acceptance/internal/config_test.go index ea06335c5d..16fa597644 100644 --- a/acceptance/internal/config_test.go +++ b/acceptance/internal/config_test.go @@ -8,10 +8,11 @@ import ( func TestExpandEnvMatrix(t *testing.T) { tests := []struct { - name string - matrix map[string][]string - exclude map[string][]string - expected [][]string + name string + matrix map[string][]string + exclude map[string][]string + extraVars []string + expected [][]string }{ { name: "empty matrix", @@ -160,11 +161,52 @@ func TestExpandEnvMatrix(t *testing.T) { {"KEY1=A"}, }, }, + { + name: "extraVars used for exclusion matching but stripped from result", + matrix: map[string][]string{ + "KEY": {"A", "B"}, + }, + exclude: map[string][]string{ + "rule1": {"KEY=A", "CONFIG_Cloud=true"}, + }, + extraVars: []string{"CONFIG_Cloud=true"}, + expected: [][]string{ + {"KEY=B"}, + }, + }, + { + name: "extraVars not matching exclusion rule", + matrix: map[string][]string{ + "KEY": {"A", "B"}, + }, + exclude: map[string][]string{ + "rule1": {"KEY=A", "CONFIG_Cloud=true"}, + }, + extraVars: []string{"CONFIG_Local=true"}, + expected: [][]string{ + {"KEY=A"}, + {"KEY=B"}, + }, + }, + { + name: "extraVars with empty matrix and exclusion", + matrix: map[string][]string{}, + exclude: map[string][]string{"rule1": {"CONFIG_Cloud=true"}}, + extraVars: []string{"CONFIG_Cloud=true"}, + expected: nil, + }, + { + name: "extraVars with empty matrix no exclusion match", + matrix: map[string][]string{}, + exclude: map[string][]string{"rule1": {"CONFIG_Cloud=true"}}, + extraVars: []string{"CONFIG_Local=true"}, + expected: [][]string{{}}, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - result := ExpandEnvMatrix(tt.matrix, tt.exclude) + result := ExpandEnvMatrix(tt.matrix, tt.exclude, tt.extraVars) assert.Equal(t, tt.expected, result) }) } From b080d7b278a73e574de7435d969d763578869039 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Fri, 30 Jan 2026 15:57:33 +0100 Subject: [PATCH 2/3] clean up --- acceptance/internal/config.go | 17 ----------------- acceptance/internal/config_test.go | 14 -------------- 2 files changed, 31 deletions(-) diff --git a/acceptance/internal/config.go b/acceptance/internal/config.go index f93709d4ce..9a11136d7c 100644 --- a/acceptance/internal/config.go +++ b/acceptance/internal/config.go @@ -271,16 +271,6 @@ func ExpandEnvMatrix(matrix, exclude map[string][]string, extraVars []string) [] result := [][]string{{}} if len(matrix) == 0 { - if len(exclude) > 0 && len(extraVars) > 0 { - // Even with empty matrix, we need to check if the single empty result - // should be excluded based on extraVars - result[0] = append(result[0], extraVars...) - result = filterExcludedEnvSets(result, exclude) - // Strip extraVars from result - for i := range result { - result[i] = []string{} - } - } return result } @@ -293,13 +283,6 @@ func ExpandEnvMatrix(matrix, exclude map[string][]string, extraVars []string) [] } if len(filteredMatrix) == 0 { - if len(exclude) > 0 && len(extraVars) > 0 { - result[0] = append(result[0], extraVars...) - result = filterExcludedEnvSets(result, exclude) - for i := range result { - result[i] = []string{} - } - } return result } diff --git a/acceptance/internal/config_test.go b/acceptance/internal/config_test.go index 16fa597644..fa3c164d3b 100644 --- a/acceptance/internal/config_test.go +++ b/acceptance/internal/config_test.go @@ -188,20 +188,6 @@ func TestExpandEnvMatrix(t *testing.T) { {"KEY=B"}, }, }, - { - name: "extraVars with empty matrix and exclusion", - matrix: map[string][]string{}, - exclude: map[string][]string{"rule1": {"CONFIG_Cloud=true"}}, - extraVars: []string{"CONFIG_Cloud=true"}, - expected: nil, - }, - { - name: "extraVars with empty matrix no exclusion match", - matrix: map[string][]string{}, - exclude: map[string][]string{"rule1": {"CONFIG_Cloud=true"}}, - extraVars: []string{"CONFIG_Local=true"}, - expected: [][]string{{}}, - }, } for _, tt := range tests { From b7331f2b004f1899a4267a581085067c3005cbed Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Fri, 30 Jan 2026 16:00:42 +0100 Subject: [PATCH 3/3] clean up --- acceptance/acceptance_test.go | 2 -- acceptance/internal/config.go | 4 +--- acceptance/internal/config_test.go | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index a185cfdcf3..0c5b43ed66 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -341,8 +341,6 @@ func testAccept(t *testing.T, inprocessMode bool, singleTest string) int { var extraVars []string if cloudEnv != "" { extraVars = append(extraVars, "CONFIG_Cloud=true") - } else { - extraVars = append(extraVars, "CONFIG_Local=true") } expanded := internal.ExpandEnvMatrix(config.EnvMatrix, config.EnvMatrixExclude, extraVars) diff --git a/acceptance/internal/config.go b/acceptance/internal/config.go index 9a11136d7c..fbf1ce3807 100644 --- a/acceptance/internal/config.go +++ b/acceptance/internal/config.go @@ -105,9 +105,7 @@ type TestConfig struct { // The key is arbitrary string and the value is a list of KEY=value pairs to exclude. // For example: // EnvMatrixExclude.noplantf = ["READPLAN=1", "DATABRICKS_BUNDLE_ENGINE=terraform"] - // Special pseudo-vars are available for matching test config state: - // CONFIG_Cloud=true - matches when running in cloud mode (CLOUD_ENV is set) - // CONFIG_Local=true - matches when running in local mode (CLOUD_ENV is not set) + // Special pseudo-var CONFIG_Cloud=true is available for excluding combinations on cloud runs. EnvMatrixExclude map[string][]string // List of keys for which to do string replacement value -> [KEY]. If not set, defaults to true. diff --git a/acceptance/internal/config_test.go b/acceptance/internal/config_test.go index fa3c164d3b..c2701337f5 100644 --- a/acceptance/internal/config_test.go +++ b/acceptance/internal/config_test.go @@ -182,7 +182,7 @@ func TestExpandEnvMatrix(t *testing.T) { exclude: map[string][]string{ "rule1": {"KEY=A", "CONFIG_Cloud=true"}, }, - extraVars: []string{"CONFIG_Local=true"}, + extraVars: nil, expected: [][]string{ {"KEY=A"}, {"KEY=B"},