-
Notifications
You must be signed in to change notification settings - Fork 53
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): Refactor tests to avoid asserting policyIDs #3171
Draft
shahzadlone
wants to merge
2
commits into
sourcenetwork:develop
Choose a base branch
from
shahzadlone:lone/test/policy-id-refactor
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+276
−8
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// 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_demo | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/sourcenetwork/immutable" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
) | ||
|
||
func TestACP_DEMO(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
|
||
Description: "DEMO", | ||
|
||
Actions: []any{ | ||
testUtils.AddPolicy{ // Specified and subbed in for User1 and User2 schema below | ||
|
||
Identity: immutable.Some(1), | ||
|
||
Policy: ` | ||
name: test | ||
description: a test policy which marks a collection in a database as a resource | ||
|
||
actor: | ||
name: actor | ||
|
||
resources: | ||
users: | ||
permissions: | ||
read: | ||
expr: owner + reader | ||
write: | ||
expr: owner | ||
|
||
relations: | ||
owner: | ||
types: | ||
- actor | ||
reader: | ||
types: | ||
- actor | ||
admin: | ||
manages: | ||
- reader | ||
types: | ||
- actor | ||
`, | ||
|
||
// TODO: Remove after draft is approved | ||
// Note: This is also valid now that it is optional, but we don't need to provide it at all. | ||
ExpectedPolicyID: immutable.Some( | ||
"94eb195c0e459aa79e02a1986c7e731c5015721c18a373f2b2a0ed140a04b454", | ||
), | ||
}, | ||
|
||
testUtils.AddPolicy{ // Specified and subbed in for User3 schema below | ||
|
||
Identity: immutable.Some(1), | ||
|
||
Policy: ` | ||
name: test | ||
description: another policy | ||
|
||
actor: | ||
name: actor | ||
|
||
resources: | ||
users: | ||
permissions: | ||
read: | ||
expr: owner + reader | ||
write: | ||
expr: owner | ||
|
||
relations: | ||
owner: | ||
types: | ||
- actor | ||
reader: | ||
types: | ||
- actor | ||
admin: | ||
manages: | ||
- reader | ||
types: | ||
- actor | ||
`, | ||
|
||
// TODO: Remove after draft is approved | ||
// Note: No policyID assertion needed | ||
}, | ||
|
||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Users1 @policy( | ||
id: "%policyID%", | ||
resource: "users" | ||
) { | ||
name: String | ||
age: Int | ||
} | ||
|
||
type User2 @policy( | ||
id: "%policyID%", | ||
resource: "users" | ||
) { | ||
name: String | ||
age: Int | ||
} | ||
|
||
type User3 @policy( | ||
id: "%policyID%", | ||
resource: "users" | ||
) { | ||
name: String | ||
age: Int | ||
} | ||
`, | ||
|
||
PolicyIDs: immutable.Some([]int{0, 0, 1}), | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,6 +129,51 @@ type SchemaUpdate struct { | |
// The schema update. | ||
Schema string | ||
|
||
// PolicyIDs is an optional list argument which makes it easier to substitute/embed PolicyIDs | ||
// into the schema string where place holder labels ("%policyID%") are at, without us using | ||
// explicit policy identifiers. | ||
// | ||
// Note: | ||
// - The number of placeholder labels (%policyID%) must exactly match the number of policyID | ||
// indexes in this list. | ||
// - The list must contain the policyID Indexes in the same order they are to be substituted in. | ||
// - Can substitute the same policyID at an index, by specifying that index multiple times. | ||
// - The indexes must be valid (correspond to the number of policies added so far). | ||
// | ||
// Example: | ||
// | ||
// Consider we have one policy that was added resulting in the following policyID: | ||
// PolicyID="94eb195c0e459aa79e02a1986c7e731c5015721c18a373f2b2a0ed140a04b454" | ||
// | ||
// Then using this attribute like: | ||
// PolicyIDs: immutable.Some([]int{0, 0}), | ||
// | ||
// On a Schema string like: | ||
// ``` | ||
// type Users1 @policy(id: "%policyID%", resource: "users") { | ||
// name: String | ||
// age: Int | ||
// } | ||
// | ||
// type Users2 @policy(id: "%policyID%", resource: "users") { | ||
// name: String | ||
// age: Int | ||
// } | ||
// ``` | ||
// The Schema that will be loaded will be this modified one: | ||
// ``` | ||
// type Users1 @policy(id: "94eb195c0e459aa79e02a1986c7e731c5015721c18a373f2b2a0ed140a04b454", resource: "users") { | ||
// name: String | ||
// age: Int | ||
// } | ||
// | ||
// type Users2 @policy(id: "94eb195c0e459aa79e02a1986c7e731c5015721c18a373f2b2a0ed140a04b454", resource: "users") { | ||
// name: String | ||
// age: Int | ||
// } | ||
// ``` | ||
PolicyIDs immutable.Option[[]int] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: I don't think this being Same goes for Fred's suggestion about decoupling this from |
||
|
||
// Optionally, the expected results. | ||
// | ||
// Each item will be compared individually, if ID, RootID, SchemaVersionID or Fields on the | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: would prefer
if len(s.policyIDs) <= maxNodeID
as the variable doesn't add any clarity.