Documentation
¶
Overview ¶
Package testfixtures contains code that helps to run tests against datastores.
Index ¶
- Constants
- Variables
- func DatastoreFromSchemaAndTestRelationships(ds datastore.Datastore, schema string, relationships []tuple.Relationship, ...) (datastore.Datastore, datastore.Revision)
- func EmptyDatastore(ds datastore.Datastore, require *require.Assertions) (datastore.Datastore, datastore.Revision)
- func NewValidatingDatastore(delegate datastore.Datastore) datastore.Datastore
- func RandomObjectID(length uint8) string
- func StandardDatastoreWithCaveatedData(ds datastore.Datastore, require *require.Assertions) (datastore.Datastore, datastore.Revision)
- func StandardDatastoreWithData(ds datastore.Datastore, require *require.Assertions) (datastore.Datastore, datastore.Revision)
- func StandardDatastoreWithSchema(ds datastore.Datastore, require *require.Assertions) (datastore.Datastore, datastore.Revision)
- type BulkRelationshipGenerator
- type RelationshipChecker
- func (tc RelationshipChecker) ExactRelationshipIterator(ctx context.Context, rel tuple.Relationship, rev datastore.Revision) datastore.RelationshipIterator
- func (tc RelationshipChecker) NoRelationshipExists(ctx context.Context, rel tuple.Relationship, rev datastore.Revision)
- func (tc RelationshipChecker) RelationshipExists(ctx context.Context, rel tuple.Relationship, rev datastore.Revision)
- func (tc RelationshipChecker) VerifyIteratorCount(iter datastore.RelationshipIterator, count int)
- func (tc RelationshipChecker) VerifyIteratorResults(iter datastore.RelationshipIterator, rels ...tuple.Relationship)
- func (tc RelationshipChecker) VerifyOrderedIteratorResults(iter datastore.RelationshipIterator, rels ...tuple.Relationship) options.Cursor
Constants ¶
const ( FirstLetters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_" SubsequentLetters = FirstLetters + "/_|-" )
Variables ¶
var CaveatDef = ns.MustCaveatDefinition( caveats.MustEnvForVariablesWithDefaultTypeSet(map[string]caveattypes.VariableType{ "secret": caveattypes.Default.StringType, "expectedSecret": caveattypes.Default.StringType, }), "test", "secret == expectedSecret", )
var DocumentNS = ns.Namespace( "document", ns.MustRelation("owner", nil, ns.AllowedRelation("user", "..."), ns.AllowedRelationWithCaveat("user", "...", ns.AllowedCaveat("test")), ), ns.MustRelation("editor", nil, ns.AllowedRelation("user", "..."), ), ns.MustRelation("viewer", nil, ns.AllowedRelation("user", "..."), ns.AllowedRelationWithCaveat("user", "...", ns.AllowedCaveat("test")), ), ns.MustRelation("viewer_and_editor", nil, ns.AllowedRelation("user", "..."), ), ns.MustRelation("caveated_viewer", nil, ns.AllowedRelationWithCaveat("user", "...", ns.AllowedCaveat("test")), ), ns.MustRelation("expiring_viewer", nil, ns.AllowedRelationWithExpiration("user", "..."), ), ns.MustRelation("parent", nil, ns.AllowedRelation("folder", "...")), ns.MustRelation("edit", ns.Union( ns.ComputedUserset("owner"), ns.ComputedUserset("editor"), ), ), ns.MustRelation("view", ns.Union( ns.ComputedUserset("viewer"), ns.ComputedUserset("edit"), ns.TupleToUserset("parent", "view"), ), ), ns.MustRelation("view_and_edit", ns.Intersection( ns.ComputedUserset("viewer_and_editor"), ns.ComputedUserset("edit"), ), ), )
var FolderNS = ns.Namespace( "folder", ns.MustRelation("owner", nil, ns.AllowedRelation("user", "..."), ns.AllowedRelationWithCaveat("user", "...", ns.AllowedCaveat("test")), ), ns.MustRelation("editor", nil, ns.AllowedRelation("user", "..."), ), ns.MustRelation("viewer", nil, ns.AllowedRelation("user", "..."), ns.AllowedRelation("folder", "viewer"), ns.AllowedRelationWithCaveat("folder", "viewer", ns.AllowedCaveat("test")), ), ns.MustRelation("parent", nil, ns.AllowedRelation("folder", "...")), ns.MustRelation("edit", ns.Union( ns.ComputedUserset("editor"), ns.ComputedUserset("owner"), ), ), ns.MustRelation("view", ns.Union( ns.ComputedUserset("viewer"), ns.ComputedUserset("edit"), ns.TupleToUserset("parent", "view"), ), ), )
var StandardCaveatedRelationships = []string{
"document:caveatedplan#caveated_viewer@user:caveatedguy#...[test:{\"expectedSecret\":\"1234\"}]",
}
var StandardRelationships = []string{
"document:companyplan#parent@folder:company#...",
"document:masterplan#parent@folder:strategy#...",
"folder:strategy#parent@folder:company#...",
"folder:company#owner@user:owner#...",
"folder:company#viewer@user:legal#...",
"folder:strategy#owner@user:vp_product#...",
"document:masterplan#owner@user:product_manager#...",
"document:masterplan#viewer@user:eng_lead#...",
"document:masterplan#parent@folder:plans#...",
"folder:plans#viewer@user:chief_financial_officer#...",
"folder:auditors#viewer@user:auditor#...",
"folder:company#viewer@folder:auditors#viewer",
"document:healthplan#parent@folder:plans#...",
"folder:isolated#viewer@user:villain#...",
"document:specialplan#viewer_and_editor@user:multiroleguy#...",
"document:specialplan#editor@user:multiroleguy#...",
"document:specialplan#viewer_and_editor@user:missingrolegal#...",
"document:base64YWZzZGZh-ZHNmZHPwn5iK8J+YivC/fmIrwn5iK==#owner@user:base64YWZzZGZh-ZHNmZHPwn5iK8J+YivC/fmIrwn5iK==#...",
"document:veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryverylong#owner@user:veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryverylong#...",
"document:ownerplan#viewer@user:owner#...",
}
StandardRelationships defines standard relationships for tests. NOTE: some tests index directly into this slice, so if you're adding a new relationship, add it at the *end*.
var UserNS = ns.Namespace("user")
Functions ¶
func DatastoreFromSchemaAndTestRelationships ¶ added in v1.15.0
func DatastoreFromSchemaAndTestRelationships(ds datastore.Datastore, schema string, relationships []tuple.Relationship, require *require.Assertions) (datastore.Datastore, datastore.Revision)
DatastoreFromSchemaAndTestRelationships returns a validating datastore wrapping that specified, loaded with the given schema and relationships.
func EmptyDatastore ¶ added in v1.5.0
func EmptyDatastore(ds datastore.Datastore, require *require.Assertions) (datastore.Datastore, datastore.Revision)
EmptyDatastore returns an empty datastore for testing.
func NewValidatingDatastore ¶ added in v0.0.2
NewValidatingDatastore creates a proxy which runs validation on all call parameters before passing the call onward.
func RandomObjectID ¶ added in v1.20.0
func StandardDatastoreWithCaveatedData ¶ added in v1.14.0
func StandardDatastoreWithCaveatedData(ds datastore.Datastore, require *require.Assertions) (datastore.Datastore, datastore.Revision)
StandardDatastoreWithCaveatedData returns a datastore populated with both the standard test definitions and some caveated relationships.
func StandardDatastoreWithData ¶
func StandardDatastoreWithData(ds datastore.Datastore, require *require.Assertions) (datastore.Datastore, datastore.Revision)
StandardDatastoreWithData returns a datastore populated with both the standard test definitions and relationships.
func StandardDatastoreWithSchema ¶
func StandardDatastoreWithSchema(ds datastore.Datastore, require *require.Assertions) (datastore.Datastore, datastore.Revision)
StandardDatastoreWithSchema returns a datastore populated with the standard test definitions.
Types ¶
type BulkRelationshipGenerator ¶ added in v1.39.0
type BulkRelationshipGenerator struct { WithExpiration bool WithCaveat bool // contains filtered or unexported fields }
func NewBulkRelationshipGenerator ¶ added in v1.39.0
func NewBulkRelationshipGenerator(objectType, relation, subjectType string, count int, t *testing.T) *BulkRelationshipGenerator
func (*BulkRelationshipGenerator) Next ¶ added in v1.39.0
func (btg *BulkRelationshipGenerator) Next(_ context.Context) (*tuple.Relationship, error)
type RelationshipChecker ¶ added in v1.39.0
type RelationshipChecker struct { Require *require.Assertions DS datastore.Datastore }
RelationshipChecker is a helper type which provides an easy way for collecting relationships from an iterator and verify those found.
func (RelationshipChecker) ExactRelationshipIterator ¶ added in v1.39.0
func (tc RelationshipChecker) ExactRelationshipIterator(ctx context.Context, rel tuple.Relationship, rev datastore.Revision) datastore.RelationshipIterator
func (RelationshipChecker) NoRelationshipExists ¶ added in v1.39.0
func (tc RelationshipChecker) NoRelationshipExists(ctx context.Context, rel tuple.Relationship, rev datastore.Revision)
func (RelationshipChecker) RelationshipExists ¶ added in v1.39.0
func (tc RelationshipChecker) RelationshipExists(ctx context.Context, rel tuple.Relationship, rev datastore.Revision)
func (RelationshipChecker) VerifyIteratorCount ¶ added in v1.39.0
func (tc RelationshipChecker) VerifyIteratorCount(iter datastore.RelationshipIterator, count int)
func (RelationshipChecker) VerifyIteratorResults ¶ added in v1.39.0
func (tc RelationshipChecker) VerifyIteratorResults(iter datastore.RelationshipIterator, rels ...tuple.Relationship)
func (RelationshipChecker) VerifyOrderedIteratorResults ¶ added in v1.39.0
func (tc RelationshipChecker) VerifyOrderedIteratorResults(iter datastore.RelationshipIterator, rels ...tuple.Relationship) options.Cursor