Skip to content

Commit

Permalink
WIP - add support
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Oct 24, 2024
1 parent 7f78282 commit a700cac
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/integration/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -218,6 +220,7 @@ func newState(
collectionNames: collectionNames,
collectionIndexesByRoot: map[uint32]int{},
docIDs: [][]client.DocID{},
cids: map[any]string{},
indexes: [][][]client.IndexDescription{},
isBench: false,
}
Expand Down

0 comments on commit a700cac

Please sign in to comment.