Skip to content

Commit

Permalink
PR fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
islamaliev committed Oct 17, 2024
1 parent 9aa2989 commit 6633ea8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
4 changes: 2 additions & 2 deletions cli/node_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
func MakeNodeIdentityCommand() *cobra.Command {
var cmd = &cobra.Command{
Use: "node_identity",
Short: "Get information about the node's identity",
Long: `Get information about the node's identity.
Short: "Get the information public about the node's identity",
Long: `Get the information public about the node's identity.
Node uses the identity to be able to exchange encryption keys with other nodes.
Expand Down
2 changes: 2 additions & 0 deletions cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ func MakeStartCommand() *cobra.Command {
cmd.Printf(devModeBanner)
if cfg.GetBool("keyring.disabled") {
var err error

Check warning on line 144 in cli/start.go

View check run for this annotation

Codecov / codecov/patch

cli/start.go#L143-L144

Added lines #L143 - L144 were not covered by tests
// TODO: we want to persist this identity so we can restart the node with the same identity
// even in development mode. https://github.com/sourcenetwork/defradb/issues/3148
opts, err = addEphemeralIdentity(opts)
if err != nil {
return err

Check warning on line 149 in cli/start.go

View check run for this annotation

Codecov / codecov/patch

cli/start.go#L147-L149

Added lines #L147 - L149 were not covered by tests
Expand Down
56 changes: 35 additions & 21 deletions tests/integration/acp.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/stretchr/testify/require"

acpIdentity "github.com/sourcenetwork/defradb/acp/identity"
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/internal/db"
"github.com/sourcenetwork/defradb/keyring"
"github.com/sourcenetwork/defradb/node"
Expand Down Expand Up @@ -195,7 +196,7 @@ func addDocActorRelationshipACP(s *state, action AddDocActorRelationship) {
getTargetIdentity(s, action.TargetIdentity, nodeID),
)

assertACPResult(s, action.ExpectedError, err, action.ExpectedExistence, result.ExistedAlready, "existed")
assertAddDocActorRelationship(s, err, action, result)
} else {
for i := range getNodes(action.NodeID, s.nodes) {
node := s.nodes[i]
Expand All @@ -211,14 +212,29 @@ func addDocActorRelationshipACP(s *state, action AddDocActorRelationship) {
getTargetIdentity(s, action.TargetIdentity, i),
)

assertACPResult(s, action.ExpectedError, err, action.ExpectedExistence, result.ExistedAlready, "existed")
assertAddDocActorRelationship(s, err, action, result)
if acpType == SourceHubACPType {
break
}
}
}
}

func assertAddDocActorRelationship(
s *state,
actualErr error,
action AddDocActorRelationship,
result client.AddDocActorRelationshipResult,
) {
expectedErrorRaised := AssertError(s.t, s.testCase.Description, actualErr, 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, result.ExistedAlready, "existed")
}
}

// DeleteDocActorRelationship will attempt to delete a relationship between a document and an actor.
type DeleteDocActorRelationship struct {
// NodeID may hold the ID (index) of the node we want to delete doc actor relationship on.
Expand Down Expand Up @@ -282,7 +298,7 @@ func deleteDocActorRelationshipACP(s *state, action DeleteDocActorRelationship)
getTargetIdentity(s, action.TargetIdentity, nodeID),
)

assertACPResult(s, action.ExpectedError, err, action.ExpectedRecordFound, result.RecordFound, "record found")
assertDeleteDocActorRelationship(s, err, action, result)
} else {
for i := range getNodes(action.NodeID, s.nodes) {
node := s.nodes[i]
Expand All @@ -297,15 +313,29 @@ func deleteDocActorRelationshipACP(s *state, action DeleteDocActorRelationship)
action.Relation,
getTargetIdentity(s, action.TargetIdentity, i),
)

assertACPResult(s, action.ExpectedError, err, action.ExpectedRecordFound, result.RecordFound, "record found")
assertDeleteDocActorRelationship(s, err, action, result)
if acpType == SourceHubACPType {
break
}
}
}
}

func assertDeleteDocActorRelationship(
s *state,
actualErr error,
action DeleteDocActorRelationship,
result client.DeleteDocActorRelationshipResult,
) {
expectedErrorRaised := AssertError(s.t, s.testCase.Description, actualErr, 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, result.RecordFound, "record found mismatch")
}
}

func getCollectionAndDocInfo(s *state, collectionID, docInd, nodeID int) (string, string) {
collectionName := ""
docID := ""
Expand Down Expand Up @@ -345,22 +375,6 @@ func getRequestorIdentity(s *state, requestorIdent, nodeID int) immutable.Option
return acpIdentity.None
}

func assertACPResult(
s *state,
expectedError string,
actualErr error,
expectedBool, actualBool bool,
boolDesc string,
) {
expectedErrorRaised := AssertError(s.t, s.testCase.Description, actualErr, expectedError)
assertExpectedErrorRaised(s.t, s.testCase.Description, expectedError, expectedErrorRaised)

if !expectedErrorRaised {
require.Equal(s.t, expectedError, "")
require.Equal(s.t, expectedBool, actualBool, boolDesc)
}
}

func setupSourceHub(s *state) ([]node.ACPOpt, error) {
var isACPTest bool
for _, a := range s.testCase.Actions {
Expand Down

0 comments on commit 6633ea8

Please sign in to comment.