diff --git a/tests/integration/results.go b/tests/integration/results.go index b082a4c04d..76b5db815c 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" @@ -79,6 +80,41 @@ func areResultsAnyOf(expected AnyOf, actual any) bool { return false } +type UniqueCid struct { + ID any +} + +var _ Validator = (*UniqueCid)(nil) + +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() + } +} + // areResultsEqual returns true if the expected and actual results are of equal value. // // Values of type json.Number and immutable.Option will be reduced to their underlying types. 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, }