github.com/hyperledger/aries-framework-go@v0.3.2/pkg/doc/cm/common_test.go (about) 1 /* 2 Copyright SecureKey Technologies Inc. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package cm_test 8 9 import ( 10 "encoding/json" 11 "testing" 12 13 "github.com/stretchr/testify/require" 14 15 "github.com/hyperledger/aries-framework-go/pkg/doc/verifiable" 16 "github.com/hyperledger/aries-framework-go/pkg/internal/ldtestutil" 17 ) 18 19 const errorMessageTestNameFormat = "Test name: %s" 20 21 // Marshals the presentation and then unmarshals it again so that the type of the custom fields matches the type of 22 // the expected presentation - this allows us to use reflect.DeepEqual to compare them. 23 func marshalThenUnmarshalAgain(t *testing.T, presentation *verifiable.Presentation, 24 testName string) *verifiable.Presentation { 25 presentationBytes, err := json.Marshal(presentation) 26 require.NoError(t, err, errorMessageTestNameFormat, testName) 27 28 return makePresentationFromBytes(t, presentationBytes, testName) 29 } 30 31 func makePresentationFromBytes(t *testing.T, presentationBytes []byte, testName string) *verifiable.Presentation { 32 loader, err := ldtestutil.DocumentLoader() 33 require.NoError(t, err) 34 35 presentation, err := verifiable.ParsePresentation(presentationBytes, 36 verifiable.WithPresDisabledProofCheck(), 37 verifiable.WithPresJSONLDDocumentLoader(loader)) 38 require.NoError(t, err, errorMessageTestNameFormat, testName) 39 40 return presentation 41 }