crudcontracts

package
v0.235.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllDeleter

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

func AllFinder

func AllFinder[Entity, ID any](subject crud.AllFinder[Entity], opts ...Option[Entity, 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[Entity, ID any](subject crd[Entity, ID], opts ...Option[Entity, ID]) contract.Contract

func ByIDFinder

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

func ByIDsFinder

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

func Creator

func Creator[Entity, ID any](subject crd[Entity, ID], opts ...Option[Entity, ID]) contract.Contract

func Deleter

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

func Finder

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

func OnePhaseCommitProtocol

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

func Purger

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

func QueryMany

func QueryMany[Entity, ID any](
	subject any,

	query QueryManyFunc[Entity],

	IncludedEntity func(tb testing.TB) Entity,

	ExcludedEntity func(tb testing.TB) Entity,
	opts ...Option[Entity, ID],
) contract.Contract

func QueryOne

func QueryOne[Entity, ID any](subject any, query QueryOneFunc[Entity], opts ...Option[Entity, ID]) contract.Contract

func Updater

func Updater[Entity, ID any](ssubject subjectUpdater[Entity, ID], opts ...Option[Entity, 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() 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
}

func (Config[ENT, ID]) Configure

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

func (*Config[ENT, ID]) Init

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

type Contract

type Contract interface {
	testcase.Suite
	testcase.OpenSuite
}

type Option

type Option[ENT, ID any] interface {
	option.Option[Config[ENT, ID]]
}

type QueryManyFunc

type QueryManyFunc[Entity any] func(tb testing.TB, ctx context.Context) iterators.Iterator[Entity]

type QueryOneFunc

type QueryOneFunc[Entity any] func(tb testing.TB, ctx context.Context, ent Entity) (_ Entity, found bool, _ error)

Query takes an entity value and returns with a closure that has the knowledge about how to query resource to find passed entity.

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.

type TestingTBContextKey

type TestingTBContextKey struct{}

Jump to

Keyboard shortcuts

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