adaptor

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2017 License: BSD-3-Clause Imports: 7 Imported by: 24

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNamespaceMalformed = errors.New("malformed namespace, expected a '.' deliminated string")

ErrNamespaceMalformed represents the error to be returned when an invalid namespace is given.

Functions

func Adaptors

func Adaptors() map[string]Adaptor

Adaptors returns an non-initialized adaptor and is best used for doing assertions to see if the Adaptor supports other interfaces

func Add

func Add(name string, creator Creator)

Add should be called in init func of adaptor

func MockConfirmWrites added in v0.4.0

func MockConfirmWrites() (chan struct{}, func() bool)

MockConfirmWrites is a helper function for tests needing a confirms chan.

func RegisteredAdaptors added in v0.3.0

func RegisteredAdaptors() []string

RegisteredAdaptors returns a slice of the names of every adaptor registered.

func VerifyWriteConfirmed added in v0.4.0

func VerifyWriteConfirmed(f func() bool, t *testing.T)

VerifyWriteConfirmed is a helper function to be used in conjunction with MockConfirmWrites.

Types

type Adaptor

type Adaptor interface {
	Client() (client.Client, error)
	Reader() (client.Reader, error)
	Writer(chan struct{}, *sync.WaitGroup) (client.Writer, error)
}

Adaptor defines the interface which provides functions to create client interfaces

func GetAdaptor added in v0.3.0

func GetAdaptor(name string, conf Config) (Adaptor, error)

GetAdaptor looks up an adaptor by name and then init's it with the provided Config. returns ErrNotFound if the provided name was not registered.

type BaseConfig added in v0.3.0

type BaseConfig struct {
	URI     string `json:"uri"`
	Timeout string `json:"timeout"`
}

BaseConfig is a standard typed config struct to use for as general purpose config for most databases.

type Config

type Config map[string]interface{}

Config is an alias to map[string]interface{} and helps us turn a fuzzy document into a conrete named struct

func (*Config) Construct

func (c *Config) Construct(conf interface{}) error

Construct will Marshal the Config and then Unmarshal it into a named struct the generic map into a proper struct

func (Config) GetString

func (c Config) GetString(key string) string

GetString returns value stored in the config under the given key, or an empty string if the key doesn't exist, or isn't a string value

type Connectable

type Connectable interface {
	Connect() error
}

Connectable defines the interface that adapters should follow to have their connections set on load Connect() allows the adaptor an opportunity to setup connections prior to Start()

type Creator

type Creator func() Adaptor

Creator defines the init structure for an adaptor

type Describable

type Describable interface {
	SampleConfig() string
	Description() string
}

Describable defines the interface that all database connectors and nodes must follow in order to support the help functions. SampleConfig() returns an example JSON structure to configure the adaptor Description() provides contextual information for what the adaptor is for

type ErrFuncNotSupported added in v0.3.0

type ErrFuncNotSupported struct {
	Name string
	Func string
}

ErrFuncNotSupported should be used for adaptors that do not support a given function defined by the interface.

func (ErrFuncNotSupported) Error added in v0.3.0

func (a ErrFuncNotSupported) Error() string

type ErrNotFound

type ErrNotFound struct {
	Name string
}

ErrNotFound gives the details of the failed adaptor

func (ErrNotFound) Error

func (a ErrNotFound) Error() string

type Mock added in v0.3.0

type Mock struct {
	BaseConfig
}

Mock can be used for mocking tests that need no functional client interfaces.

func (*Mock) Client added in v0.3.0

func (m *Mock) Client() (client.Client, error)

Client satisfies the V2 interface for providing a client.Client.

func (*Mock) Reader added in v0.3.0

func (m *Mock) Reader() (client.Reader, error)

Reader satisfies the V2 interface for providing a client.Reader.

func (*Mock) Writer added in v0.3.0

func (m *Mock) Writer(chan struct{}, *sync.WaitGroup) (client.Writer, error)

Writer satisfies the V2 interface for providing a client.Writer.

type MockClientErr added in v0.4.0

type MockClientErr struct {
	BaseConfig
}

MockClientErr can be used to to mock client.Client() errors.

func (*MockClientErr) Client added in v0.4.0

func (m *MockClientErr) Client() (client.Client, error)

Client satisfies the client.Client interface.

func (*MockClientErr) Reader added in v0.4.0

func (m *MockClientErr) Reader() (client.Reader, error)

Reader satisfies client.Reader.

func (*MockClientErr) Writer added in v0.4.0

func (m *MockClientErr) Writer(chan struct{}, *sync.WaitGroup) (client.Writer, error)

Writer satisfies client.Writer.

type MockWriterErr added in v0.4.0

type MockWriterErr struct {
	BaseConfig
}

MockWriterErr can be used to to mock client.Write() errors.

func (*MockWriterErr) Client added in v0.4.0

func (m *MockWriterErr) Client() (client.Client, error)

Client satisfies the client.Client interface.

func (*MockWriterErr) Reader added in v0.4.0

func (m *MockWriterErr) Reader() (client.Reader, error)

Reader satisfies the V2 interface for providing a client.Reader.

func (*MockWriterErr) Writer added in v0.4.0

func (m *MockWriterErr) Writer(chan struct{}, *sync.WaitGroup) (client.Writer, error)

Writer satisfies the V2 interface for providing a client.Writer.

type UnsupportedMock added in v0.3.0

type UnsupportedMock struct {
	BaseConfig
}

UnsupportedMock can be used for mocking tests that need no functional client interfaces.

func (*UnsupportedMock) Client added in v0.3.0

func (m *UnsupportedMock) Client() (client.Client, error)

Client satisfies the V2 interface for providing a client.Client.

func (*UnsupportedMock) Reader added in v0.3.0

func (m *UnsupportedMock) Reader() (client.Reader, error)

Reader satisfies the V2 interface for providing a client.Reader.

func (*UnsupportedMock) Writer added in v0.3.0

func (m *UnsupportedMock) Writer(chan struct{}, *sync.WaitGroup) (client.Writer, error)

Writer satisfies the V2 interface for providing a client.Writer.

Jump to

Keyboard shortcuts

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