diff --git a/internal/configs/module_test.go b/internal/configs/module_test.go index c4fc7b4713..f30b21d65c 100644 --- a/internal/configs/module_test.go +++ b/internal/configs/module_test.go @@ -551,7 +551,12 @@ func TestModule_conflicting_backend_cloud_stateStore(t *testing.T) { t.Fatal("module should have error diags, but does not") } - if got := diags.Error(); !strings.Contains(got, tc.wantMsg) { + if tc.allowExperiments { + if len(diags) != 2 && len(diags.Errs()) != 1 { + t.Fatalf("expected 2 diagnostics (1 error, 1 warning), but got: %#v", diags) + } + } + if got := diags.Errs()[0]; !strings.Contains(got.Error(), tc.wantMsg) { t.Fatalf("expected error to contain %q\nerror was:\n%s", tc.wantMsg, got) } }) @@ -674,9 +679,13 @@ func TestModule_state_store_multiple(t *testing.T) { if !diags.HasErrors() { t.Fatal("module should have error diags, but does not") } + if len(diags.Errs()) != 1 { + t.Fatalf("expected 1 error, but received %d", len(diags.Errs())) + } want := `Duplicate 'state_store' configuration block` - if got := diags.Error(); !strings.Contains(got, want) { + err := diags.Errs()[0] + if got := err.Error(); !strings.Contains(got, want) { t.Fatalf("expected error to contain %q\nerror was:\n%s", want, got) } }) diff --git a/internal/configs/parser_config_dir_test.go b/internal/configs/parser_config_dir_test.go index 2fe176ca68..bccc3dbc84 100644 --- a/internal/configs/parser_config_dir_test.go +++ b/internal/configs/parser_config_dir_test.go @@ -36,11 +36,16 @@ func TestParserLoadConfigDirSuccess(t *testing.T) { t.Run(name, func(t *testing.T) { parser := NewParser(nil) + var expectWarning bool if strings.Contains(name, "state-store") { // The PSS project is currently gated as experimental // TODO(SarahFrench/radeksimko) - remove this from the test once // the feature is GA. parser.allowExperiments = true + + // While the feature is experimental a warning will always be returned + // about the feature. + expectWarning = true } path := filepath.Join("testdata/valid-modules", name) @@ -73,8 +78,20 @@ func TestParserLoadConfigDirSuccess(t *testing.T) { } diags = filterDiags } - if len(diags) != 0 { - t.Errorf("unexpected diagnostics") + if diags.HasErrors() { + t.Errorf("unexpected error diagnostics") + for _, diag := range diags.Errs() { + t.Logf("- %s", diag) + } + } + if !expectWarning && len(diags) != 0 { + t.Errorf("unexpected diagnostics: expected no warnings") + for _, diag := range diags { + t.Logf("- %s", diag) + } + } + if expectWarning && len(diags) != 1 { + t.Errorf("unexpected diagnostics: expected a single warning") for _, diag := range diags { t.Logf("- %s", diag) }