Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #335 from bryanhuhta/bryanhuhta/parse-comments
fix: skip comments when loading test relationships
- Loading branch information
Showing
4 changed files
with
101 additions
and
1 deletion.
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,50 @@ | ||
package validationfile | ||
|
||
import ( | ||
"testing" | ||
|
||
v0 "github.com/authzed/authzed-go/proto/authzed/api/v0" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/authzed/spicedb/internal/datastore/memdb" | ||
"github.com/authzed/spicedb/pkg/tuple" | ||
) | ||
|
||
func TestPopulateFromFiles(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
filePaths []string | ||
want []*v0.RelationTuple | ||
}{ | ||
{ | ||
name: "no comment", | ||
filePaths: []string{"testdata/loader_no_comment.yaml"}, | ||
want: []*v0.RelationTuple{ | ||
tuple.Parse("example/project:pied_piper#owner@example/user:milburga"), | ||
tuple.Parse("example/project:pied_piper#reader@example/user:tarben"), | ||
tuple.Parse("example/project:pied_piper#writer@example/user:freyja"), | ||
}, | ||
}, | ||
{ | ||
name: "with comment", | ||
filePaths: []string{"testdata/loader_with_comment.yaml"}, | ||
want: []*v0.RelationTuple{ | ||
tuple.Parse("example/project:pied_piper#owner@example/user:milburga"), | ||
tuple.Parse("example/project:pied_piper#reader@example/user:tarben"), | ||
tuple.Parse("example/project:pied_piper#writer@example/user:freyja"), | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
require := require.New(t) | ||
ds, err := memdb.NewMemdbDatastore(0, 0, 0, 0) | ||
require.NoError(err) | ||
|
||
parsed, _, err := PopulateFromFiles(ds, tt.filePaths) | ||
require.NoError(err) | ||
require.Equal(tt.want, parsed.Tuples) | ||
}) | ||
} | ||
} |
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,23 @@ | ||
schema: >- | ||
definition example/user {} | ||
definition example/project { | ||
relation reader: example/user | ||
relation writer: example/user | ||
relation owner: example/user | ||
permission read = reader + write | ||
permission write = writer + admin | ||
permission admin = owner | ||
} | ||
relationships: >- | ||
example/project:pied_piper#owner@example/user:milburga | ||
example/project:pied_piper#reader@example/user:tarben | ||
example/project:pied_piper#writer@example/user:freyja | ||
assertions: | ||
assertTrue: [] | ||
assertFalse: [] | ||
validation: null |
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,27 @@ | ||
schema: >- | ||
definition example/user {} | ||
definition example/project { | ||
relation reader: example/user | ||
relation writer: example/user | ||
relation owner: example/user | ||
permission read = reader + write | ||
permission write = writer + admin | ||
permission admin = owner | ||
} | ||
relationships: >- | ||
// Some comment | ||
example/project:pied_piper#owner@example/user:milburga | ||
example/project:pied_piper#reader@example/user:tarben | ||
// Some other comment | ||
example/project:pied_piper#writer@example/user:freyja | ||
assertions: | ||
assertTrue: [] | ||
assertFalse: [] | ||
validation: null |