specs

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

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

View Source
const ErrIDRequired frameless.Error = `` /* 174-byte string literal not displayed */

Variables

This section is empty.

Functions

func BenchmarkEntityVolumeCount

func BenchmarkEntityVolumeCount() int

func TestUniqConstrain

func TestUniqConstrain(t *testing.T, r minimumRequirements, e interface{}, f FixtureFactory, uniqConstrain ...string)

Types

type CommonSpec

type CommonSpec struct {
	EntityType interface{}
	FixtureFactory
	Subject interface {
		resources.Updater
		// contains filtered or unexported methods
	}
}

func (CommonSpec) Benchmark

func (spec CommonSpec) Benchmark(b *testing.B)

func (CommonSpec) Test

func (spec CommonSpec) Test(t *testing.T)

type CreatorPublisherSpec added in v0.8.0

type CreatorPublisherSpec struct {
	Subject interface {
		resources.CreatorPublisher
		// contains filtered or unexported methods
	}
	EntityType     interface{}
	FixtureFactory FixtureFactory
}

func (CreatorPublisherSpec) Benchmark added in v0.8.0

func (spec CreatorPublisherSpec) Benchmark(b *testing.B)

func (CreatorPublisherSpec) Spec added in v0.8.0

func (spec CreatorPublisherSpec) Spec(s *testcase.Spec)

func (CreatorPublisherSpec) Test added in v0.8.0

func (spec CreatorPublisherSpec) Test(t *testing.T)

type CreatorSpec

type CreatorSpec struct {
	EntityType interface{}
	FixtureFactory
	Subject minimumRequirements
}

func (CreatorSpec) Benchmark

func (spec CreatorSpec) Benchmark(b *testing.B)

func (CreatorSpec) Test

func (spec CreatorSpec) Test(t *testing.T)

type DeleterPublisherSpec added in v0.8.0

type DeleterPublisherSpec struct {
	Subject interface {
		resources.DeleterPublisher
		// contains filtered or unexported methods
	}
	EntityType     interface{}
	FixtureFactory FixtureFactory
}

func (DeleterPublisherSpec) Benchmark added in v0.8.0

func (spec DeleterPublisherSpec) Benchmark(b *testing.B)

func (DeleterPublisherSpec) Spec added in v0.8.0

func (spec DeleterPublisherSpec) Spec(s *testcase.Spec)

func (DeleterPublisherSpec) Test added in v0.8.0

func (spec DeleterPublisherSpec) Test(t *testing.T)

type DeleterSpec

type DeleterSpec struct {
	EntityType interface{}
	FixtureFactory
	Subject minimumRequirements
}

func (DeleterSpec) Benchmark

func (spec DeleterSpec) Benchmark(b *testing.B)

func (DeleterSpec) Test

func (spec DeleterSpec) Test(t *testing.T)

type FinderSpec

type FinderSpec struct {
	EntityType interface{}
	FixtureFactory
	Subject minimumRequirements
}

func (FinderSpec) Benchmark

func (spec FinderSpec) Benchmark(b *testing.B)

func (FinderSpec) Test

func (spec FinderSpec) Test(t *testing.T)

type FixtureFactory

type FixtureFactory interface {
	// Create create a newEntityBasedOn struct instance based on the received input struct type.
	// Create also populate the struct field with dummy values.
	// It is expected that the newly created fixture will have no content for extID field.
	Create(EntityType interface{}) (StructPTR interface{})
	// Context able to provide the specs with a context object for a certain entity Type.
	Context() (ctx context.Context)
}

type FixtureFactorySpec

type FixtureFactorySpec struct {
	Type interface{}
	FixtureFactory
}

func (FixtureFactorySpec) Test

func (spec FixtureFactorySpec) Test(t *testing.T)

type OnePhaseCommitProtocolSpec added in v0.6.0

type OnePhaseCommitProtocolSpec struct {
	EntityType     interface{}
	FixtureFactory FixtureFactory
	Subject        interface {
		resources.OnePhaseCommitProtocol
		// contains filtered or unexported methods
	}
}

func (OnePhaseCommitProtocolSpec) Benchmark added in v0.6.0

func (spec OnePhaseCommitProtocolSpec) Benchmark(b *testing.B)

func (OnePhaseCommitProtocolSpec) Spec added in v0.6.1

func (spec OnePhaseCommitProtocolSpec) Spec(tb testing.TB)

func (OnePhaseCommitProtocolSpec) Test added in v0.6.0

func (spec OnePhaseCommitProtocolSpec) Test(t *testing.T)

type UniqConstrainSpec

type UniqConstrainSpec struct {
	// Struct that is the subject of this spec
	EntityType interface{}
	FixtureFactory

	// the combination of which the values must be uniq
	// The values for this are the struct Fields that together represent a uniq constrain
	// if you only want to make uniq one certain field across the Resource,
	// then you only have to provide that only value in the slice
	UniqConstrain []string

	// the Resource object that implements the specification
	Subject minimumRequirements
}

func (UniqConstrainSpec) Benchmark

func (spec UniqConstrainSpec) Benchmark(b *testing.B)

func (UniqConstrainSpec) Test

func (spec UniqConstrainSpec) Test(t *testing.T)

type UpdaterPublisherSpec added in v0.8.0

type UpdaterPublisherSpec struct {
	Subject interface {
		resources.Updater
		resources.UpdaterPublisher
		// contains filtered or unexported methods
	}
	EntityType     interface{}
	FixtureFactory FixtureFactory
}

func (UpdaterPublisherSpec) Benchmark added in v0.8.0

func (spec UpdaterPublisherSpec) Benchmark(b *testing.B)

func (UpdaterPublisherSpec) Spec added in v0.8.0

func (spec UpdaterPublisherSpec) Spec(s *testcase.Spec)

func (UpdaterPublisherSpec) Test added in v0.8.0

func (spec UpdaterPublisherSpec) Test(t *testing.T)

type UpdaterSpec

type UpdaterSpec struct {
	EntityType interface{}
	FixtureFactory
	Subject updateSpecSubject
}

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

func (UpdaterSpec) Benchmark

func (spec UpdaterSpec) Benchmark(b *testing.B)

func (UpdaterSpec) Test

func (spec UpdaterSpec) Test(t *testing.T)

Jump to

Keyboard shortcuts

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