From ecf5a34b63ffca814efac7bdde0822e9c8f97b62 Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Thu, 24 Oct 2024 14:42:47 -0400 Subject: [PATCH] WIP - add support --- tests/integration/results.go | 40 ++++++++++++++++++++++++++++++++++++ tests/integration/state.go | 3 +++ tests/integration/utils.go | 9 ++++++-- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/tests/integration/results.go b/tests/integration/results.go index cc54565fe8..4487df6fdc 100644 --- a/tests/integration/results.go +++ b/tests/integration/results.go @@ -16,6 +16,7 @@ import ( "testing" "time" + "github.com/ipfs/go-cid" "github.com/sourcenetwork/immutable" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -227,3 +228,42 @@ func assertCollectionDescriptions( } } } + +////////////////////////////////////// + +type Foo interface { // probs not needed + Validate(s *state, actualValue any) +} + +type UniqueCid struct { + ID any +} + +func NewUniqueCid(id any) UniqueCid { + return UniqueCid{ + ID: id, + } +} + +func (ucid *UniqueCid) Validate(s *state, actualValue any, msgAndArgs ...any) { + isNew := true + for id, value := range s.cids { + if id == ucid.ID { + require.Equal(s.t, value, actualValue) + isNew = false + } else { + require.NotEqual(s.t, value, actualValue, "UniqueCid must be unique!", msgAndArgs) + } + } + + if isNew { + require.IsType(s.t, "", actualValue) + + cid, err := cid.Decode(actualValue.(string)) + if err != nil { + require.NoError(s.t, err) + } + + s.cids[ucid.ID] = cid.String() + } +} diff --git a/tests/integration/state.go b/tests/integration/state.go index 9e65458531..045b8b0de1 100644 --- a/tests/integration/state.go +++ b/tests/integration/state.go @@ -175,6 +175,8 @@ type state struct { // nodes. docIDs [][]client.DocID + cids map[any]string + // Indexes, by index, by collection index, by node index. indexes [][][]client.IndexDescription @@ -218,6 +220,7 @@ func newState( collectionNames: collectionNames, collectionIndexesByRoot: map[uint32]int{}, docIDs: [][]client.DocID{}, + cids: map[any]string{}, indexes: [][][]client.IndexDescription{}, isBench: false, } diff --git a/tests/integration/utils.go b/tests/integration/utils.go index 05698e9a39..d70d59bf94 100644 --- a/tests/integration/utils.go +++ b/tests/integration/utils.go @@ -2067,6 +2067,8 @@ func assertRequestResultDocs( for field, actualValue := range actualDoc { stack.pushMap(field) + pathInfo := fmt.Sprintf("node: %v, path: %s", nodeID, stack) + switch expectedValue := expectedDoc[field].(type) { case AnyOf: assertResultsAnyOf(s.t, s.clientType, expectedValue, actualValue) @@ -2077,7 +2079,7 @@ func assertRequestResultDocs( s.clientType, expectedDocID, actualValue, - fmt.Sprintf("node: %v, path: %s", nodeID, stack), + pathInfo, ) case []map[string]any: actualValueMap := ConvertToArrayOfMaps(s.t, actualValue) @@ -2090,13 +2092,16 @@ func assertRequestResultDocs( stack, ) + case UniqueCid: + expectedValue.Validate(s, actualValue, pathInfo) + default: assertResultsEqual( s.t, s.clientType, expectedValue, actualValue, - fmt.Sprintf("node: %v, path: %s", nodeID, stack), + pathInfo, ) } stack.pop()