All test stuff #88
@ -105,6 +105,5 @@ func CIDFromJSONBytesUsingIpldPrime(content []byte) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
// return cborcid.String(), nil
|
|
||||||
return lnk.String(), nil
|
return lnk.String(), nil
|
||||||
}
|
}
|
||||||
|
30
utils/json_test.go
Normal file
30
utils/json_test.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAndValidateCIDGeneration(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
content string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"empty string", "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"empty json", "{}",
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"test record", "\\xa6curlohttps://cerc.iodtypex\\x19WebsiteRegistrationRecordgversione0.0.1ltls_cert_cidx.QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnRrbuild_artifact_cidx.QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9x\\x1crepo_registration_record_cidx.QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
deprecatedAndCorrect, _ := CIDFromJSONBytes([]byte(tc.content))
|
||||||
|
newImpl, _ := CIDFromJSONBytesUsingIpldPrime([]byte(tc.content))
|
||||||
|
require.Equal(t, deprecatedAndCorrect, newImpl, tc.name)
|
||||||
|
}
|
||||||
|
|||||||
|
}
|
Loading…
Reference in New Issue
Block a user
We should either
require.NoError()
the errors returned by these functions or make sure the returned result isn't nil/empty, because if both functions were to error out and return a nil/empty result it would evaluate them as equal and the test would pass.Also, ideally we'd have a static fixture for what the expected CID is for some input content- so that if both functions are updated in the same change set we can be certain we didn't break them but in the same way such that this test still passes.
But, since we will be getting rid of
CIDFromJSONBytes
soon we shouldn't do that here. Once we get rid ofCIDFromJSONBytes
, we will have to test against a static fixture.