crudcontracts

package
v0.297.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllDeleter

func AllDeleter[ENT, ID any](subject allDeleterSubjectResource[ENT, ID], opts ...Option[ENT, ID]) contract.Contract

func AllFinder

func AllFinder[ENT, ID any](subject crud.AllFinder[ENT], opts ...Option[ENT, ID]) contract.Contract

AllFinder can return business entities from a given resource that implement it's test The "EntityTypeName" is an Empty struct for the specific entity (struct) type that should be returned.

NewEntityForTest used only for testing and should not be provided outside of testing

func ByIDDeleter

func ByIDDeleter[ENT, ID any](subject crud.ByIDDeleter[ID], opts ...Option[ENT, ID]) contract.Contract

func ByIDFinder

func ByIDFinder[ENT, ID any](subject crud.ByIDFinder[ENT, ID], opts ...Option[ENT, ID]) contract.Contract

func ByIDsFinder

func ByIDsFinder[ENT, ID any](subject crud.ByIDsFinder[ENT, ID], opts ...Option[ENT, ID]) contract.Contract

func Creator

func Creator[ENT, ID any](subject crud.Creator[ENT], opts ...Option[ENT, ID]) contract.Contract

func Deleter

func Deleter[Entity, ID any](subject deleterSubject[Entity, ID], opts ...Option[Entity, ID]) contract.Contract

func Finder

func Finder[ENT, ID any](subject subjectFinder[ENT, ID], opts ...Option[ENT, ID]) contract.Contract

func OnePhaseCommitProtocol

func OnePhaseCommitProtocol[ENT, ID any](subject any, manager comproto.OnePhaseCommitProtocol, opts ...Option[ENT, ID]) contract.Contract

func Purger

func Purger[Entity, ID any](subject purgerSubjectResource[Entity, ID], opts ...Option[Entity, ID]) contract.Contract

func QueryMany

func QueryMany[ENT, ID any](
	resource any,
	methodName string,
	subject func(testing.TB) QueryManySubject[ENT],
	opts ...Option[ENT, ID],
) contract.Contract

func QueryOne

func QueryOne[ENT, ID any](
	resource any,
	methodName string,
	subject func(tb testing.TB) QueryOneSubject[ENT],
	opts ...Option[ENT, ID],
) contract.Contract

func Saver added in v0.242.0

func Saver[ENT, ID any](subject crud.Saver[ENT], opts ...Option[ENT, ID]) contract.Contract

func Updater

func Updater[ENT, ID any](subject crud.Updater[ENT], opts ...Option[ENT, ID]) contract.Contract

Updater will request an update for a wrapped entity object in the Resource

Types

type Config

type Config[ENT, ID any] struct {
	// MakeContext is responsible to return back a backgrond context for testing with the crud contract subject.
	MakeContext func(testing.TB) context.Context
	// MakeEntity is responsible to create a populated Entity.
	MakeEntity func(testing.TB) ENT
	// SupportIDReuse is an optional configuration value that tells the contract
	// that recreating an entity with an ID which belongs to a previously deleted entity is accepted.
	SupportIDReuse bool
	// SupportRecreate is an optional configuration value that tells the contract
	// that deleting an Entity then recreating it with the same values is supported by the Creator.
	SupportRecreate bool
	// ChangeEntity is an optional configuration field for tests that involve updating an entity.
	// This field express what Entity fields are allowed to be changed by the user of the Updater crud interface.
	// For example, if the changed Entity field is ignored by the Update method,
	// you can match this by not changing the Entity field as part of the ChangeEntity function.
	ChangeEntity func(testing.TB, *ENT)
	// ExampleEntity is an optional field that able to return back an example Entity.
	// The Entity should have a valid ID and should exist in the resource which is being tested.
	//
	// ExampleEntity enables testing a resource that doesn't implement the crud.Creator interface.
	ExampleEntity func(testing.TB) ENT
	// IDA [optional] is the ID Accessor.
	// Configure this if you don't use the ext:"id" tag in your entity.
	// TODO: add support for this accessor in crudtest
	IDA extid.Accessor[ENT, ID]

	// LazyNotFoundError will allow QueryMany methods to return crud.ErrNotFound during the iteration,
	// instead during the method call.
	// For e.g.: crud.ByIDsFinder[ENT, ID]
	LazyNotFoundError bool
}

func (Config[ENT, ID]) Configure

func (c Config[ENT, ID]) Configure(config *Config[ENT, ID])

func (*Config[ENT, ID]) Helper added in v0.296.0

func (c *Config[ENT, ID]) Helper() crudtest.Helper[ENT, ID]

func (*Config[ENT, ID]) Init

func (c *Config[ENT, ID]) Init()

func (Config[ENT, ID]) ModifyEntity added in v0.247.0

func (c Config[ENT, ID]) ModifyEntity(tb testing.TB, ptr *ENT)

type Contract

type Contract interface {
	testcase.Suite
	testcase.OpenSuite
}

type Option

type Option[ENT, ID any] option.Option[Config[ENT, ID]]

type QueryManySubject added in v0.244.0

type QueryManySubject[ENT any] struct {
	// Query creates a query that expected to find the ExpectedEntity
	//
	// By convention, any preparation action that affect the resource must take place prior to returning the closure.
	// The QueryOneFunc closure should only have the Method call with the already mapped values.
	// Query will be evaluated in the beginning of the testing,
	// and executed after all the test Context preparation is done.
	//
	// The func signature for Query is the generic representation of a query that meant to find one result.
	// It is really similar to resources.Finder#FindByID,
	// with the exception that the closure meant to know the query method name on the subject and the inputs it requires.
	Query func(ctx context.Context) iter.Seq2[ENT, error]
	// IncludedEntity return an entity that is matched by the QueryManyFunc.
	// If subject doesn't support Creator, then it should be present in the subject resource.
	IncludedEntity func() ENT
	// MakeExcludedEntity is an optional property,
	// that could be used ensure the query returns only the expected values.
	// If subject doesn't support Creator, then it should be present in the subject resource.
	ExcludedEntity func() ENT
}

type QueryOneSubject added in v0.244.0

type QueryOneSubject[ENT any] struct {
	// Query creates a query that expected to find the ExpectedEntity
	//
	// By convention, any preparation action that affect the resource must take place prior to returning the closure.
	// The QueryOneFunc closure should only have the Method call with the already mapped values.
	// Query will be evaluated in the beginning of the testing,
	// and executed after all the test Context preparation is done.
	//
	// The func signature for Query is the generic representation of a query that meant to find one result.
	// It is really similar to resources.Finder#FindByID,
	// with the exception that the closure meant to know the query method name on the subject and the inputs it requires.
	Query func(ctx context.Context) (_ ENT, found bool, _ error)
	// ExpectedEntity is an entity that is matched by the Query.
	// If subject doesn't support Creator, then it should be present in the subject resource.
	ExpectedEntity ENT
	// MakeExcludedEntity is an optional property,
	// that could be used ensure the query returns only the expected values.
	// If subject doesn't support Creator, then it should be present in the subject resource.
	ExcludedEntity func() ENT
}

type TestingTBContextKey

type TestingTBContextKey struct{}

Jump to

Keyboard shortcuts

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