github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/backend/remote-state/s3/testing_test.go (about)

     1  package s3
     2  
     3  import (
     4  	"github.com/terramate-io/tf/tfdiags"
     5  )
     6  
     7  // diagnosticComparer is a Comparer function for use with cmp.Diff to compare two tfdiags.Diagnostic values
     8  func diagnosticComparer(l, r tfdiags.Diagnostic) bool {
     9  	if l.Severity() != r.Severity() {
    10  		return false
    11  	}
    12  	if l.Description() != r.Description() {
    13  		return false
    14  	}
    15  
    16  	lp := tfdiags.GetAttribute(l)
    17  	rp := tfdiags.GetAttribute(r)
    18  	if len(lp) != len(rp) {
    19  		return false
    20  	}
    21  	return lp.Equals(rp)
    22  }
    23  
    24  // diagnosticSummaryComparer is a Comparer function for use with cmp.Diff to compare
    25  // the Severity and Summary fields two tfdiags.Diagnostic values
    26  func diagnosticSummaryComparer(l, r tfdiags.Diagnostic) bool {
    27  	if l.Severity() != r.Severity() {
    28  		return false
    29  	}
    30  
    31  	ld := l.Description()
    32  	rd := r.Description()
    33  	return ld.Summary == rd.Summary
    34  }