@@ -24,6 +24,7 @@ import (
2424 "github.com/hashicorp/terraform/internal/states/remote"
2525 "github.com/hashicorp/terraform/internal/states/statefile"
2626 "github.com/hashicorp/terraform/internal/states/statemgr"
27+ "github.com/hashicorp/terraform/internal/tfdiags"
2728)
2829
2930func TestRemoteClient_impl (t * testing.T ) {
@@ -385,10 +386,18 @@ func TestRemoteClient_stateChecksum(t *testing.T) {
385386
386387 // fetching an empty state through client1 should now error out due to a
387388 // mismatched checksum.
388- if _ , diags := client1 .Get (); ! IsA [badChecksumError ](diags .Err ()) {
389- t .Fatalf ("expected state checksum error: got %s" , diags .Err ())
390- } else if bse , ok := As [badChecksumError ](diags .Err ()); ok && len (bse .digest ) != 0 {
391- t .Fatalf ("expected empty checksum, got %x" , bse .digest )
389+ if _ , diags := client1 .Get (); diags .HasErrors () {
390+ var comparableErr error
391+ if errValue , isDiag := diags .Err ().(tfdiags.DiagnosticsAsError ); isDiag {
392+ // To use `As` below we need to extract the error that's wrapped
393+ // in a diagnostic.
394+ comparableErr = errValue .WrappedErrors ()[0 ]
395+ }
396+ if ! IsA [badChecksumError ](comparableErr ) {
397+ t .Fatalf ("expected state checksum error: got %s" , diags .Err ())
398+ } else if bse , ok := As [badChecksumError ](comparableErr ); ok && len (bse .digest ) != 0 {
399+ t .Fatalf ("expected empty checksum, got %x" , bse .digest )
400+ }
392401 }
393402
394403 // put the old state in place of the new, without updating the checksum
@@ -398,8 +407,16 @@ func TestRemoteClient_stateChecksum(t *testing.T) {
398407
399408 // fetching the wrong state through client1 should now error out due to a
400409 // mismatched checksum.
401- if _ , diags := client1 .Get (); ! IsA [badChecksumError ](diags .Err ()) {
402- t .Fatalf ("expected state checksum error: got %s" , diags .Err ())
410+ if _ , diags := client1 .Get (); diags .HasErrors () {
411+ var comparableErr error
412+ if errValue , isDiag := diags .Err ().(tfdiags.DiagnosticsAsError ); isDiag {
413+ // To use `As` below we need to extract the error that's wrapped
414+ // in a diagnostic.
415+ comparableErr = errValue .WrappedErrors ()[0 ]
416+ }
417+ if ! IsA [badChecksumError ](comparableErr ) {
418+ t .Fatalf ("expected state checksum error: got %s" , diags .Err ())
419+ }
403420 }
404421
405422 // update the state with the correct one after we Get again
0 commit comments