Documentation
¶
Index ¶
- Constants
- Variables
- func FromTextMessage(m *Message, v interface{}) error
- func NewChatSetup(recv1, recv2 ReceiveFun) ([]*FakeConnection, []*Agent, func())
- type Agent
- type AgentFuncsCreator
- type Chat
- type ChatData
- type Connection
- type FakeChannel
- type FakeConnection
- type Message
- type Messenger
- type ReceiveFun
- type SendFun
Constants ¶
const ( // TextMessage denotes a text data message. TextMessage = 1 // BinaryMessage denotes a binary data message. BinaryMessage = 2 // CloseMessage denotes a close control message. CloseMessage = 8 // PingMessage denotes a ping control message. PingMessage = 9 // PongMessage denotes a pong control message. PongMessage = 10 )
Message types, same as websocket.
Variables ¶
var WorkerPool *worker.Pool
WorkerPool is a worker pool, which if initialised, is used instead of launching new goroutines every time when needed.
Functions ¶
func FromTextMessage ¶
FromTextMessage creates an instance of a JSON-annotated type from a Message of type Text.
func NewChatSetup ¶
func NewChatSetup(recv1, recv2 ReceiveFun) ([]*FakeConnection, []*Agent, func())
NewChatSetup creates the whole setup required for a chat between two talking agents.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent is the class for talking agents. A talking agent both accepts and sends messages.
func NewAgent ¶
func NewAgent(c Connection, r ReceiveFun) *Agent
NewAgent creates a new talking agent. The agent will take care of closing the connection when stopped.
func (*Agent) IsRunning ¶
IsRunning returns true if the agent is still running. An stopped agent is not usable anymore.
type AgentFuncsCreator ¶
type AgentFuncsCreator func(t *testing.T) (ReceiveFun, func(), error)
AgentFuncsCreator creates channel listeners for the service side, for testing.
type Chat ¶
type Chat struct {
// contains filtered or unexported fields
}
Chat is a helper struct managing the communication between two talking agents.
type ChatData ¶
type ChatData struct { Conns []*FakeConnection Agents []*Agent ClientInbox *Message // contains filtered or unexported fields }
ChatData holds information about a chat.
func (*ChatData) ExpectClientMessage ¶
func (c *ChatData) ExpectClientMessage()
ExpectClientMessage sets the expectation for receiving a message on client-side.
func (*ChatData) ExpectServiceMessage ¶
func (c *ChatData) ExpectServiceMessage()
ExpectServiceMessage sets the expectation for receiving a message on servce-side.
func (*ChatData) WaitForClientMessages ¶
func (c *ChatData) WaitForClientMessages()
WaitForClientMessages waits for all the message expectations on client-side to be fulfilled.
func (*ChatData) WaitForServiceMessages ¶
func (c *ChatData) WaitForServiceMessages()
WaitForServiceMessages waits for all the message expectations on service-side to be fulfilled.
type Connection ¶
Connection is the interface for an endpoint.
type FakeChannel ¶
type FakeChannel struct {
// contains filtered or unexported fields
}
FakeChannel represents a theoretical communication channel. between two parties. It is useful for mocking real communication channels. In a FakeChannel, there are two Message channels. One party reads from the first channel and writes to the second channel. The other party does the opposite.
func NewFakeChannel ¶
func NewFakeChannel() *FakeChannel
NewFakeChannel creates a new fake channel instance.
type FakeConnection ¶
type FakeConnection struct {
// contains filtered or unexported fields
}
FakeConnection represents a theoretical communication endpoint. It is useful for mocking real communication endpoints.
func NewFakeConnection ¶
func NewFakeConnection(channel *FakeChannel, index int) *FakeConnection
NewFakeConnection returns a new fake connection instance.
func (*FakeConnection) Close ¶
func (c *FakeConnection) Close()
Close closes the fake connection by writing a close message on the fake channel.
func (*FakeConnection) ExpectMessages ¶
func (c *FakeConnection) ExpectMessages(count int)
ExpectMessages expectats for 'count' messages.
func (*FakeConnection) Subscribe ¶
func (c *FakeConnection) Subscribe(cb func(*Message, bool))
Subscribe subscribes the given callback to the connection's message arrival event loop.
func (*FakeConnection) WaitForMessages ¶
func (c *FakeConnection) WaitForMessages()
WaitForMessages waits for the expected messages.
func (*FakeConnection) Write ¶
func (c *FakeConnection) Write(m *Message) error
Write writes a message on the fake channel.
type Message ¶
Message is the unit of transmission.
func SimpleMessage ¶
SimpleMessage creates a simple text message.
func ToTextMessage ¶
ToTextMessage converts a JSON-annotated struct to a Message of type Text. It returns a nil value if the marshaling does not succeed.
type Messenger ¶
type Messenger struct {
Chats []*ChatData
}
Messenger is an abstraction for multiple client - single service communications, for the purpose of testing the service.
func NewMessenger ¶
func NewMessenger(t *testing.T, n int, agentFuncsCreator AgentFuncsCreator, clientName, serviceName string) *Messenger
NewMessenger spawns n given communication channels between a service and n clients.
type ReceiveFun ¶
ReceiveFun is the signature of the function that handles a received message.