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

fix(i): Sort out invalid testing framework node indexing #3068

Merged
132 changes: 132 additions & 0 deletions tests/integration/acp/p2p/create_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// Copyright 2024 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package test_acp_p2p

import (
"fmt"
"testing"

"github.com/sourcenetwork/immutable"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

func TestACP_P2PCreatePrivateDocumentsOnDifferentNodes_SourceHubACP(t *testing.T) {
expectedPolicyID := "fc56b7509c20ac8ce682b3b9b4fdaad868a9c70dda6ec16720298be64f16e9a4"

test := testUtils.TestCase{

Description: "Test acp, p2p create private documents on different nodes, with source-hub",

SupportedACPTypes: immutable.Some(
[]testUtils.ACPType{
testUtils.SourceHubACPType,
},
),

Actions: []any{
testUtils.RandomNetworkingConfig(),

testUtils.RandomNetworkingConfig(),

testUtils.AddPolicy{

Identity: immutable.Some(1),

Policy: `
name: Test Policy

description: A Policy

actor:
name: actor

resources:
users:
permissions:
read:
expr: owner + reader + writer

write:
expr: owner + writer

nothing:
expr: dummy

relations:
owner:
types:
- actor

reader:
types:
- actor

writer:
types:
- actor

admin:
manages:
- reader
types:
- actor

dummy:
types:
- actor
`,

ExpectedPolicyID: expectedPolicyID,
},

testUtils.SchemaUpdate{
Schema: fmt.Sprintf(`
type Users @policy(
id: "%s",
resource: "users"
) {
name: String
age: Int
}
`,
expectedPolicyID,
),
},

testUtils.CreateDoc{
Identity: immutable.Some(1),

NodeID: immutable.Some(0),

CollectionID: 0,

DocMap: map[string]any{
"name": "Shahzad",
},
},

testUtils.CreateDoc{
Identity: immutable.Some(1),

NodeID: immutable.Some(1),

CollectionID: 0,

DocMap: map[string]any{
"name": "Shahzad Lone",
},
},
},
}

testUtils.ExecuteTestCase(t, test)
}
159 changes: 159 additions & 0 deletions tests/integration/acp/p2p/delete_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
// Copyright 2024 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package test_acp_p2p

import (
"fmt"
"testing"

"github.com/sourcenetwork/immutable"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

func TestACP_P2PDeletePrivateDocumentsOnDifferentNodes_SourceHubACP(t *testing.T) {
expectedPolicyID := "fc56b7509c20ac8ce682b3b9b4fdaad868a9c70dda6ec16720298be64f16e9a4"

test := testUtils.TestCase{

Description: "Test acp, p2p delete private documents on different nodes, with source-hub",

SupportedACPTypes: immutable.Some(
[]testUtils.ACPType{
testUtils.SourceHubACPType,
},
),

Actions: []any{
testUtils.RandomNetworkingConfig(),

testUtils.RandomNetworkingConfig(),

testUtils.AddPolicy{

Identity: immutable.Some(1),

Policy: `
name: Test Policy

description: A Policy

actor:
name: actor

resources:
users:
permissions:
read:
expr: owner + reader + writer

write:
expr: owner + writer

nothing:
expr: dummy

relations:
owner:
types:
- actor

reader:
types:
- actor

writer:
types:
- actor

admin:
manages:
- reader
types:
- actor

dummy:
types:
- actor
`,

ExpectedPolicyID: expectedPolicyID,
},

testUtils.SchemaUpdate{
Schema: fmt.Sprintf(`
type Users @policy(
id: "%s",
resource: "users"
) {
name: String
age: Int
}
`,
expectedPolicyID,
),
},

testUtils.ConfigureReplicator{
SourceNodeID: 0,
TargetNodeID: 1,
},

testUtils.CreateDoc{
Identity: immutable.Some(1),

NodeID: immutable.Some(0),

CollectionID: 0,

DocMap: map[string]any{
"name": "Shahzad",
},
},

testUtils.CreateDoc{
Identity: immutable.Some(1),

NodeID: immutable.Some(1),

CollectionID: 0,

DocMap: map[string]any{
"name": "Shahzad Lone",
},
},

testUtils.WaitForSync{},

testUtils.DeleteDoc{
Identity: immutable.Some(1),

NodeID: immutable.Some(0),

CollectionID: 0,

DocID: 0,
},

testUtils.DeleteDoc{
Identity: immutable.Some(1),

NodeID: immutable.Some(1),

CollectionID: 0,

DocID: 1,
},
},
}

testUtils.ExecuteTestCase(t, test)
}
Loading
Loading