testfixtures

package
v1.30.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FirstLetters      = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_"
	SubsequentLetters = FirstLetters + "/_|-"
)

Variables

View Source
var CaveatDef = ns.MustCaveatDefinition(
	caveats.MustEnvForVariables(map[string]caveattypes.VariableType{
		"secret":         caveattypes.StringType,
		"expectedSecret": caveattypes.StringType,
	}),
	"test",
	"secret == expectedSecret",
)
View Source
var DocumentNS = ns.Namespace(
	"document",
	ns.MustRelation("owner",
		nil,
		ns.AllowedRelation("user", "..."),
	),
	ns.MustRelation("editor",
		nil,
		ns.AllowedRelation("user", "..."),
	),
	ns.MustRelation("viewer",
		nil,
		ns.AllowedRelation("user", "..."),
	),
	ns.MustRelation("viewer_and_editor",
		nil,
		ns.AllowedRelation("user", "..."),
	),
	ns.MustRelation("caveated_viewer",
		nil,
		ns.AllowedRelationWithCaveat("user", "...", ns.AllowedCaveat("test")),
	),
	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"),
		),
	),
)
View Source
var FolderNS = ns.Namespace(
	"folder",
	ns.MustRelation("owner",
		nil,
		ns.AllowedRelation("user", "..."),
	),
	ns.MustRelation("editor",
		nil,
		ns.AllowedRelation("user", "..."),
	),
	ns.MustRelation("viewer",
		nil,
		ns.AllowedRelation("user", "..."),
		ns.AllowedRelation("folder", "viewer"),
	),
	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"),
		),
	),
)
View Source
var StandardTuples = []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#...",
}

StandardTuples defines standard tuples for tests. NOTE: some tests index directly into this slice, so if you're adding a new tuple, add it at the *end*.

View Source
var UserNS = ns.Namespace("user")

Functions

func DatastoreFromSchemaAndTestRelationships added in v1.15.0

func DatastoreFromSchemaAndTestRelationships(ds datastore.Datastore, schema string, relationships []*core.RelationTuple, require *require.Assertions) (datastore.Datastore, datastore.Revision)

DatastoreFromSchemaAndTestRelationships returns a validating datastore wrapping that specified, loaded with the given scehma and relationships.

func EmptyDatastore added in v1.5.0

EmptyDatastore returns an empty datastore for testing.

func NewValidatingDatastore added in v0.0.2

func NewValidatingDatastore(delegate datastore.Datastore) datastore.Datastore

NewValidatingDatastore creates a proxy which runs validation on all call parameters before passing the call onward.

func RandomObjectID added in v1.20.0

func RandomObjectID(length uint8) string

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 BulkTupleGenerator added in v1.22.0

type BulkTupleGenerator struct {
	// contains filtered or unexported fields
}

func NewBulkTupleGenerator added in v1.22.0

func NewBulkTupleGenerator(objectType, relation, subjectType string, count int, t *testing.T) *BulkTupleGenerator

func (*BulkTupleGenerator) Next added in v1.22.0

type TupleChecker

type TupleChecker struct {
	Require *require.Assertions
	DS      datastore.Datastore
}

TupleChecker is a helper type which provides an easy way for collecting relationships/tuples from an iterator and verify those found.

func (TupleChecker) ExactRelationshipIterator added in v1.8.0

func (tc TupleChecker) ExactRelationshipIterator(ctx context.Context, tpl *core.RelationTuple, rev datastore.Revision) datastore.RelationshipIterator

func (TupleChecker) NoTupleExists

func (tc TupleChecker) NoTupleExists(ctx context.Context, tpl *core.RelationTuple, rev datastore.Revision)

func (TupleChecker) TupleExists

func (tc TupleChecker) TupleExists(ctx context.Context, tpl *core.RelationTuple, rev datastore.Revision)

func (TupleChecker) VerifyIteratorCount

func (tc TupleChecker) VerifyIteratorCount(iter datastore.RelationshipIterator, count int)

func (TupleChecker) VerifyIteratorResults

func (tc TupleChecker) VerifyIteratorResults(iter datastore.RelationshipIterator, tpls ...*core.RelationTuple)

func (TupleChecker) VerifyOrderedIteratorResults added in v1.21.0

func (tc TupleChecker) VerifyOrderedIteratorResults(iter datastore.RelationshipIterator, tpls ...*core.RelationTuple)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL