From ac6a5602ad6c79fdf16e7b50f623568f85341ea2 Mon Sep 17 00:00:00 2001 From: Michael Shaw Date: Wed, 25 Jan 2023 15:05:48 -0500 Subject: [PATCH] utils/json test for comparing known, but deprecated method to new implementation --- utils/json.go | 1 - utils/json_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 utils/json_test.go diff --git a/utils/json.go b/utils/json.go index 31a4d67c..5bb934ba 100644 --- a/utils/json.go +++ b/utils/json.go @@ -105,6 +105,5 @@ func CIDFromJSONBytesUsingIpldPrime(content []byte) (string, error) { if err != nil { return "", err } - // return cborcid.String(), nil return lnk.String(), nil } diff --git a/utils/json_test.go b/utils/json_test.go new file mode 100644 index 00000000..f44ed47d --- /dev/null +++ b/utils/json_test.go @@ -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) + } +}