From cd4cb94a1a806dffa57540a23b27295587df530a Mon Sep 17 00:00:00 2001 From: Fred Carle Date: Mon, 12 Feb 2024 13:54:43 -0500 Subject: [PATCH] add support for clients that json marshal results --- tests/integration/query/commits/simple_test.go | 6 +++--- tests/integration/results.go | 3 +++ tests/integration/utils2.go | 9 +++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/integration/query/commits/simple_test.go b/tests/integration/query/commits/simple_test.go index 2b307e4366..743af2debe 100644 --- a/tests/integration/query/commits/simple_test.go +++ b/tests/integration/query/commits/simple_test.go @@ -351,7 +351,7 @@ func TestQuery_CommitsWithAllFieldsWithUpdate_NoError(t *testing.T) { { "cid": "bafybeiddpjl27ulw2yo4ohup6gr2wob3pwagqw2rbeaxxodv4ljelnu7ve", "collectionID": int64(1), - "delta": []uint8([]byte{0x16}), + "delta": testUtils.CBORField(22), "docID": "bae-f54b9689-e06e-5e3a-89b3-f3aee8e64ca7", "fieldId": "1", "fieldName": "age", @@ -366,7 +366,7 @@ func TestQuery_CommitsWithAllFieldsWithUpdate_NoError(t *testing.T) { { "cid": "bafybeieikx6l2xead2dzsa5wwy5irxced2eddyq23jkp4csf5igoob7diq", "collectionID": int64(1), - "delta": []uint8([]byte{0x15}), + "delta": testUtils.CBORField(21), "docID": "bae-f54b9689-e06e-5e3a-89b3-f3aee8e64ca7", "fieldId": "1", "fieldName": "age", @@ -376,7 +376,7 @@ func TestQuery_CommitsWithAllFieldsWithUpdate_NoError(t *testing.T) { { "cid": "bafybeiehcr3diremeja2ndk2osux647v5fc7s353h7pbvrnsagw4paugku", "collectionID": int64(1), - "delta": []uint8([]byte{0x64, 0x4a, 0x6f, 0x68, 0x6e}), + "delta": testUtils.CBORField("John"), "docID": "bae-f54b9689-e06e-5e3a-89b3-f3aee8e64ca7", "fieldId": "2", "fieldName": "name", diff --git a/tests/integration/results.go b/tests/integration/results.go index df21acef30..20270af1c4 100644 --- a/tests/integration/results.go +++ b/tests/integration/results.go @@ -11,6 +11,7 @@ package tests import ( + "encoding/base64" "encoding/json" "testing" "time" @@ -116,6 +117,8 @@ func areResultsEqual(expected any, actual any) bool { return areResultOptionsEqual(expectedVal, actual) case immutable.Option[string]: return areResultOptionsEqual(expectedVal, actual) + case []uint8: + return areResultsEqual(base64.StdEncoding.EncodeToString(expectedVal), actual) case []int64: return areResultArraysEqual(expectedVal, actual) case []uint64: diff --git a/tests/integration/utils2.go b/tests/integration/utils2.go index e90a24dd59..e7396336d2 100644 --- a/tests/integration/utils2.go +++ b/tests/integration/utils2.go @@ -20,6 +20,7 @@ import ( "time" "github.com/bxcodec/faker/support/slice" + "github.com/fxamacker/cbor/v2" "github.com/libp2p/go-libp2p/core/crypto" "github.com/sourcenetwork/immutable" "github.com/stretchr/testify/assert" @@ -1953,3 +1954,11 @@ func MustParseTime(timeString string) time.Time { } return t } + +func CBORField(value any) []byte { + enc, err := cbor.Marshal(value) + if err != nil { + panic(err) + } + return enc +}