diff --git a/tools/lib/report/report_test.go b/tools/lib/report/report_test.go index e486232..6c42113 100644 --- a/tools/lib/report/report_test.go +++ b/tools/lib/report/report_test.go @@ -23,12 +23,14 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" "github.com/google/go-sev-guest/abi" "github.com/google/go-sev-guest/client" spb "github.com/google/go-sev-guest/proto/sevsnp" test "github.com/google/go-sev-guest/testing" "google.golang.org/protobuf/encoding/prototext" "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/testing/protocmp" ) var qp client.QuoteProvider @@ -170,6 +172,18 @@ func TestReadAttestation(t *testing.T) { } } +func binAttestationDiff(left, right []byte) string { + leftp := &spb.Attestation{} + rightp := &spb.Attestation{} + if err := proto.Unmarshal(left, leftp); err != nil { + return fmt.Sprintf("left parse: %v", err) + } + if err := proto.Unmarshal(right, rightp); err != nil { + return fmt.Sprintf("right parse: %v", err) + } + return cmp.Diff(leftp, rightp, protocmp.Transform()) +} + func TestTransform(t *testing.T) { mu.Do(initDevice) t.Run("bin", func(t *testing.T) { @@ -186,8 +200,8 @@ func TestTransform(t *testing.T) { if err != nil { t.Fatalf("Transform(_, \"proto\") = _, %v. Expect nil.", err) } - if !bytes.Equal(protoout, input.protocerts) { - t.Fatalf("Transform(_, \"proto\") = %v, nil. Expect %v.", protoout, input.protocerts) + if diff := binAttestationDiff(protoout, input.protocerts); diff != "" { + t.Fatalf("Transform(_, \"proto\") = %v, nil. Expect %v.\nDiff: %s", protoout, input.protocerts, diff) } }) t.Run("textproto", func(t *testing.T) {