tgtest

package
v0.48.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2021 License: MIT Imports: 27 Imported by: 8

Documentation

Overview

Package tgtest provides test Telegram server for basic end-to-end tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferedConn

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

func NewBufferedConn

func NewBufferedConn(conn transport.Conn) *BufferedConn

func (*BufferedConn) Close

func (c *BufferedConn) Close() error

func (*BufferedConn) Push

func (c *BufferedConn) Push(b *bin.Buffer)

func (*BufferedConn) Recv

func (c *BufferedConn) Recv(ctx context.Context, b *bin.Buffer) error

func (*BufferedConn) Send

func (c *BufferedConn) Send(ctx context.Context, b *bin.Buffer) error

type Cluster

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

Cluster creates cluster of multiple servers, representing telegram multiple datacenters.

func NewCluster

func NewCluster(codec func() transport.Codec) *Cluster

NewCluster creates new server Cluster.

func (*Cluster) Common

func (c *Cluster) Common() *Dispatcher

Common returns common dispatcher.

func (*Cluster) Config

func (c *Cluster) Config() tg.Config

Config returns config for client.

func (*Cluster) DC

func (c *Cluster) DC(id int, name string) *Server

DC registers new server and returns it.

func (*Cluster) Dispatch

func (c *Cluster) Dispatch(id int, name string) *Dispatcher

Dispatch registers new server and returns its dispatcher.

func (*Cluster) Keys

func (c *Cluster) Keys() []*rsa.PublicKey

Keys returns all servers public keys.

func (*Cluster) Ready

func (c *Cluster) Ready() <-chan struct{}

Ready returns signal channel to await readiness.

func (*Cluster) Up

func (c *Cluster) Up(ctx context.Context) error

Up runs all servers in a cluster.

func (*Cluster) WithLogger

func (c *Cluster) WithLogger(log *zap.Logger) *Cluster

WithLogger sets logger.

type Dispatcher

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

Dispatcher is a plain handler to map requests by ID.

func NewDispatcher

func NewDispatcher() *Dispatcher

NewDispatcher creates new Dispatcher.

func (*Dispatcher) Fallback

func (d *Dispatcher) Fallback(h Handler) *Dispatcher

Fallback sets fallback handler.

func (*Dispatcher) Handle

func (d *Dispatcher) Handle(id uint32, h Handler) *Dispatcher

Handle sets handler for given TypeID.

func (*Dispatcher) HandleFunc

func (d *Dispatcher) HandleFunc(id uint32, h func(server *Server, req *Request) error) *Dispatcher

HandleFunc sets handler for given TypeID.

func (*Dispatcher) OnMessage

func (d *Dispatcher) OnMessage(server *Server, req *Request) error

OnMessage implements Handler

func (*Dispatcher) Result

func (d *Dispatcher) Result(id uint32, msg bin.Encoder) *Dispatcher

Result sets constant result for given TypeID. NB: it uses rpc_result to pack given encoder.

func (*Dispatcher) Vector

func (d *Dispatcher) Vector(id uint32, msgs ...bin.Encoder) *Dispatcher

Vector sets constant Vector result for given TypeID. NB: it uses rpc_result to pack generic vector with given encoders.

type Handler

type Handler interface {
	OnMessage(server *Server, req *Request) error
}

func TestTransport

func TestTransport(t testing.TB, logger *zap.Logger, message string) Handler

type HandlerFunc

type HandlerFunc func(server *Server, req *Request) error

HandlerFunc is functional adapter for Handler.OnMessage method.

func (HandlerFunc) OnMessage

func (h HandlerFunc) OnMessage(server *Server, req *Request) error

type Request

type Request struct {
	DC         int
	Session    Session
	MsgID      int64
	Buf        *bin.Buffer
	RequestCtx context.Context
}

type Server

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

func NewUnstartedServer

func NewUnstartedServer(dcID int, log *zap.Logger, codec func() transport.Codec) *Server

func (*Server) AddSession

func (s *Server) AddSession(key crypto.AuthKey)

func (*Server) Dispatcher

func (s *Server) Dispatcher() *Dispatcher

func (*Server) ForceDisconnect

func (s *Server) ForceDisconnect(k Session)

func (*Server) Key

func (s *Server) Key() *rsa.PublicKey

func (*Server) Send

func (s *Server) Send(ctx context.Context, k Session, t proto.MessageType, encoder bin.Encoder) error

func (*Server) SendAck

func (s *Server) SendAck(ctx context.Context, k Session, ids ...int64) error

func (*Server) SendBool

func (s *Server) SendBool(req *Request, r bool) error

func (*Server) SendConfig

func (s *Server) SendConfig(req *Request) error

func (*Server) SendErr

func (s *Server) SendErr(req *Request, e *tgerr.Error) error

func (*Server) SendEternalSalt

func (s *Server) SendEternalSalt(req *Request) error

func (*Server) SendFutureSalts

func (s *Server) SendFutureSalts(req *Request, salts ...mt.FutureSalt) error

func (*Server) SendPong

func (s *Server) SendPong(req *Request, pingID int64) error

func (*Server) SendResult

func (s *Server) SendResult(req *Request, msg bin.Encoder) error

func (*Server) SendUpdates

func (s *Server) SendUpdates(ctx context.Context, k Session, updates ...tg.UpdateClass) error

func (*Server) SendVector

func (s *Server) SendVector(req *Request, msgs ...bin.Encoder) error

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, l net.Listener) error

type Session

type Session struct {
	SessionID int64
	crypto.AuthKey
}

type Suite

type Suite struct {
	testing.TB
	Ctx context.Context
	Log *zap.Logger
}

func NewSuite

func NewSuite(ctx context.Context, tb testing.TB, log *zap.Logger) Suite

type TB

type TB interface {
	Log(args ...interface{})
	Logf(format string, args ...interface{})
	Fatal(args ...interface{})
}

Directories

Path Synopsis
services
file
Package file contains file service implementation for tgtest server.
Package file contains file service implementation for tgtest server.

Jump to

Keyboard shortcuts

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