plugin

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypePluginer bit.Mask = 1 << iota
	TypeReceiver
	TypeSender
	TypeFilter
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Err  error
	Code ErrorCode
}

Error wraps a plugin's errors. Because this package will have no knowledge of which plugins it's importing, the convention is for the plugin to set a Code associated with the plugin.

func (*Error) Error

func (e *Error) Error() string

Error implements the standard error interface.

Output:

plugin error (code=42): wrapped Err.Error() goes here

func (*Error) Is

func (e *Error) Is(target error) bool

Is compares two Error. It does a simple string comparison. This means that references to memory at different addresses for the same key will result in different strings, thus causing `Is` to return false.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap implement's Go v1.13's error pattern

type ErrorCode

type ErrorCode int

ErrorCode holds a numeric value that can be used to communicate an enumerated list of error codes back to the caller. It is expected that the user of the plugin will reference the plugin documentation to determine the meaning of the error.

type HashFn

type HashFn func(i interface{}) (string, error)

type Hasher

type Hasher interface {
	// PluginerHash calculates the hash of a receiver based on the
	// given configuration
	PluginerHash(config interface{}) (string, error)
}

Hasher defines the hashing interface that a pluginer needs to implement

type HasherMock

type HasherMock struct {
	// PluginerHashFunc mocks the PluginerHash method.
	PluginerHashFunc func(config interface{}) (string, error)
	// contains filtered or unexported fields
}

HasherMock is a mock implementation of Hasher.

func TestSomethingThatUsesHasher(t *testing.T) {

	// make and configure a mocked Hasher
	mockedHasher := &HasherMock{
		PluginerHashFunc: func(config interface{}) (string, error) {
			panic("mock out the PluginerHash method")
		},
	}

	// use mockedHasher in code that requires Hasher
	// and then make assertions.

}

func (*HasherMock) PluginerHash

func (mock *HasherMock) PluginerHash(config interface{}) (string, error)

PluginerHash calls PluginerHashFunc.

func (*HasherMock) PluginerHashCalls

func (mock *HasherMock) PluginerHashCalls() []struct {
	Config interface{}
}

PluginerHashCalls gets all the calls that were made to PluginerHash. Check the length with:

len(mockedHasher.PluginerHashCalls())

type InvalidConfigError

type InvalidConfigError struct {
	Err error
}

InvalidConfigError is returned when a configuration parameter results in a plugin error

func (*InvalidConfigError) Error

func (e *InvalidConfigError) Error() string

Error implements the standard error interface. It'll display the code as well printing out the Values in key sorted order.

func (*InvalidConfigError) Is

func (e *InvalidConfigError) Is(target error) bool

Is compares two Error. It does a simple string comparison. This means that references to memory at different addresses for the same key will result in different strings, thus causing `Is` to return false.

func (*InvalidConfigError) Unwrap

func (e *InvalidConfigError) Unwrap() error

Unwrap implement's Go v1.13's error pattern

type NewFiltererFn

type NewFiltererFn func(tid tenant.Id, plugin string, name string, config interface{}, secrets secret.Vault, tableSyncer syncer.DeltaSyncer) (filter.Filterer, error)

type NewPluginerFn

type NewPluginerFn func(config interface{}) (Pluginer, error)

type NewPluginerer

type NewPluginerer interface {
	Hasher
	NewPluginer(config interface{}) (Pluginer, error)
}

NewPluginerer is something that is able to return a new Pluginer

type NewPluginererMock

type NewPluginererMock struct {
	// NewPluginerFunc mocks the NewPluginer method.
	NewPluginerFunc func(config interface{}) (Pluginer, error)

	// PluginerHashFunc mocks the PluginerHash method.
	PluginerHashFunc func(config interface{}) (string, error)
	// contains filtered or unexported fields
}

NewPluginererMock is a mock implementation of NewPluginerer.

func TestSomethingThatUsesNewPluginerer(t *testing.T) {

	// make and configure a mocked NewPluginerer
	mockedNewPluginerer := &NewPluginererMock{
		NewPluginerFunc: func(config interface{}) (Pluginer, error) {
			panic("mock out the NewPluginer method")
		},
		PluginerHashFunc: func(config interface{}) (string, error) {
			panic("mock out the PluginerHash method")
		},
	}

	// use mockedNewPluginerer in code that requires NewPluginerer
	// and then make assertions.

}

func (*NewPluginererMock) NewPluginer

func (mock *NewPluginererMock) NewPluginer(config interface{}) (Pluginer, error)

NewPluginer calls NewPluginerFunc.

func (*NewPluginererMock) NewPluginerCalls

func (mock *NewPluginererMock) NewPluginerCalls() []struct {
	Config interface{}
}

NewPluginerCalls gets all the calls that were made to NewPluginer. Check the length with:

len(mockedNewPluginerer.NewPluginerCalls())

func (*NewPluginererMock) PluginerHash

func (mock *NewPluginererMock) PluginerHash(config interface{}) (string, error)

PluginerHash calls PluginerHashFunc.

func (*NewPluginererMock) PluginerHashCalls

func (mock *NewPluginererMock) PluginerHashCalls() []struct {
	Config interface{}
}

PluginerHashCalls gets all the calls that were made to PluginerHash. Check the length with:

len(mockedNewPluginerer.PluginerHashCalls())

type NewReceiverFn

type NewReceiverFn func(tid tenant.Id, plugin string, name string, config interface{}, secrets secret.Vault, tableSyncer syncer.DeltaSyncer) (receiver.Receiver, error)

type NewSenderFn

type NewSenderFn func(tid tenant.Id, plugin string, name string, config interface{}, secrets secret.Vault, tableSyncer syncer.DeltaSyncer) (sender.Sender, error)

type NilPluginError

type NilPluginError struct{}

func (*NilPluginError) Error

func (e *NilPluginError) Error() string

type NotSupportedError

type NotSupportedError struct{}

NotSupportedError can be returned if a plugin doesn't support publishing subscribing.

func (*NotSupportedError) Error

func (e *NotSupportedError) Error() string

Error implements the standard error interface. It'll display the code as well printing out the Values in key sorted order.

func (*NotSupportedError) Is

func (e *NotSupportedError) Is(target error) bool

Is compares two Error. It does a simple string comparison. This means that references to memory at different addresses for the same key will result in different strings, thus causing `Is` to return false.

type Option

type Option func(OptionProcessor) error

func WithCommitID

func WithCommitID(commitID string) Option

func WithConfig

func WithConfig(config interface{}) Option

func WithFilterHasher

func WithFilterHasher(fn HashFn) Option

func WithName

func WithName(name string) Option

func WithNewPluginer

func WithNewPluginer(fn NewPluginerFn) Option

func WithNewReceiver

func WithNewReceiver(fn NewReceiverFn) Option

func WithNewSender

func WithNewSender(fn NewSenderFn) Option

func WithPluginerHasher

func WithPluginerHasher(fn HashFn) Option

func WithReceiverHasher

func WithReceiverHasher(fn HashFn) Option

func WithSenderHasher

func WithSenderHasher(fn HashFn) Option

func WithVersion

func WithVersion(version string) Option

type OptionError

type OptionError struct {
	Err error
}

func (*OptionError) Error

func (e *OptionError) Error() string

TODO

type OptionProcessor

type OptionProcessor interface {
	WithName(name string) error
	WithVersion(version string) error
	WithCommitID(commitID string) error

	WithConfig(config interface{}) error

	WithNewPluginer(fn NewPluginerFn) error
	WithPluginerHasher(fn HashFn) error

	// TODO: https://github.com/xmidt-org/ears/issues/74
	WithNewFilterer(fn NewFiltererFn) error
	WithFilterHasher(fn HashFn) error

	WithNewReceiver(fn NewReceiverFn) error
	WithReceiverHasher(fn HashFn) error

	WithNewSender(fn NewSenderFn) error
	WithSenderHasher(fn HashFn) error
}

type Plugin

type Plugin struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Plugin implements Pluginer

func NewPlugin

func NewPlugin(options ...Option) (*Plugin, error)

func (*Plugin) CommitID

func (p *Plugin) CommitID() string

func (*Plugin) Config

func (p *Plugin) Config() string

func (*Plugin) FiltererHash

func (p *Plugin) FiltererHash(config interface{}) (string, error)

func (*Plugin) Name

func (p *Plugin) Name() string

func (*Plugin) NewFilterer

func (p *Plugin) NewFilterer(tid tenant.Id, plugin string, name string, config interface{}, secrets secret.Vault, tableSyncer syncer.DeltaSyncer) (filter.Filterer, error)

func (*Plugin) NewPluginer

func (p *Plugin) NewPluginer(config interface{}) (Pluginer, error)

func (*Plugin) NewReceiver

func (p *Plugin) NewReceiver(tid tenant.Id, plugin string, name string, config interface{}, secrets secret.Vault, tableSyncer syncer.DeltaSyncer) (receiver.Receiver, error)

func (*Plugin) NewSender

func (p *Plugin) NewSender(tid tenant.Id, plugin string, name string, config interface{}, secrets secret.Vault, tableSyncer syncer.DeltaSyncer) (sender.Sender, error)

func (*Plugin) PluginerHash

func (p *Plugin) PluginerHash(config interface{}) (string, error)

func (*Plugin) ReceiverHash

func (p *Plugin) ReceiverHash(config interface{}) (string, error)

func (*Plugin) SenderHash

func (p *Plugin) SenderHash(config interface{}) (string, error)

func (*Plugin) SupportedTypes

func (p *Plugin) SupportedTypes() bit.Mask

func (*Plugin) Version

func (p *Plugin) Version() string

func (*Plugin) WithCommitID

func (p *Plugin) WithCommitID(commitID string) error

func (*Plugin) WithConfig

func (p *Plugin) WithConfig(config interface{}) error

func (*Plugin) WithFilterHasher

func (p *Plugin) WithFilterHasher(fn HashFn) error

func (*Plugin) WithName

func (p *Plugin) WithName(name string) error

func (*Plugin) WithNewFilterer

func (p *Plugin) WithNewFilterer(fn NewFiltererFn) error

func (*Plugin) WithNewPluginer

func (p *Plugin) WithNewPluginer(fn NewPluginerFn) error

func (*Plugin) WithNewReceiver

func (p *Plugin) WithNewReceiver(fn NewReceiverFn) error

func (*Plugin) WithNewSender

func (p *Plugin) WithNewSender(fn NewSenderFn) error

func (*Plugin) WithPluginerHasher

func (p *Plugin) WithPluginerHasher(fn HashFn) error

func (*Plugin) WithReceiverHasher

func (p *Plugin) WithReceiverHasher(fn HashFn) error

func (*Plugin) WithSenderHasher

func (p *Plugin) WithSenderHasher(fn HashFn) error

func (*Plugin) WithVersion

func (p *Plugin) WithVersion(version string) error

type Pluginer

type Pluginer interface {
	Name() string
	Version() string
	CommitID() string
	Config() string

	// A bitmask of supported types
	SupportedTypes() bit.Mask
}

Pluginer defines values that should be returned in order to get visibility into which plugin was loaded and how it was configured.

type PluginerMock

type PluginerMock struct {
	// CommitIDFunc mocks the CommitID method.
	CommitIDFunc func() string

	// ConfigFunc mocks the Config method.
	ConfigFunc func() string

	// NameFunc mocks the Name method.
	NameFunc func() string

	// SupportedTypesFunc mocks the SupportedTypes method.
	SupportedTypesFunc func() bit.Mask

	// VersionFunc mocks the Version method.
	VersionFunc func() string
	// contains filtered or unexported fields
}

PluginerMock is a mock implementation of Pluginer.

func TestSomethingThatUsesPluginer(t *testing.T) {

	// make and configure a mocked Pluginer
	mockedPluginer := &PluginerMock{
		CommitIDFunc: func() string {
			panic("mock out the CommitID method")
		},
		ConfigFunc: func() string {
			panic("mock out the Config method")
		},
		NameFunc: func() string {
			panic("mock out the Name method")
		},
		SupportedTypesFunc: func() bit.Mask {
			panic("mock out the SupportedTypes method")
		},
		VersionFunc: func() string {
			panic("mock out the Version method")
		},
	}

	// use mockedPluginer in code that requires Pluginer
	// and then make assertions.

}

func (*PluginerMock) CommitID

func (mock *PluginerMock) CommitID() string

CommitID calls CommitIDFunc.

func (*PluginerMock) CommitIDCalls

func (mock *PluginerMock) CommitIDCalls() []struct {
}

CommitIDCalls gets all the calls that were made to CommitID. Check the length with:

len(mockedPluginer.CommitIDCalls())

func (*PluginerMock) Config

func (mock *PluginerMock) Config() string

Config calls ConfigFunc.

func (*PluginerMock) ConfigCalls

func (mock *PluginerMock) ConfigCalls() []struct {
}

ConfigCalls gets all the calls that were made to Config. Check the length with:

len(mockedPluginer.ConfigCalls())

func (*PluginerMock) Name

func (mock *PluginerMock) Name() string

Name calls NameFunc.

func (*PluginerMock) NameCalls

func (mock *PluginerMock) NameCalls() []struct {
}

NameCalls gets all the calls that were made to Name. Check the length with:

len(mockedPluginer.NameCalls())

func (*PluginerMock) SupportedTypes

func (mock *PluginerMock) SupportedTypes() bit.Mask

SupportedTypes calls SupportedTypesFunc.

func (*PluginerMock) SupportedTypesCalls

func (mock *PluginerMock) SupportedTypesCalls() []struct {
}

SupportedTypesCalls gets all the calls that were made to SupportedTypes. Check the length with:

len(mockedPluginer.SupportedTypesCalls())

func (*PluginerMock) Version

func (mock *PluginerMock) Version() string

Version calls VersionFunc.

func (*PluginerMock) VersionCalls

func (mock *PluginerMock) VersionCalls() []struct {
}

VersionCalls gets all the calls that were made to Version. Check the length with:

len(mockedPluginer.VersionCalls())

Jump to

Keyboard shortcuts

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