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

diag: Consider Equal() method for Diagnostics #397

Closed
bflad opened this issue Jun 29, 2022 · 1 comment · Fixed by #402
Closed

diag: Consider Equal() method for Diagnostics #397

bflad opened this issue Jun 29, 2022 · 1 comment · Fixed by #402
Assignees
Labels
diags Issues and pull requests about our diagnostics abstraction. enhancement New feature or request
Milestone

Comments

@bflad
Copy link
Contributor

bflad commented Jun 29, 2022

Module version

v0.9.0

Use-cases

Downstream code may desire to do equality checking of diag.Diagnostics, such as unit testing responses from various framework functionality. In particular,

Most Go modules that implement checking of this sort, such as https://pkg.go.dev/github.com/google/go-cmp, will prefer an Equal() method on a Go type if it exists. Otherwise they will fallback to other methods, such as type and field inspection, which are more difficult to manage (e.g. differences between diag.ErrorDiagnostic/diag.WarningDiagnostic and diag.withPath) in some cases are not possible to test outside the framework (internal/reflect.DiagIntoIncompatibleType).

Attempted Solutions

Using go-cmp with diag.Diagnostics types and skipping unit testing where problematic.

Proposal

The diag.Diagnostic interface already requires an Equal() method that handles severity, summary, and detail equality, so all that is necessary would be implementing an Equal() method on the diag.Diagnostics type alias as well.

References

Not sure if this would affect #217.

@bflad bflad added enhancement New feature or request diags Issues and pull requests about our diagnostics abstraction. tf-devex-triage labels Jun 29, 2022
@bflad bflad self-assigned this Jul 7, 2022
bflad added a commit that referenced this issue Jul 7, 2022
Reference: #397

This should help simplify downstream code wishing use testing libraries that perform equality checks based on types that implement `Equal()` methods, such as [`go-cmp`](https://pkg.go.dev/github.com/google/go-cmp).
@bflad bflad added this to the v0.10.0 milestone Jul 8, 2022
@bflad bflad closed this as completed in #402 Jul 8, 2022
bflad added a commit that referenced this issue Jul 8, 2022
Reference: #397

This should help simplify downstream code wishing use testing libraries that perform equality checks based on types that implement `Equal()` methods, such as [`go-cmp`](https://pkg.go.dev/github.com/google/go-cmp).
@github-actions
Copy link

github-actions bot commented Aug 8, 2022

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
diags Issues and pull requests about our diagnostics abstraction. enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant