Documentation ¶
Overview ¶
Package sdtest test utilities to mock service discovery client
Index ¶
- func MockServices(client *ClientMock, services map[string][]*discovery.Instance) (err error)
- func MockServicesFromFile(client *ClientMock, fsys fs.FS, path string) error
- func MockServicesFromProperties(client *ClientMock, appCfg bootstrap.ApplicationConfig, prefix string) error
- func SetupServicesWithFile(di *DI, fsys fs.FS, path string) test.SetupFunc
- func SetupServicesWithProperties(di *DI, prefix string) test.SetupFunc
- func WithMockedSD(opts ...SDMockOptions) test.Options
- type ClientMock
- func (c *ClientMock) Context() context.Context
- func (c *ClientMock) Instancer(serviceName string) (discovery.Instancer, error)
- func (c *ClientMock) MockError(svcName string, what error, when time.Time)
- func (c *ClientMock) MockService(svcName string, count int, opts ...InstanceMockOptions) []*discovery.Instance
- func (c *ClientMock) UpdateMockedService(svcName string, matcher InstanceMockMatcher, opts ...InstanceMockOptions) (count int)
- type DI
- type InstanceMockMatcher
- type InstanceMockOptions
- type InstancerMock
- func (i *InstancerMock) DeregisterCallback(_ interface{})
- func (i *InstancerMock) Instances(matcher discovery.InstanceMatcher) ([]*discovery.Instance, error)
- func (i *InstancerMock) MockError(what error, when time.Time)
- func (i *InstancerMock) MockInstances(count int, opts ...InstanceMockOptions) []*discovery.Instance
- func (i *InstancerMock) RegisterCallback(_ interface{}, _ discovery.Callback)
- func (i *InstancerMock) Service() *discovery.Service
- func (i *InstancerMock) ServiceName() string
- func (i *InstancerMock) Start(_ context.Context)
- func (i *InstancerMock) Stop()
- func (i *InstancerMock) UpdateInstances(matcher InstanceMockMatcher, opts ...InstanceMockOptions) (count int)
- type SDMockOption
- type SDMockOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MockServices ¶
func MockServices(client *ClientMock, services map[string][]*discovery.Instance) (err error)
MockServices mocks given ClientMock with given services. The key is the service name
func MockServicesFromFile ¶
func MockServicesFromFile(client *ClientMock, fsys fs.FS, path string) error
MockServicesFromFile read YAML file for mocked service definition and mock ClientMock
func MockServicesFromProperties ¶
func MockServicesFromProperties(client *ClientMock, appCfg bootstrap.ApplicationConfig, prefix string) error
MockServicesFromProperties bind mocked service definitions from properties with given prefix and mock ClientMock
func SetupServicesWithFile ¶
SetupServicesWithFile is a test setup function that read service definitions from a YAML file and mock the discovery client
func SetupServicesWithProperties ¶
SetupServicesWithProperties is a test setup function that read service definitions from properties and mock the discovery client
func WithMockedSD ¶
func WithMockedSD(opts ...SDMockOptions) test.Options
Types ¶
type ClientMock ¶
type ClientMock struct { Instancers map[string]*InstancerMock // contains filtered or unexported fields }
func NewMockClient ¶
func NewMockClient(ctx context.Context) *ClientMock
func ProvideDiscoveryClient ¶
func ProvideDiscoveryClient(ctx *bootstrap.ApplicationContext) (discovery.Client, *ClientMock)
func (*ClientMock) Context ¶
func (c *ClientMock) Context() context.Context
func (*ClientMock) Instancer ¶
func (c *ClientMock) Instancer(serviceName string) (discovery.Instancer, error)
func (*ClientMock) MockError ¶
func (c *ClientMock) MockError(svcName string, what error, when time.Time)
func (*ClientMock) MockService ¶
func (c *ClientMock) MockService(svcName string, count int, opts ...InstanceMockOptions) []*discovery.Instance
func (*ClientMock) UpdateMockedService ¶
func (c *ClientMock) UpdateMockedService(svcName string, matcher InstanceMockMatcher, opts ...InstanceMockOptions) (count int)
type DI ¶
type DI struct { fx.In AppCtx *bootstrap.ApplicationContext Client *ClientMock }
type InstanceMockMatcher ¶
func AnyInstance ¶
func AnyInstance() InstanceMockMatcher
func InstanceAfterN ¶
func InstanceAfterN(n int) InstanceMockMatcher
func NthInstance ¶
func NthInstance(n int) InstanceMockMatcher
type InstanceMockOptions ¶
func BeCritical ¶
func BeCritical() InstanceMockOptions
func BeHealthy ¶
func BeHealthy() InstanceMockOptions
func WithExtraTag ¶
func WithExtraTag(tags ...string) InstanceMockOptions
func WithMeta ¶
func WithMeta(k, v string) InstanceMockOptions
type InstancerMock ¶
type InstancerMock struct { SName string InstanceMocks []*discovery.Instance ErrTimeMock time.Time ErrMock error Started bool // contains filtered or unexported fields }
func NewMockInstancer ¶
func NewMockInstancer(ctx context.Context, svcName string) *InstancerMock
func (*InstancerMock) DeregisterCallback ¶
func (i *InstancerMock) DeregisterCallback(_ interface{})
func (*InstancerMock) Instances ¶
func (i *InstancerMock) Instances(matcher discovery.InstanceMatcher) ([]*discovery.Instance, error)
func (*InstancerMock) MockInstances ¶
func (i *InstancerMock) MockInstances(count int, opts ...InstanceMockOptions) []*discovery.Instance
func (*InstancerMock) RegisterCallback ¶
func (i *InstancerMock) RegisterCallback(_ interface{}, _ discovery.Callback)
func (*InstancerMock) Service ¶
func (i *InstancerMock) Service() *discovery.Service
func (*InstancerMock) ServiceName ¶
func (i *InstancerMock) ServiceName() string
func (*InstancerMock) Start ¶
func (i *InstancerMock) Start(_ context.Context)
func (*InstancerMock) Stop ¶
func (i *InstancerMock) Stop()
func (*InstancerMock) UpdateInstances ¶
func (i *InstancerMock) UpdateInstances(matcher InstanceMockMatcher, opts ...InstanceMockOptions) (count int)
type SDMockOptions ¶
type SDMockOptions func(opt *SDMockOption)
func DefinitionWithPrefix ¶
func DefinitionWithPrefix(prefix string) SDMockOptions
DefinitionWithPrefix load service discovery mocking from application properties, with given prefix
func LoadDefinition ¶
func LoadDefinition(fsys fs.FS, path string) SDMockOptions
LoadDefinition load service discovery mocking from file system, this override DefinitionWithPrefix