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 bb0917e commit ecf5a34
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
40 changes: 40 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 @@ -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()
}
}
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
9 changes: 7 additions & 2 deletions tests/integration/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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()
Expand Down

0 comments on commit ecf5a34

Please sign in to comment.