mirror of https://github.com/hashicorp/terraform
Fix diagnostic comparison issues in `s3` backend tests (#37509)
* Fix S3 backend test affected by making the Workspaces method return errors via diagnostics * Address diagnostics comparison issues in test by ensuring expected diagnostics are defined in the context of the config they're triggered by * Fix failing test case `TestBackendConfig_EC2MetadataEndpoint/envvar_invalid_mode` by making `diagnosticBase` struct comparable * Add compile-time checks that diagnostic types fulfil interfaces * Stop diagnosticBase implementing ComparableDiagnostic, re-add S3-specific comparer code to s3 package * Update tests to use the S3-specific comparer again * Fix test case missed in refactoringpull/37496/head^2
parent
e854d8364d
commit
1c09e58b3d
@ -0,0 +1,28 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
package s3
|
||||
|
||||
import (
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/hashicorp/terraform/internal/tfdiags"
|
||||
)
|
||||
|
||||
var diagnosticComparer cmp.Option = cmp.Comparer(diagnosticComparerS3)
|
||||
|
||||
// diagnosticComparerS3 is a Comparer function for use with cmp.Diff to compare two tfdiags.Diagnostic values
|
||||
func diagnosticComparerS3(l, r tfdiags.Diagnostic) bool {
|
||||
if l.Severity() != r.Severity() {
|
||||
return false
|
||||
}
|
||||
if l.Description() != r.Description() {
|
||||
return false
|
||||
}
|
||||
|
||||
lp := tfdiags.GetAttribute(l)
|
||||
rp := tfdiags.GetAttribute(r)
|
||||
if len(lp) != len(rp) {
|
||||
return false
|
||||
}
|
||||
return lp.Equals(rp)
|
||||
}
|
||||
Loading…
Reference in new issue