Skip to content

Commit

Permalink
add support for clients that json marshal results
Browse files Browse the repository at this point in the history
  • Loading branch information
fredcarle committed Feb 12, 2024
1 parent b7adcae commit cd4cb94
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tests/integration/query/commits/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package tests

import (
"encoding/base64"
"encoding/json"
"testing"
"time"
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/utils2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

0 comments on commit cd4cb94

Please sign in to comment.