testutil

package
v0.0.0-...-dbf8721 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AliasMetamodel

func AliasMetamodel() *metamodel.Metamodel

AliasMetamodel returns a metamodel with aliases for testing alias resolution.

func AliasMetamodelYAML

func AliasMetamodelYAML() string

AliasMetamodelYAML returns the YAML for AliasMetamodel().

func AssertEqual

func AssertEqual(t *testing.T, got, want interface{})

AssertEqual checks that two values are deeply equal. DeepEqual (not ==) so that slices, maps, and other uncomparable types diff instead of panicking.

func AssertError

func AssertError(t *testing.T, err error)

AssertError checks that an error is not nil.

func AssertFileExists

func AssertFileExists(t *testing.T, path string)

AssertFileExists checks that a file exists at the given path.

func AssertFileNotExists

func AssertFileNotExists(t *testing.T, path string)

AssertFileNotExists checks that a file does not exist at the given path.

func AssertIsDir

func AssertIsDir(t *testing.T, path string)

AssertIsDir checks that a path is a directory.

func AssertLengthEqual

func AssertLengthEqual(t *testing.T, slice interface{}, expectedLen int)

AssertLengthEqual checks that a slice or map has the expected length.

func AssertNoError

func AssertNoError(t *testing.T, err error)

AssertNoError checks that an error is nil.

func AssertNotEqual

func AssertNotEqual(t *testing.T, got, notWant interface{})

AssertNotEqual checks that two values are not deeply equal.

func AssertStringContains

func AssertStringContains(t *testing.T, s, substr string)

AssertStringContains checks that a string contains a substring.

func AssertStringNotContains

func AssertStringNotContains(t *testing.T, s, substr string)

AssertStringNotContains checks that a string does not contain a substring.

func ChangeDir

func ChangeDir(t *testing.T, dir string) func()

ChangeDir changes the current directory and returns a cleanup function that restores the original directory.

func CreateDir

func CreateDir(t *testing.T, path string)

CreateDir creates a directory at the specified path. Creates parent directories as needed.

func CreateFile

func CreateFile(t *testing.T, path, content string)

CreateFile creates a file with the given content at the specified path. Creates parent directories as needed.

func RandomBool

func RandomBool() bool

RandomBool generates a random boolean.

func RandomDate

func RandomDate() string

RandomDate generates a random date within the last year.

func RandomEnumValue

func RandomEnumValue(values []string) string

RandomEnumValue picks a random value from the given list. Panics if values is empty.

func RandomID

func RandomID(prefix string) string

RandomID generates a random ID with the given prefix like "PREFIX-a3f8". If prefix is empty, generates just the suffix.

func RandomInt

func RandomInt(low, high int) int

RandomInt generates a random integer in the range [low, high]. If low > high, the values are swapped.

func RandomString

func RandomString() string

RandomString generates a random string like "word-a3f8".

func ReadFile

func ReadFile(t *testing.T, path string) string

ReadFile reads a file and returns its contents as a string.

func RenameTestMetamodelYAML

func RenameTestMetamodelYAML() string

RenameTestMetamodelYAML returns a metamodel for rename tests with requirement, decision, and depends-on/addresses relations.

func SimpleMetamodel

func SimpleMetamodel() *metamodel.Metamodel

SimpleMetamodel returns a simple metamodel for testing with requirement and decision types.

func SimpleMetamodelYAML

func SimpleMetamodelYAML() string

SimpleMetamodelYAML returns a simple metamodel YAML for testing.

func TempDirWithCleanup

func TempDirWithCleanup(t *testing.T) string

TempDirWithCleanup creates a temporary directory for testing. Uses t.TempDir() which automatically cleans up after the test.

func TicketMetamodel

func TicketMetamodel() *metamodel.Metamodel

TicketMetamodel returns a metamodel for ticket/issue tracking tests.

func WorkspaceMetamodel

func WorkspaceMetamodel() *metamodel.Metamodel

WorkspaceMetamodel returns a metamodel suitable for workspace tests with requirement, decision, stakeholder, and checklist types plus automations.

func WorkspaceMetamodelYAML

func WorkspaceMetamodelYAML() string

WorkspaceMetamodelYAML returns the YAML for WorkspaceMetamodel().

Types

type EntityBuilder

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

EntityBuilder provides a fluent interface for building test entities. Builders should not be reused after Build() - each call creates a fresh builder.

func Entity

func Entity(entityType string) *EntityBuilder

Entity creates a simple entity builder with a random ID. The entity will have a random ID unless set explicitly with ID().

func EntityFor

func EntityFor(meta *metamodel.Metamodel, entityType string) *EntityBuilder

EntityFor creates a metamodel-aware entity builder that auto-fills required properties. Panics if meta is nil or entityType is not defined in the metamodel.

func NewEntity

func NewEntity(id, entityType string) *EntityBuilder

NewEntity creates a new entity builder with the given ID and type.

func (*EntityBuilder) Build

func (b *EntityBuilder) Build() *entity.Entity

Build returns the built entity.

func (*EntityBuilder) ID

func (b *EntityBuilder) ID(id string) *EntityBuilder

ID sets the entity ID explicitly.

func (*EntityBuilder) With

func (b *EntityBuilder) With(key string, value interface{}) *EntityBuilder

With is an alias for WithProperty for more concise syntax.

func (*EntityBuilder) WithContent

func (b *EntityBuilder) WithContent(content string) *EntityBuilder

WithContent sets the content of the entity.

func (*EntityBuilder) WithDescription

func (b *EntityBuilder) WithDescription(desc string) *EntityBuilder

WithDescription adds a description property to the entity.

func (*EntityBuilder) WithList

func (b *EntityBuilder) WithList(key string, values ...string) *EntityBuilder

WithList sets a list property value.

func (*EntityBuilder) WithProperty

func (b *EntityBuilder) WithProperty(key string, value interface{}) *EntityBuilder

WithProperty adds a property to the entity.

func (*EntityBuilder) WithTitle

func (b *EntityBuilder) WithTitle(title string) *EntityBuilder

WithTitle adds a title property to the entity.

func (*EntityBuilder) Without

func (b *EntityBuilder) Without(key string) *EntityBuilder

Without marks a property to be skipped during auto-fill (only relevant for EntityFor).

type EntityDefBuilder

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

EntityDefBuilder provides a fluent interface for building entity definitions.

func (*EntityDefBuilder) Aliases

func (e *EntityDefBuilder) Aliases(aliases ...string) *EntityDefBuilder

Aliases sets entity type aliases.

func (*EntityDefBuilder) End

End finishes building the entity and adds it to the metamodel.

func (*EntityDefBuilder) IDPrefix

func (e *EntityDefBuilder) IDPrefix(prefix string) *EntityDefBuilder

IDPrefix sets a single ID prefix.

func (*EntityDefBuilder) IDPrefixes

func (e *EntityDefBuilder) IDPrefixes(prefixes ...string) *EntityDefBuilder

IDPrefixes sets multiple ID prefixes.

func (*EntityDefBuilder) IDType

func (e *EntityDefBuilder) IDType(idType string) *EntityDefBuilder

IDType sets the ID generation type (short, sequential, manual).

func (*EntityDefBuilder) Label

func (e *EntityDefBuilder) Label(label string) *EntityDefBuilder

Label sets the entity label.

func (*EntityDefBuilder) ListProp

func (e *EntityDefBuilder) ListProp(name, propType string, required bool) *EntityDefBuilder

ListProp adds a multi-select property.

func (*EntityDefBuilder) Plural

func (e *EntityDefBuilder) Plural(plural string) *EntityDefBuilder

Plural sets the plural name (used for directory names).

func (*EntityDefBuilder) Prop

func (e *EntityDefBuilder) Prop(name, propType string, required bool) *EntityDefBuilder

Prop adds a simple property with just type and required flag.

func (*EntityDefBuilder) PropWithDefault

func (e *EntityDefBuilder) PropWithDefault(name, propType string, required bool, defaultVal string) *EntityDefBuilder

PropWithDefault adds a property with a default value.

type MetamodelBuilder

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

MetamodelBuilder provides a fluent interface for building test metamodels.

func NewMetamodel

func NewMetamodel() *MetamodelBuilder

NewMetamodel creates a new metamodel builder.

func (*MetamodelBuilder) Build

func (b *MetamodelBuilder) Build() *metamodel.Metamodel

Build returns the built metamodel, initializing the alias map.

func (*MetamodelBuilder) DefineEntity

func (b *MetamodelBuilder) DefineEntity(name string) *EntityDefBuilder

DefineEntity starts building an entity definition with the fluent API. Call End() to finish.

func (*MetamodelBuilder) WithAutomation

func (b *MetamodelBuilder) WithAutomation(auto metamodel.AutomationDef) *MetamodelBuilder

WithAutomation adds an automation rule to the metamodel.

func (*MetamodelBuilder) WithCustomType

func (b *MetamodelBuilder) WithCustomType(name string, values []string) *MetamodelBuilder

WithCustomType adds a custom type to the metamodel.

func (*MetamodelBuilder) WithCustomTypeDefault

func (b *MetamodelBuilder) WithCustomTypeDefault(name string, values []string, defaultVal string) *MetamodelBuilder

WithCustomTypeDefault adds a custom type with a default value.

func (*MetamodelBuilder) WithEntity

func (b *MetamodelBuilder) WithEntity(name, label string, idPatterns []string) *MetamodelBuilder

WithEntity adds an entity definition with common defaults (simple 3-arg form).

func (*MetamodelBuilder) WithEntityProperty

func (b *MetamodelBuilder) WithEntityProperty(entityName, propName, propType string, required bool) *MetamodelBuilder

WithEntityProperty adds a property to an entity definition.

func (*MetamodelBuilder) WithRelation

func (b *MetamodelBuilder) WithRelation(name, label string, from, to []string) *MetamodelBuilder

WithRelation adds a relation definition to the metamodel.

func (*MetamodelBuilder) WithRelationCardinality

func (b *MetamodelBuilder) WithRelationCardinality(
	name, label string,
	from, to []string,
	minOut, maxOut, minIn, maxIn *int,
) *MetamodelBuilder

WithRelationCardinality adds a relation with cardinality constraints.

func (*MetamodelBuilder) WithSetOnCreate

func (b *MetamodelBuilder) WithSetOnCreate(entityTypes []string, propName, value string) *MetamodelBuilder

WithSetOnCreate adds an automation that sets a property when an entity is created.

func (*MetamodelBuilder) WithValidation

func (b *MetamodelBuilder) WithValidation(rule metamodel.ValidationRule) *MetamodelBuilder

WithValidation appends a validation rule to the metamodel. Use for tests whose subject is the rule itself (when/then or Lua) — the rule stays at the call site while the entity-shape boilerplate comes from the builder.

type RelationBuilder

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

RelationBuilder provides a fluent interface for building test relations. Builders should not be reused after Build() - each call creates a fresh builder.

func NewRelation

func NewRelation(from, relationType, to string) *RelationBuilder

NewRelation creates a new relation builder with from, type, and to already set.

func Relation

func Relation(relationType string) *RelationBuilder

Relation creates a new relation builder with just the relation type. Use From() and To() to set the source and target entity IDs.

func (*RelationBuilder) Build

func (b *RelationBuilder) Build() *entity.Relation

Build returns the built relation. Panics if From or To are not set.

func (*RelationBuilder) From

func (b *RelationBuilder) From(id string) *RelationBuilder

From sets the source entity ID.

func (*RelationBuilder) To

To sets the target entity ID.

func (*RelationBuilder) WithContent

func (b *RelationBuilder) WithContent(content string) *RelationBuilder

WithContent sets the relation's markdown content.

func (*RelationBuilder) WithProperty

func (b *RelationBuilder) WithProperty(key string, value interface{}) *RelationBuilder

WithProperty adds a property to the relation.

Jump to

Keyboard shortcuts

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