Documentation ¶
Overview ¶
Package specs
Summary ¶
This package implements generic CRUD operation related testing specifications that commonly appears upon interacting with external resources.
Reason for separate pkg from resources pkg ¶
This package originally was part of the resources pkg, but package "testing" has side effects on import. In order to avoid force the import on the implementations, the specs had to be extracted into a separate package. Since testing#T.Run is heavily used, abstracting testing.T away is difficult.
Minimum Requirement from Resource point of view ¶
In order to make this package work, you have to implement the TestMinimumRequirementsWithExampleEntities specification. Most of the other Resource specs specification depends on the Resource specs mentioned in the min requirement specification. Keep in mind, that you have no guarantee on your Resource content during test execution, because some specification may alter the content of the Resource (db), or delete from it. If you need specific data in the Resource you want to test with, you must ensure in the test execution that such Context is correctly provisioned, and after test execution, cleaned up. If you use such data-set in a external Resource that needs to be kept intact, I advise you to use separate environments for test execution and manual testing.
Requirement from Business Entities ¶
This package depends on a fact that there is a string field ID in a business entity struct, or at least a tag `ext:"ID"`. This allows the package to create specifications that assumes, that the ID field links the EntityTypeName structure to an external Resource object. The Resource specs package doesn't care about the content of the ID string field, and don't have assumptions other than the existence of the field ID on a struct
Index ¶
- Constants
- Variables
- func CreateEntity(tb testing.TB, subject CRD, ctx context.Context, ptr interface{})
- func CreatePTR(ff frameless.FixtureFactory, T T) interface{}
- func DeleteAllEntity(tb testing.TB, subject CRD, ctx context.Context)
- func DeleteEntity(tb testing.TB, subject CRD, ctx context.Context, ent interface{})
- func HasEntity(tb testing.TB, subject frameless.Finder, ctx context.Context, ent interface{})
- func HasID(tb testing.TB, ent interface{}) (id interface{})
- func IsAbsent(tb testing.TB, T T, subject frameless.Finder, ctx context.Context, ...)
- func IsFindable(tb testing.TB, T T, subject frameless.Finder, ctx context.Context, ...) interface{}
- func UpdateEntity(tb testing.TB, subject interface{ ... }, ctx context.Context, ptr interface{})
- type CRD
- type Creator
- type Deleter
- type FindOne
- type Finder
- type FixtureFactory
- type Interface
- type MetaAccessor
- type MetaAccessorBasic
- type MetaAccessorPublisher
- type MetaAccessorSubject
- type OnePhaseCommitProtocol
- type Publisher
- type PublisherSubject
- type QueryOne
- type T
- type Updater
- type UpdaterSubject
Constants ¶
const ErrIDRequired frameless.Error = `` /* 174-byte string literal not displayed */
Variables ¶
var AsyncTester = testcase.Retry{Strategy: Waiter}
var Waiter = testcase.Waiter{ WaitDuration: time.Millisecond, WaitTimeout: 5 * time.Second, }
Functions ¶
func CreateEntity ¶
func CreatePTR ¶ added in v0.43.1
func CreatePTR(ff frameless.FixtureFactory, T T) interface{}
func DeleteEntity ¶
func IsFindable ¶
Types ¶
type Creator ¶
type Deleter ¶
type FindOne ¶
type FindOne struct { T Subject func(testing.TB) CRD Context func(testing.TB) context.Context FixtureFactory func(testing.TB) frameless.FixtureFactory // MethodName is the name of the test subject QueryOne method of this contract specification. MethodName string // ToQuery takes an entity ptr and returns with a closure that has the knowledge about how to query on the Subject resource to find the entity. // // By convention, any preparation action that affect the Storage must take place prior to returning the closure. // The QueryOne closure should only have the Method call with the already mapped values. // ToQuery will be evaluated in the beginning of the testing, // and executed after all the test Context preparation is done. ToQuery func(tb testing.TB, resource interface{}, ent T) QueryOne // Specify allow further specification describing for a given FindOne query function. // If none specified, this field will be ignored Specify func(testing.TB) }
type Finder ¶
type FixtureFactory ¶
type FixtureFactory struct { T interface{} Subject func(testing.TB) frameless.FixtureFactory Context func(testing.TB) context.Context }
func (FixtureFactory) Benchmark ¶ added in v0.49.0
func (c FixtureFactory) Benchmark(b *testing.B)
func (FixtureFactory) Spec ¶ added in v0.49.0
func (c FixtureFactory) Spec(s *testcase.Spec)
func (FixtureFactory) String ¶ added in v0.49.0
func (c FixtureFactory) String() string
func (FixtureFactory) Test ¶ added in v0.49.0
func (c FixtureFactory) Test(t *testing.T)
type Interface ¶
type Interface interface { testcase.Contract testcase.OpenContract }
Interface represent a resource specification also known as "contract".
The main goal of a resource Spec is to introduce dependency injection pattern at logical level between consumers and suppliers. In other words any expectations from a consumer/interactor/use-case towards a used dependency should be defined in a contract. This allows architecture flexibility since the expectations not bound to a certain technology, but purely high level and as such can be implemented in various ways.
Using resource Spec also force the writer of the Spec to keep things at high level and only focus on the expected behavior, instead of going into implementation details.
type MetaAccessor ¶ added in v0.43.1
type MetaAccessor struct {
T, V T
Subject func(testing.TB) MetaAccessorSubject
Context func(testing.TB) context.Context
FixtureFactory func(testing.TB) frameless.FixtureFactory
}
func (MetaAccessor) Benchmark ¶ added in v0.43.1
func (c MetaAccessor) Benchmark(b *testing.B)
func (MetaAccessor) Spec ¶ added in v0.43.1
func (c MetaAccessor) Spec(s *testcase.Spec)
func (MetaAccessor) Test ¶ added in v0.43.1
func (c MetaAccessor) Test(t *testing.T)
type MetaAccessorBasic ¶ added in v0.43.1
type MetaAccessorBasic struct { // V is the value T type that can be set and looked up with frameless.MetaAccessor. V T Subject func(testing.TB) frameless.MetaAccessor FixtureFactory func(testing.TB) frameless.FixtureFactory }
func (MetaAccessorBasic) Benchmark ¶ added in v0.43.1
func (c MetaAccessorBasic) Benchmark(b *testing.B)
func (MetaAccessorBasic) Spec ¶ added in v0.43.1
func (c MetaAccessorBasic) Spec(s *testcase.Spec)
func (MetaAccessorBasic) Test ¶ added in v0.43.1
func (c MetaAccessorBasic) Test(t *testing.T)
type MetaAccessorPublisher ¶ added in v0.43.1
type MetaAccessorPublisher struct {
T, V T
Subject func(testing.TB) MetaAccessorSubject
Context func(testing.TB) context.Context
FixtureFactory func(testing.TB) frameless.FixtureFactory
}
func (MetaAccessorPublisher) Benchmark ¶ added in v0.43.1
func (c MetaAccessorPublisher) Benchmark(b *testing.B)
func (MetaAccessorPublisher) Spec ¶ added in v0.43.1
func (c MetaAccessorPublisher) Spec(s *testcase.Spec)
func (MetaAccessorPublisher) Test ¶ added in v0.43.1
func (c MetaAccessorPublisher) Test(t *testing.T)
type MetaAccessorSubject ¶ added in v0.43.1
type MetaAccessorSubject struct { frameless.MetaAccessor CRD frameless.Publisher }
type OnePhaseCommitProtocol ¶
type OnePhaseCommitProtocol struct { T Subject func(testing.TB) (frameless.OnePhaseCommitProtocol, CRD) Context func(testing.TB) context.Context FixtureFactory func(testing.TB) frameless.FixtureFactory }
func (OnePhaseCommitProtocol) Benchmark ¶
func (c OnePhaseCommitProtocol) Benchmark(b *testing.B)
func (OnePhaseCommitProtocol) Spec ¶
func (c OnePhaseCommitProtocol) Spec(s *testcase.Spec)
func (OnePhaseCommitProtocol) Test ¶
func (c OnePhaseCommitProtocol) Test(t *testing.T)
type Publisher ¶ added in v0.41.0
type PublisherSubject ¶ added in v0.41.0
type QueryOne ¶
QueryOne 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.
QueryOne is generated through ToQuery factory function in FindOne resource contract specification.
type Updater ¶
type Updater struct { T T Subject func(testing.TB) UpdaterSubject Context func(testing.TB) context.Context FixtureFactory func(testing.TB) frameless.FixtureFactory }
Updater will request an update for a wrapped entity object in the Resource