Documentation
¶
Index ¶
- type Connection
- type ConnectionMock
- func (mock *ConnectionMock) Addr() string
- func (mock *ConnectionMock) AddrCalls() []struct{}
- func (mock *ConnectionMock) CheckHealth() error
- func (mock *ConnectionMock) CheckHealthCalls() []struct{}
- func (mock *ConnectionMock) ListenAndServe() error
- func (mock *ConnectionMock) ListenAndServeCalls() []struct{}
- func (mock *ConnectionMock) ListenPath(path string, method string, handler http.HandlerFunc) error
- func (mock *ConnectionMock) ListenPathCalls() []struct{ ... }
- func (mock *ConnectionMock) Shutdown(ctx context.Context)
- func (mock *ConnectionMock) ShutdownCalls() []struct{ ... }
- type ConnectionPool
- type ConnectionPoolMock
- type HTTPConnection
- type HTTPConnectionPool
- type HTTPProvider
- func (h *HTTPProvider) Direction() string
- func (h *HTTPProvider) Listen() (<-chan *providers.Message, error)
- func (sp *HTTPProvider) Name() string
- func (h *HTTPProvider) Publish(msg providers.Message) (providers.Message, error)
- func (h *HTTPProvider) Setup() error
- func (h *HTTPProvider) Stop() error
- func (h *HTTPProvider) Type() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection interface { ListenAndServe() error Addr() string ListenPath(path string, method string, handler http.HandlerFunc) error CheckHealth() error Shutdown(ctx context.Context) }
func NewHTTPConnection ¶
func NewHTTPConnection(bindAddr string, port int, logger logger.Logger) Connection
NewHTTPConnection creates a new connection and bind to the given address and port
type ConnectionMock ¶
type ConnectionMock struct { // AddrFunc mocks the Addr method. AddrFunc func() string // CheckHealthFunc mocks the CheckHealth method. CheckHealthFunc func() error // ListenAndServeFunc mocks the ListenAndServe method. ListenAndServeFunc func() error // ListenPathFunc mocks the ListenPath method. ListenPathFunc func(path string, method string, handler http.HandlerFunc) error // ShutdownFunc mocks the Shutdown method. ShutdownFunc func(ctx context.Context) // contains filtered or unexported fields }
ConnectionMock is a mock implementation of Connection.
func TestSomethingThatUsesConnection(t *testing.T) { // make and configure a mocked Connection mockedConnection := &ConnectionMock{ AddrFunc: func() string { panic("TODO: mock out the Addr method") }, CheckHealthFunc: func() error { panic("TODO: mock out the CheckHealth method") }, ListenAndServeFunc: func() error { panic("TODO: mock out the ListenAndServe method") }, ListenPathFunc: func(path string, method string, handler http.HandlerFunc) error { panic("TODO: mock out the ListenPath method") }, ShutdownFunc: func(ctx context.Context) { panic("TODO: mock out the Shutdown method") }, } // TODO: use mockedConnection in code that requires Connection // and then make assertions. }
func (*ConnectionMock) AddrCalls ¶
func (mock *ConnectionMock) AddrCalls() []struct { }
AddrCalls gets all the calls that were made to Addr. Check the length with:
len(mockedConnection.AddrCalls())
func (*ConnectionMock) CheckHealth ¶
func (mock *ConnectionMock) CheckHealth() error
CheckHealth calls CheckHealthFunc.
func (*ConnectionMock) CheckHealthCalls ¶
func (mock *ConnectionMock) CheckHealthCalls() []struct { }
CheckHealthCalls gets all the calls that were made to CheckHealth. Check the length with:
len(mockedConnection.CheckHealthCalls())
func (*ConnectionMock) ListenAndServe ¶
func (mock *ConnectionMock) ListenAndServe() error
ListenAndServe calls ListenAndServeFunc.
func (*ConnectionMock) ListenAndServeCalls ¶
func (mock *ConnectionMock) ListenAndServeCalls() []struct { }
ListenAndServeCalls gets all the calls that were made to ListenAndServe. Check the length with:
len(mockedConnection.ListenAndServeCalls())
func (*ConnectionMock) ListenPath ¶
func (mock *ConnectionMock) ListenPath(path string, method string, handler http.HandlerFunc) error
ListenPath calls ListenPathFunc.
func (*ConnectionMock) ListenPathCalls ¶
func (mock *ConnectionMock) ListenPathCalls() []struct { Path string Method string Handler http.HandlerFunc }
ListenPathCalls gets all the calls that were made to ListenPath. Check the length with:
len(mockedConnection.ListenPathCalls())
func (*ConnectionMock) Shutdown ¶
func (mock *ConnectionMock) Shutdown(ctx context.Context)
Shutdown calls ShutdownFunc.
func (*ConnectionMock) ShutdownCalls ¶
func (mock *ConnectionMock) ShutdownCalls() []struct { Ctx context.Context }
ShutdownCalls gets all the calls that were made to Shutdown. Check the length with:
len(mockedConnection.ShutdownCalls())
type ConnectionPool ¶
type ConnectionPool interface {
GetConnection(bindAddr string, port int, log logger.Logger) (Connection, error)
}
ConnectionPool defines the interface for http ConnectionPools
type ConnectionPoolMock ¶
type ConnectionPoolMock struct { // GetConnectionFunc mocks the GetConnection method. GetConnectionFunc func(bindAddr string, port int, log logger.Logger) (Connection, error) // contains filtered or unexported fields }
ConnectionPoolMock is a mock implementation of ConnectionPool.
func TestSomethingThatUsesConnectionPool(t *testing.T) { // make and configure a mocked ConnectionPool mockedConnectionPool := &ConnectionPoolMock{ GetConnectionFunc: func(bindAddr string, port int, log logger.Logger) (Connection, error) { panic("TODO: mock out the GetConnection method") }, } // TODO: use mockedConnectionPool in code that requires ConnectionPool // and then make assertions. }
func (*ConnectionPoolMock) GetConnection ¶
func (mock *ConnectionPoolMock) GetConnection(bindAddr string, port int, log logger.Logger) (Connection, error)
GetConnection calls GetConnectionFunc.
func (*ConnectionPoolMock) GetConnectionCalls ¶
func (mock *ConnectionPoolMock) GetConnectionCalls() []struct { BindAddr string Port int Log logger.Logger }
GetConnectionCalls gets all the calls that were made to GetConnection. Check the length with:
len(mockedConnectionPool.GetConnectionCalls())
type HTTPConnection ¶
type HTTPConnection struct {
// contains filtered or unexported fields
}
HTTPConnection defines an HTTP Connection and is a wrapper for http.Server
func (*HTTPConnection) Addr ¶
func (h *HTTPConnection) Addr() string
Addr returns the bound address for the connection
func (*HTTPConnection) CheckHealth ¶
func (h *HTTPConnection) CheckHealth() error
CheckHealth checks the health of the connection and returns an error if unhealthy
func (*HTTPConnection) ListenAndServe ¶
func (h *HTTPConnection) ListenAndServe() error
ListenAndServe calls the http.Server ListenAndServe method
func (*HTTPConnection) ListenPath ¶
func (h *HTTPConnection) ListenPath(path string, method string, handler http.HandlerFunc) error
ListenPath registers a new http.HandlerFunc at the given path
func (*HTTPConnection) Shutdown ¶
func (h *HTTPConnection) Shutdown(ctx context.Context)
Shutdown shuts down the connection
type HTTPConnectionPool ¶
type HTTPConnectionPool struct {
// contains filtered or unexported fields
}
HTTPConnectionPool is a concrete implementation of ConnectionPool
func NewHTTPConnectionPool ¶
func NewHTTPConnectionPool() *HTTPConnectionPool
func (*HTTPConnectionPool) GetConnection ¶
func (h *HTTPConnectionPool) GetConnection(bindAddr string, port int, logger logger.Logger) (Connection, error)
GetConnection return a http server from the pool if one exists, or creates a new http server and starts listening. This method needs a complete update to take into account https
type HTTPProvider ¶
type HTTPProvider struct { Protocol string `hcl:"protocol,optional"` // default to http Server string `hcl:"server"` Port int `hcl:"port,optional"` // default to 80 Method string `hcl:"method,optional"` // default to POST Path string `hcl:"path,optional"` // default to / TLS *providers.TLS `hcl:"tls_config,block"` AuthBasic *providers.AuthBasic `hcl:"auth_basic,block"` AuthMTLS *providers.AuthMTLS `hcl:"auth_mtls,block"` // contains filtered or unexported fields }
func NewHTTPProvider ¶
func NewHTTPProvider( name, direction string, cp ConnectionPool, l logger.Logger) *HTTPProvider
func (*HTTPProvider) Direction ¶
func (h *HTTPProvider) Direction() string
func (*HTTPProvider) Name ¶
func (sp *HTTPProvider) Name() string
func (*HTTPProvider) Setup ¶
func (h *HTTPProvider) Setup() error
func (*HTTPProvider) Stop ¶
func (h *HTTPProvider) Stop() error
func (*HTTPProvider) Type ¶
func (h *HTTPProvider) Type() string