sdtest

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package sdtest test utilities to mock service discovery client

Index

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

func SetupServicesWithFile(di *DI, fsys fs.FS, path string) test.SetupFunc

SetupServicesWithFile is a test setup function that read service definitions from a YAML file and mock the discovery client

func SetupServicesWithProperties

func SetupServicesWithProperties(di *DI, prefix string) test.SetupFunc

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

type InstanceMockMatcher func(inst *discovery.Instance) bool

func AnyInstance

func AnyInstance() InstanceMockMatcher

func InstanceAfterN

func InstanceAfterN(n int) InstanceMockMatcher

func NthInstance

func NthInstance(n int) InstanceMockMatcher

type InstanceMockOptions

type InstanceMockOptions func(inst *discovery.Instance)

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) MockError

func (i *InstancerMock) MockError(what error, when time.Time)

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 SDMockOption

type SDMockOption struct {
	FS               fs.FS
	DefPath          string
	PropertiesPrefix string
}

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

Jump to

Keyboard shortcuts

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