common

package
v0.0.0-...-f77af5b Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2018 License: BSD-3-Clause Imports: 17 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetGlogFlags

func SetGlogFlags()

SetGlogFlags walk around a glog issue and force it to log to stderr. It need to be called at the beginning of each test.

Types

type BotConfig

type BotConfig struct {
	Id       int
	Config   map[string]string
	Channels []*Channel
}

Configuration for a 'chatbot', which is what clients pay for

type Channel

type Channel struct {
	Id          int
	Name        string
	Pwd         string
	Fingerprint string
}

Configuration for a channel

func (*Channel) Credential

func (cc *Channel) Credential() string

func (*Channel) String

func (cc *Channel) String() string

type ChatBot

type ChatBot interface {
	io.Closer
	Send(channel, msg string)
	Update(config *BotConfig)
	IsRunning() bool
	GetUser() string
}

Interface all bots must implement

type MockIRCServer

type MockIRCServer struct {
	sync.RWMutex
	Port    string
	Message string
	Got     []string
}

func NewMockIRCServer

func NewMockIRCServer(msg, port string) *MockIRCServer

func (*MockIRCServer) GotLength

func (srv *MockIRCServer) GotLength() int

func (*MockIRCServer) Run

func (srv *MockIRCServer) Run(t *testing.T)

type MockQueue

type MockQueue struct {
	sync.RWMutex
	Got         map[string][]string
	ReadChannel chan string
}

Simplistic Queue implementation used by the test suite

func NewMockQueue

func NewMockQueue() *MockQueue

func (*MockQueue) Blpop

func (mq *MockQueue) Blpop(keys []string, timeoutsecs uint) (*string, []byte, error)

func (*MockQueue) Llen

func (mq *MockQueue) Llen(key string) (int, error)

func (*MockQueue) Lpush

func (mq *MockQueue) Lpush(key string, val []byte) error

func (*MockQueue) Ltrim

func (mq *MockQueue) Ltrim(key string, start int, end int) error

func (*MockQueue) Ping

func (mq *MockQueue) Ping() (string, error)

func (*MockQueue) Publish

func (mq *MockQueue) Publish(queue string, message []byte) error

func (*MockQueue) Rpush

func (mq *MockQueue) Rpush(key string, val []byte) error

type MockSocket

type MockSocket struct {
	sync.RWMutex
	Counter  chan bool
	Receiver chan string
}

MockSocket is a dummy implementation of ReadWriteCloser

func (*MockSocket) Close

func (sock *MockSocket) Close() error

func (*MockSocket) Read

func (sock *MockSocket) Read(into []byte) (int, error)

func (*MockSocket) Write

func (sock *MockSocket) Write(data []byte) (int, error)

type MockStorage

type MockStorage struct {
	// contains filtered or unexported fields
}

Simplistic Storage implementation used by the test suite

func (*MockStorage) BotConfig

func (ms *MockStorage) BotConfig() []*BotConfig

func (*MockStorage) SetCount

func (ms *MockStorage) SetCount(channel string, count int) error

type PostgresStorage

type PostgresStorage struct {
	// contains filtered or unexported fields
}

func NewPostgresStorage

func NewPostgresStorage() *PostgresStorage

Connect to the database.

func (*PostgresStorage) BotConfig

func (ps *PostgresStorage) BotConfig() []*BotConfig

func (*PostgresStorage) Close

func (ms *PostgresStorage) Close() error

func (*PostgresStorage) SetCount

func (ms *PostgresStorage) SetCount(channel string, count int) error

type Queue

type Queue interface {

	// Publish 'message' on 'queue' (Redis calls it 'channel')
	Publish(queue string, message []byte) error

	// Append item to the end (right) of a list. Creates the list if needed.
	Rpush(key string, val []byte) error

	// Append item to the beginning (left) of a list. Creates the list if needed.
	Lpush(key string, val []byte) error

	// Blocking Pop from one or more Redis lists
	Blpop(keys []string, timeoutsecs uint) (*string, []byte, error)

	// Check if queue is available. First return arg is "PONG".
	Ping() (string, error)

	// List length
	Llen(string) (int, error)

	// Trim list to given range
	Ltrim(string, int, int) error
}

Message queue

func NewRedisQueue

func NewRedisQueue() Queue

type RedisQueue

type RedisQueue struct {
	// contains filtered or unexported fields
}

* REDIS WRAPPER * Survives Redis restarts, waits for Redis to be available. * Implements common.Queue

func (*RedisQueue) Blpop

func (rq *RedisQueue) Blpop(keys []string, timeoutsecs uint) (*string, []byte, error)

func (*RedisQueue) Llen

func (rq *RedisQueue) Llen(key string) (int, error)

func (*RedisQueue) Lpush

func (rq *RedisQueue) Lpush(key string, val []byte) error

func (*RedisQueue) Ltrim

func (rq *RedisQueue) Ltrim(key string, start int, end int) error

func (*RedisQueue) Ping

func (rq *RedisQueue) Ping() (string, error)

func (*RedisQueue) Publish

func (rq *RedisQueue) Publish(queue string, message []byte) error

func (*RedisQueue) Rpush

func (rq *RedisQueue) Rpush(key string, val []byte) error

type Storage

type Storage interface {
	BotConfig() []*BotConfig
	SetCount(string, int) error
}

Storage. Wraps the database

func NewMockStorage

func NewMockStorage(serverPort string) Storage

Jump to

Keyboard shortcuts

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