github.com/opentofu/opentofu@v1.7.1/internal/backend/remote-state/s3/testing_test.go (about)

     1  // Copyright (c) The OpenTofu Authors
     2  // SPDX-License-Identifier: MPL-2.0
     3  // Copyright (c) 2023 HashiCorp, Inc.
     4  // SPDX-License-Identifier: MPL-2.0
     5  
     6  package s3
     7  
     8  import (
     9  	"github.com/opentofu/opentofu/internal/tfdiags"
    10  )
    11  
    12  // diagnosticComparer is a Comparer function for use with cmp.Diff to compare two tfdiags.Diagnostic values
    13  func diagnosticComparer(l, r tfdiags.Diagnostic) bool {
    14  	if l.Severity() != r.Severity() {
    15  		return false
    16  	}
    17  	if l.Description() != r.Description() {
    18  		return false
    19  	}
    20  
    21  	lp := tfdiags.GetAttribute(l)
    22  	rp := tfdiags.GetAttribute(r)
    23  	if len(lp) != len(rp) {
    24  		return false
    25  	}
    26  	return lp.Equals(rp)
    27  }
    28  
    29  // diagnosticSummaryComparer is a Comparer function for use with cmp.Diff to compare
    30  // the Severity and Summary fields two tfdiags.Diagnostic values
    31  func diagnosticSummaryComparer(l, r tfdiags.Diagnostic) bool {
    32  	if l.Severity() != r.Severity() {
    33  		return false
    34  	}
    35  
    36  	ld := l.Description()
    37  	rd := r.Description()
    38  	return ld.Summary == rd.Summary
    39  }