Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(i): Fix the nodes ID/index bug in tests #3162

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 20 additions & 136 deletions tests/integration/acp.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ func addPolicyACP(
require.Fail(s.t, "Expected error should not have an expected policyID with it.", s.testCase.Description)
}

for i, node := range getNodes(action.NodeID, s.nodes) {
identity := getIdentity(s, i, action.Identity)
nodeIDs, nodes := getNodesWithIDs(action.NodeID, s.nodes)
for index, node := range nodes {
nodeID := nodeIDs[index]
identity := getIdentity(s, nodeID, action.Identity)
ctx := db.SetContextIdentity(s.ctx, identity)
policyResult, err := node.AddPolicy(ctx, action.Policy)

Expand Down Expand Up @@ -183,16 +185,15 @@ func addDocActorRelationshipACP(
s *state,
action AddDocActorRelationship,
) {
if action.NodeID.HasValue() {
nodeID := action.NodeID.Value()
collections := s.collections[nodeID]
node := s.nodes[nodeID]
nodeIDs, nodes := getNodesWithIDs(action.NodeID, s.nodes)
for index, node := range nodes {
nodeID := nodeIDs[index]

var collectionName string
if action.CollectionID == -1 {
collectionName = ""
} else {
collection := collections[action.CollectionID]
collection := s.collections[nodeID][action.CollectionID]
if !collection.Description().Name.HasValue() {
require.Fail(s.t, "Expected non-empty collection name, but it was empty.", s.testCase.Description)
}
Expand Down Expand Up @@ -243,69 +244,11 @@ func addDocActorRelationshipACP(
require.Equal(s.t, action.ExpectedError, "")
require.Equal(s.t, action.ExpectedExistence, exists.ExistedAlready)
}
} else {
for i, node := range getNodes(action.NodeID, s.nodes) {
var collectionName string
if action.CollectionID == -1 {
collectionName = ""
} else {
collection := s.collections[i][action.CollectionID]
if !collection.Description().Name.HasValue() {
require.Fail(s.t, "Expected non-empty collection name, but it was empty.", s.testCase.Description)
}
collectionName = collection.Description().Name.Value()
}

var docID string
if action.DocID == -1 || action.CollectionID == -1 {
docID = ""
} else {
docID = s.docIDs[action.CollectionID][action.DocID].String()
}

var targetIdentity string
if action.TargetIdentity == -1 {
targetIdentity = ""
} else {
optionalTargetIdentity := getIdentity(s, i, immutable.Some(action.TargetIdentity))
if !optionalTargetIdentity.HasValue() {
require.Fail(s.t, "Expected non-empty target identity, but it was empty.", s.testCase.Description)
}
targetIdentity = optionalTargetIdentity.Value().DID
}

var requestorIdentity immutable.Option[acpIdentity.Identity]
if action.RequestorIdentity == -1 {
requestorIdentity = acpIdentity.None
} else {
requestorIdentity = getIdentity(s, i, immutable.Some(action.RequestorIdentity))
if !requestorIdentity.HasValue() {
require.Fail(s.t, "Expected non-empty requestor identity, but it was empty.", s.testCase.Description)
}
}
ctx := db.SetContextIdentity(s.ctx, requestorIdentity)

exists, err := node.AddDocActorRelationship(
ctx,
collectionName,
docID,
action.Relation,
targetIdentity,
)

expectedErrorRaised := AssertError(s.t, s.testCase.Description, err, action.ExpectedError)
assertExpectedErrorRaised(s.t, s.testCase.Description, action.ExpectedError, expectedErrorRaised)

if !expectedErrorRaised {
require.Equal(s.t, action.ExpectedError, "")
require.Equal(s.t, action.ExpectedExistence, exists.ExistedAlready)
}

// The relationship should only be added to a SourceHub chain once - there is no need to loop through
// the nodes.
if acpType == SourceHubACPType {
break
}
// The relationship should only be added to a SourceHub chain once - there is no need to loop through
// the nodes.
if acpType == SourceHubACPType {
break
}
}
}
Expand Down Expand Up @@ -361,16 +304,15 @@ func deleteDocActorRelationshipACP(
s *state,
action DeleteDocActorRelationship,
) {
if action.NodeID.HasValue() {
nodeID := action.NodeID.Value()
collections := s.collections[nodeID]
node := s.nodes[nodeID]
nodeIDs, nodes := getNodesWithIDs(action.NodeID, s.nodes)
for index, node := range nodes {
nodeID := nodeIDs[index]

var collectionName string
if action.CollectionID == -1 {
collectionName = ""
} else {
collection := collections[action.CollectionID]
collection := s.collections[nodeID][action.CollectionID]
if !collection.Description().Name.HasValue() {
require.Fail(s.t, "Expected non-empty collection name, but it was empty.", s.testCase.Description)
}
Expand Down Expand Up @@ -421,69 +363,11 @@ func deleteDocActorRelationshipACP(
require.Equal(s.t, action.ExpectedError, "")
require.Equal(s.t, action.ExpectedRecordFound, deleteDocActorRelationshipResult.RecordFound)
}
} else {
for i, node := range getNodes(action.NodeID, s.nodes) {
var collectionName string
if action.CollectionID == -1 {
collectionName = ""
} else {
collection := s.collections[i][action.CollectionID]
if !collection.Description().Name.HasValue() {
require.Fail(s.t, "Expected non-empty collection name, but it was empty.", s.testCase.Description)
}
collectionName = collection.Description().Name.Value()
}

var docID string
if action.DocID == -1 || action.CollectionID == -1 {
docID = ""
} else {
docID = s.docIDs[action.CollectionID][action.DocID].String()
}

var targetIdentity string
if action.TargetIdentity == -1 {
targetIdentity = ""
} else {
optionalTargetIdentity := getIdentity(s, i, immutable.Some(action.TargetIdentity))
if !optionalTargetIdentity.HasValue() {
require.Fail(s.t, "Expected non-empty target identity, but it was empty.", s.testCase.Description)
}
targetIdentity = optionalTargetIdentity.Value().DID
}

var requestorIdentity immutable.Option[acpIdentity.Identity]
if action.RequestorIdentity == -1 {
requestorIdentity = acpIdentity.None
} else {
requestorIdentity = getIdentity(s, i, immutable.Some(action.RequestorIdentity))
if !requestorIdentity.HasValue() {
require.Fail(s.t, "Expected non-empty requestor identity, but it was empty.", s.testCase.Description)
}
}
ctx := db.SetContextIdentity(s.ctx, requestorIdentity)

deleteDocActorRelationshipResult, err := node.DeleteDocActorRelationship(
ctx,
collectionName,
docID,
action.Relation,
targetIdentity,
)

expectedErrorRaised := AssertError(s.t, s.testCase.Description, err, action.ExpectedError)
assertExpectedErrorRaised(s.t, s.testCase.Description, action.ExpectedError, expectedErrorRaised)

if !expectedErrorRaised {
require.Equal(s.t, action.ExpectedError, "")
require.Equal(s.t, action.ExpectedRecordFound, deleteDocActorRelationshipResult.RecordFound)
}

// The relationship should only be added to a SourceHub chain once - there is no need to loop through
// the nodes.
if acpType == SourceHubACPType {
break
}
// The relationship should only be added to a SourceHub chain once - there is no need to loop through
// the nodes.
if acpType == SourceHubACPType {
break
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ func executeExplainRequest(
require.Fail(s.t, "Expected error should not have other expected results with it.", s.testCase.Description)
}

for _, node := range getNodes(action.NodeID, s.nodes) {
_, nodes := getNodesWithIDs(action.NodeID, s.nodes)
for _, node := range nodes {
result := node.ExecRequest(
s.ctx,
action.Request,
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/lens.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ func configureMigration(
s *state,
action ConfigureMigration,
) {
for _, node := range getNodes(action.NodeID, s.nodes) {
_, nodes := getNodesWithIDs(action.NodeID, s.nodes)
for _, node := range nodes {
txn := getTransaction(s, node, action.TransactionID, action.ExpectedError)
ctx := db.SetContextTxn(s.ctx, txn)

Expand Down
Loading
Loading