Skip to content

diag: Consider Equal() method for Diagnostics #397

@bflad

Description

@bflad

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.

Metadata

Metadata

Assignees

Labels

diagsIssues and pull requests about our diagnostics abstraction.enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions