Skip to content
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

Add testing helpers that allow comparing diagnostics, refactor existing tests to use them. #36456

Draft
wants to merge 7 commits into
base: sarah/diags-comparisons
Choose a base branch
from

Conversation

SarahFrench
Copy link
Member

@SarahFrench SarahFrench commented Feb 6, 2025

⚠️ This is a stacked PR, please look at #36455 ⚠️

This PR introduces testing helpers for comparing diagnostics in the tfdiags package.

Summary:

  • There was a pre-existing helper in the terraform package -assertDiagnosticsMatch- that I've replaced in this PR.
  • I've replaced use of cmp.Diff(want, got, DiagnosticComparer) with the helper that does that internally
  • I've refactored code that purposefully converted Diagnostics to RPC-friendly versions into using the new helper, as the helper does that internally

Open questions:

  • Which tests would want to check Sources?
  • Which tests would want to assert the concrete type of a returned diagnostic?

In future these could also be consolidated and brought into the tfdiags package:

  • assertDiagnosticSummary
    • func assertDiagnosticSummary(t *testing.T, diags hcl.Diagnostics, want string) bool {...} - implemented once
    • func assertDiagnosticSummary(t *testing.T, diags tfdiags.Diagnostics, want string) bool {...} - implemented once
  • assertDiagnosticCount
    • func assertDiagnosticCount(t *testing.T, diags hcl.Diagnostics, want int) bool {...} - implemented in 2 places
    • func assertDiagnosticCount(t *testing.T, diags tfdiags.Diagnostics, want int) bool {...} - implemented once
  • assertNoDiagnostics
    • func assertNoDiagnostics(t *testing.T, diags hcl.Diagnostics) bool {...} - implemented in 2 places
    • func assertNoDiagnostics(t *testing.T, diags tfdiags.Diagnostics) {...} - implemented in 2 places
    • func assertNoDiagnostics(t *testing.T, diags tfdiags.Diagnostics) bool {...} - implemented once
  • assertExactDiagnostics
    • This is only implemented and used in package configs so this would be something to leave unchanged.
  • assertNoErrors
    • func assertNoErrors(t *testing.T, diags tfdiags.Diagnostics) {...} - implemented twice

Target Release

N/A

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

@SarahFrench SarahFrench added the no-changelog-needed Add this to your PR if the change does not require a changelog entry label Feb 6, 2025
@SarahFrench SarahFrench changed the title Sarah/diags comparisons refactor Add testing helpers that allow comparing diagnostics, refactor existing tests to use them. Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog-needed Add this to your PR if the change does not require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant