From d92b5e5f5e7cf9ed1e3b14e9073a6b4871a82f44 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 30 Jun 2021 10:25:50 -0700 Subject: [PATCH] configs: valid-modules test ignores experimental features warning A common source of churn when we're running experiments is that a module that would otherwise be valid ends up generating a warning merely because the experiment is active. That means we end up needing to shuffle the test files around if the feature ultimately graduates to stable. To reduce that churn in simple cases, we'll make an exception to disregard the "Experiment is active" warning for any experiment that a module has intentionally opted into, because those warnings are always expected and not a cause for concern. It's still possible to test those warnings explicitly using the testdata/warning-files directory, if needed. --- internal/configs/parser_config_dir_test.go | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/internal/configs/parser_config_dir_test.go b/internal/configs/parser_config_dir_test.go index c3c284aa6..da2f23c9f 100644 --- a/internal/configs/parser_config_dir_test.go +++ b/internal/configs/parser_config_dir_test.go @@ -5,6 +5,8 @@ import ( "io/ioutil" "path/filepath" "testing" + + "github.com/hashicorp/hcl/v2" ) // TestParseLoadConfigDirSuccess is a simple test that just verifies that @@ -31,6 +33,33 @@ func TestParserLoadConfigDirSuccess(t *testing.T) { path := filepath.Join("testdata/valid-modules", name) mod, diags := parser.LoadConfigDir(path) + if len(diags) != 0 && len(mod.ActiveExperiments) != 0 { + // As a special case to reduce churn while we're working + // through experimental features, we'll ignore the warning + // that an experimental feature is active if the module + // intentionally opted in to that feature. + // If you want to explicitly test for the feature warning + // to be generated, consider using testdata/warning-files + // instead. + filterDiags := make(hcl.Diagnostics, 0, len(diags)) + for _, diag := range diags { + if diag.Severity != hcl.DiagWarning { + continue + } + match := false + for exp := range mod.ActiveExperiments { + allowedSummary := fmt.Sprintf("Experimental feature %q is active", exp.Keyword()) + if diag.Summary == allowedSummary { + match = true + break + } + } + if !match { + filterDiags = append(filterDiags, diag) + } + } + diags = filterDiags + } if len(diags) != 0 { t.Errorf("unexpected diagnostics") for _, diag := range diags {