mock

package
v1.7.11 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RawPlugins = map[string]RawPlugin{
	"http1": RawPlugin{
		PluginAPIVersion: pluginAPIVersion,
		PluginType:       "connector.http",
		PluginID:         "extHTTP1",
	},
	"http2": RawPlugin{
		PluginAPIVersion: pluginAPIVersion,
		PluginType:       "connector.http",
		PluginID:         "extHTTP2",
	},
	"tcp1": RawPlugin{
		PluginAPIVersion: pluginAPIVersion,
		PluginType:       "connector.tcp",
		PluginID:         "extTCP1",
	},
	"tcp2": RawPlugin{
		PluginAPIVersion: pluginAPIVersion,
		PluginType:       "connector.tcp",
		PluginID:         "extTCP2",
	},
	"tcp3": RawPlugin{
		PluginAPIVersion: pluginAPIVersion,
		PluginType:       "connector.tcp",
		PluginID:         "extTCP3",
	},
}

RawPlugins instantiates a map of RawPlugins for testing. Values of entries in this map should reflect values returned by HTTPExternalPluginsByID() and TCPExternalPluginsByID() above.

Functions

func AllHTTPPlugins

func AllHTTPPlugins() map[string]http.Plugin

AllHTTPPlugins returns map combining the HTTP internal and external mock plugins.

func AllTCPPlugins

func AllTCPPlugins() map[string]tcp.Plugin

AllTCPPlugins returns map combining the TCP internal and external mock plugins.

func ExternalPlugins

func ExternalPlugins() plugin.AvailablePlugins

ExternalPlugins creates a mock AvailablePlugins for external plugins.

func GetExternalPlugins

func GetExternalPlugins(
	pluginDir string,
	checksumfile string,
	logger log_api.Logger,
) (plugin.AvailablePlugins, error)

GetExternalPlugins is function that returns the mock external plugins. It's needed to satisfy arguments of type ExternalPluginLookupFunc.

func GetInternalPlugins

func GetInternalPlugins() (plugin.AvailablePlugins, error)

GetInternalPlugins is function that returns the mock internal plugins. It's needed to satisfy arguments of type InternalPluginLookupFunc.

func HTTPExternalPluginsByID

func HTTPExternalPluginsByID() map[string]http.Plugin

HTTPExternalPluginsByID returns mock HTTP plugins with external ids.

func HTTPInternalPluginsByID

func HTTPInternalPluginsByID() map[string]http.Plugin

HTTPInternalPluginsByID returns mock HTTP plugins with internal ids.

func InternalPlugins

func InternalPlugins() plugin.AvailablePlugins

InternalPlugins creates a mock AvailablePlugins for internal plugins.

func NewLogger

func NewLogger() log_api.Logger

NewLogger returns a mock Logger.

func TCPExternalPluginsByID

func TCPExternalPluginsByID() map[string]tcp.Plugin

TCPExternalPluginsByID returns mock TCP plugins with external ids.

func TCPInternalPluginsByID

func TCPInternalPluginsByID() map[string]tcp.Plugin

TCPInternalPluginsByID returns mock TCP plugins with internal ids.

Types

type HTTPPlugin

type HTTPPlugin struct {
	http.Plugin
	// contains filtered or unexported fields
}

HTTPPlugin is a mock struct that implements http.Plugin interface

func NewHTTPPlugin

func NewHTTPPlugin(id string) HTTPPlugin

NewHTTPPlugin creates a new HTTPPlugin mock with an id, so that it may be distinguished from other mocks by DeepEqual.

type InvalidPlugin added in v1.7.11

type InvalidPlugin struct {
	PluginAPIVersion string
	PluginType       string
	PluginID         string
	ErrorOnLookup    bool
}

InvalidPlugin implements the rawPlugin interface

func (InvalidPlugin) Lookup added in v1.7.11

func (r InvalidPlugin) Lookup(symbolName string) (go_plugin.Symbol, error)

Lookup returns a go_plugin.Symbol for a given symbol name string. A go_plugin.Symbol is an empty interface, and can be instantiated with a function or a struct. This method is intended to mimic the Lookup method for a standard Go plugin.

type Plugins

type Plugins struct {
	HTTPPluginsByID map[string]http.Plugin
	TCPPluginsByID  map[string]tcp.Plugin
}

Plugins may appear on first glance to be duplication, but it's not. We can't use the actual implementation sharedobj.Plugin without creating a literal Go circular dependency. It would be circular logically too: to use the thing we're testing to create a mock to test it. Also, note it's purely coincidental that this implementation is the same as the actual implementation in sharedobj. Either one could change. We only care about fulfilling the interface.

func (*Plugins) HTTPPlugins

func (plugins *Plugins) HTTPPlugins() map[string]http.Plugin

HTTPPlugins returns the mock HTTP plugins.

func (*Plugins) TCPPlugins

func (plugins *Plugins) TCPPlugins() map[string]tcp.Plugin

TCPPlugins returns the mock TCP plugins.

type RawPlugin added in v1.5.0

type RawPlugin struct {
	PluginAPIVersion string
	PluginType       string
	PluginID         string
}

RawPlugin implements the rawPlugin interface

func (RawPlugin) Lookup added in v1.5.0

func (r RawPlugin) Lookup(symbolName string) (go_plugin.Symbol, error)

Lookup returns a go_plugin.Symbol for a given symbol name string. A go_plugin.Symbol is an empty interface, and can be instantiated with a function or a struct. This method is intended to mimic the Lookup method for a standard Go plugin.

type TCPPlugin

type TCPPlugin struct {
	tcp.Plugin
	// contains filtered or unexported fields
}

TCPPlugin is a mock struct that implements tcp.Plugin interface

func NewTCPPlugin

func NewTCPPlugin(id string) TCPPlugin

NewTCPPlugin creates a new TCPPlugin mock with an id, so that it may be distinguished from other mocks by DeepEqual.

Jump to

Keyboard shortcuts

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