orgtest

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package orgtest is the organization counterpart of authtest's user factory: build an organization in memory, then save it through the plugin's real Go API so every rule and hook runs.

It lives in the organization module, not in authtest, because the core module cannot import the organization plugin. Like authtest it imports no database driver: the test that uses it imports its own.

Index

Constants

View Source
const DefaultOrgName = "Test Organization"

DefaultOrgName is the name NewOrganization gives when the test passes none.

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

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

Factory builds and saves organizations for one authtest.Env.

func New

func New(env *authtest.Env) *Factory

New returns the factory for env, whose Auth must have the organization plugin wired; a missing plugin fails the test.

func (*Factory) AddMember

func (f *Factory) AddMember(orgID, userID string, role organization.Role)

AddMember adds userID to orgID with role through the plugin's AddMember; a refusal fails the test.

func (*Factory) NewOrganization

func (f *Factory) NewOrganization(ownerID, name string) OrgFixture

NewOrganization builds an OrgFixture without touching the database: DefaultOrgName unless the test passes a name, a random slug that fits organization.SlugPattern, and ownerID as its creator. The organization's id is given by the plugin at SaveOrganization, as for any organization.

func (*Factory) SaveOrganization

func (f *Factory) SaveOrganization(o OrgFixture) organization.Org

SaveOrganization creates f through the plugin (CreateFor, then AddMember for each member), so slug, role and limit rules and every hook run, and returns the stored organization. Any refusal fails the test.

type Member

type Member struct {
	UserID string
	Role   organization.Role
}

Member is one membership an OrgFixture is saved with.

type OrgFixture

type OrgFixture struct {
	Name     string
	Slug     string
	OwnerID  string
	Metadata auth.AppData
	Members  []Member
}

OrgFixture is an organization not yet saved. OwnerID is the user who creates it and becomes its creator-role member; Members are added after, each with its role.

Jump to

Keyboard shortcuts

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