fixtures

package
v0.0.0-...-20e6d49 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAdminAccountAlreadyExists = eris.New("admin account already exists")
View Source
var ErrResourceDefinitionAlreadyExists = eris.New("resource definition already exists")

Functions

func LoadAdminAccount

func LoadAdminAccount(ctx context.Context, db *bun.DB, fixture *dbfixture.Fixture) (*user.User, error)

func LoadFakeAccounts

func LoadFakeAccounts(ctx context.Context, db *bun.DB, fixture *dbfixture.Fixture) error

LoadFakeAccounts generates 50 fake accounts

func LoadFixtures

func LoadFixtures(ctx context.Context, fixture *dbfixture.Fixture, db *bun.DB) error

func LoadPermissions

func LoadPermissions(ctx context.Context, db *bun.DB, fixture *dbfixture.Fixture) error

func LoadResourceDefinition

func LoadResourceDefinition(ctx context.Context, db *bun.DB) error

func LoadWorkers

func LoadWorkers(ctx context.Context, db *bun.DB, fixture *dbfixture.Fixture) error

Types

type FixtureHelpers

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

FixtureHelpers provides a set of utility functions to facilitate generating template-based fixture data, particularly for testing and development. It allows manipulation of times, generation of unique identifiers, and various array and collection operations.

func NewFixtureHelpers

func NewFixtureHelpers() *FixtureHelpers

NewFixtureHelpers creates and returns a new instance of FixtureHelpers. It initializes the base time to the current time and sets up a random number generator seeded with the current Unix time.

func (*FixtureHelpers) Concat

func (h *FixtureHelpers) Concat(arrays ...[]any) []any

Concat combines multiple slices of interfaces into a single slice. This is useful for building larger collections from smaller ones.

func (*FixtureHelpers) DateString

func (h *FixtureHelpers) DateString(format string, timestamp int64) string

DateString formats a given Unix timestamp into a string according to the specified layout. The layout should be a standard Go time layout string (e.g., "2006-01-02").

func (*FixtureHelpers) DaysAgo

func (h *FixtureHelpers) DaysAgo(days int64) int64

DaysAgo returns a Unix timestamp for N days before the base time.

func (*FixtureHelpers) DaysFromNow

func (h *FixtureHelpers) DaysFromNow(days int64) int64

DaysFromNow returns a Unix timestamp for N days after the base time.

func (*FixtureHelpers) GetTemplateFuncs

func (h *FixtureHelpers) GetTemplateFuncs() map[string]any

GetTemplateFuncs returns a map of template functions that can be used within templates. The returned map includes time-based helpers, unique ID generation, reference building, enumeration, and various collection utilities.

func (*FixtureHelpers) MonthsAgo

func (h *FixtureHelpers) MonthsAgo(months int64) int64

MonthsAgo returns a Unix timestamp for N months prior to the base time.

func (*FixtureHelpers) MonthsFromNow

func (h *FixtureHelpers) MonthsFromNow(months int64) int64

MonthsFromNow returns a Unix timestamp for N months after the base time.

func (*FixtureHelpers) Now

func (h *FixtureHelpers) Now() time.Time

Now returns the base time stored in the FixtureHelpers instance. This is useful for generating time-dependent fixtures that all share the same reference time.

func (*FixtureHelpers) Random

func (h *FixtureHelpers) Random(minX, maxX int64) int64

Random returns a random integer between min and max (inclusive).

func (*FixtureHelpers) RandomEnum

func (h *FixtureHelpers) RandomEnum(values ...string) string

RandomEnum selects and returns a random string from the provided values. Useful for picking a random value from a set of predefined options.

func (*FixtureHelpers) RandomPhone

func (h *FixtureHelpers) RandomPhone() string

RandomPhone generates and returns a random 10-digit phone number formatted as XXX-XXX-XXXX, ensuring that the first digit is never zero.

func (*FixtureHelpers) Reference

func (h *FixtureHelpers) Reference(model, field string) string

Reference returns a Go template string that references a field within a given model in the template's data. This can be used within fixtures to dynamically link related data.

func (*FixtureHelpers) Repeat

func (h *FixtureHelpers) Repeat(count int64, value any) []any

Repeat returns a slice containing the specified value repeated count times. Useful for generating repeated data in fixtures.

func (*FixtureHelpers) Sample

func (h *FixtureHelpers) Sample(count int64, items []any) ([]any, error)

Sample returns a cryptographically secure random sample of elements

func (*FixtureHelpers) Sequence

func (h *FixtureHelpers) Sequence(name string) int64

Sequence returns an incrementing integer each time it is called with the same name. This can be used to generate sequential values in templates, such as incrementing primary keys or version numbers.

func (*FixtureHelpers) Shuffle

func (h *FixtureHelpers) Shuffle(items []any) ([]any, error)

Shuffle returns a new slice with all elements randomly shuffled using crypto/rand

func (*FixtureHelpers) Slice

func (h *FixtureHelpers) Slice(start, end int64, items []any) []any

Slice returns a portion of the given slice between the specified start and end indices. If indices are out of range, they are adjusted to valid boundaries.

func (*FixtureHelpers) Timestamp

func (h *FixtureHelpers) Timestamp() int64

Timestamp returns the Unix timestamp corresponding to the base time.

func (*FixtureHelpers) ULID

func (h *FixtureHelpers) ULID() string

PULID generates and returns a new PULID as a string. This can be used for generating unique identifiers in fixtures.

func (*FixtureHelpers) YearsAgo

func (h *FixtureHelpers) YearsAgo(years int64) int64

func (*FixtureHelpers) YearsFromNow

func (h *FixtureHelpers) YearsFromNow(years int64) int64

YearsFromNow returns a Unix timestamp representing the time N years after the base time. This can be useful when generating future dates.

type PermissionDefinition

type PermissionDefinition struct {
	Resource    permission.Resource
	Action      permission.Action
	Scope       permission.Scope
	Description string
	DependsOn   []struct {
		Resource permission.Resource
		Action   permission.Action
	}
	FieldSettings []*permission.FieldPermission
}

PermissionDefinition defines a permission with its dependencies

type ResourcePermissions

type ResourcePermissions struct {
	Resource    permission.Resource
	Permissions []permissionbuilder.PermissionDefinition
}

ResourcePermissions defines all permissions for a specific resource

Jump to

Keyboard shortcuts

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