Version: v0.0.0-...-b355f1c Latest Latest

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

Go to latest
Published: Jun 22, 2021 License: MIT Imports: 18 Imported by: 0



Package fakeirc implements a fake IRC server for testing.



View Source
const ChannelTag = "test-channel"

ChannelTag is a tag key which can be used to direct messages at specific channels.


View Source
var ErrStopped = errors.New("fakeirc: server is stopped")

ErrStopped is returned by Server.Send if the server has been stopped.

View Source
var TLSConfig = &tls.Config{
	InsecureSkipVerify:       true,
	ClientAuth:               tls.RequireAndVerifyClientCert,
	Certificates:             []tls.Certificate{testCert},
	PreferServerCipherSuites: true,
	ClientCAs:                certPool,
	RootCAs:                  certPool,

} // #nosec G402

TLSConfig is a TLS configuration that can be used for testing. The fake IRC server will use this config to authenticate incoming connections when using TLS.


func TagChannel

func TagChannel(m *irc.Message, channel string) *irc.Message

TagChannel tags a message with a channel name. It modifies the message in-place, but returns the message for convenience.


type Helper

type Helper struct {
	SleepDur time.Duration
	// contains filtered or unexported fields

Helper wraps the fake IRC server, providing convenience methods for managing messages.

func NewHelper

func NewHelper(ctx context.Context, t *testing.T, opts ...Option) *Helper

NewHelper creates a new Helper.

func (*Helper) Addr

func (h *Helper) Addr() string

Addr returns the address of the server.

func (*Helper) AssertMessages

func (h *Helper) AssertMessages(gotP *[]*irc.Message, want ...*irc.Message)

AssertMessages asserts that the given messages match the expected messages.

func (*Helper) CloseConn

func (h *Helper) CloseConn(conn irc.Conn)

CloseConn closes an IRC conn, asserting that it was successfully closed.

func (*Helper) CollectFromChannel

func (h *Helper) CollectFromChannel(ch <-chan *irc.Message) *[]*irc.Message

CollectFromChannel collects all messages sent to the provided channel, asynchronously, returning a pointer to a slice which will contain the messages.

func (*Helper) CollectFromConn

func (h *Helper) CollectFromConn(conn irc.Decoder) *[]*irc.Message

CollectFromConn collects all messages sent to a conn, asynchronously, returning a pointer to a slice which will contain the messages.

func (*Helper) CollectSentToServer

func (h *Helper) CollectSentToServer() *[]*irc.Message

CollectSentToServer collects all messages sent to the server, asynchronously, returning a pointer to a slice which will contain the messages.

func (*Helper) Dial

func (h *Helper) Dial() irc.Conn

Dial dials an IRC connection to the server.

func (*Helper) SendAsServer

func (h *Helper) SendAsServer(ctx context.Context, m *irc.Message)

SendAsServer sends a message as the server, asserting that the send was successful.

func (*Helper) SendAsServerErr

func (h *Helper) SendAsServerErr(ctx context.Context, m *irc.Message) error

SendAsServerErr sends a message to the server, and returns the send error.

func (*Helper) SendWithConn

func (h *Helper) SendWithConn(conn irc.Encoder, m *irc.Message)

SendWithConn sends a message via an IRC conn, asserts its success, and sleeps.

func (*Helper) ServerMessages

func (h *Helper) ServerMessages() <-chan *irc.Message

ServerMessages returns the channel of messages sent to the server.

func (*Helper) Sleep

func (h *Helper) Sleep()

Sleep sleeps for a small period of time.

func (*Helper) StopServer

func (h *Helper) StopServer()

StopServer stops the fake IRC server.

func (*Helper) StopServerErr

func (h *Helper) StopServerErr() (err error)

StopServerErr stops the fake IRC server, returning the stop error.

func (*Helper) Wait

func (h *Helper) Wait()

Wait waits for the server to stop.

type Option

type Option func(s *Server)

Option configures the server.

func Pong

func Pong(enable bool) Option

Pong controls whether or not the server responds to PINGS with PONGS.

func RecordPings

func RecordPings(enable bool) Option

RecordPings enables recording of incoming pings the incoming channel.

func TLS

func TLS(config *tls.Config) Option

TLS enables TLS for the server given a TLS config.

type Server

type Server struct {
	// contains filtered or unexported fields

Server is a fake IRC server for use in testing.

func Start

func Start(opts ...Option) (*Server, error)

Start starts a new fake IRC server.

func (*Server) Addr

func (s *Server) Addr() string

Addr gets the address the server is listening on.

func (*Server) Dial

func (s *Server) Dial() (irc.Conn, error)

Dial dials a new IRC connnection to the server, handling TLS if needed.

func (*Server) Incoming

func (s *Server) Incoming() <-chan *irc.Message

Incoming returns the channel of messages being sent to the server from clients.

func (*Server) Send

func (s *Server) Send(ctx context.Context, m *irc.Message) error

Send sends a message as the server to all relevant clients.

func (*Server) Stop

func (s *Server) Stop() error

Stop stops the server and waits for all worker goroutines to exit.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to