teledtest

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package teledtest runs a real teled Telegram server in-process for tests.

New starts a fully-migrated server on a random local port backed by a throwaway PostgreSQL container, shut down automatically on test cleanup. It is the embeddable counterpart to gotd's tgtest: where tgtest makes you stub each RPC by hand, teledtest gives you the actual teled implementation (auth, DMs, media, bots, BotFather) to test a client against.

srv := teledtest.New(t)
err := srv.Run(ctx, nil, func(api *tg.Client) error {
    _, err := api.HelpGetConfig(ctx)
    return err
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	// DC is the datacenter id clients should dial.
	DC int
	// Addr is the server's listen address.
	Addr *net.TCPAddr
	// Keys are the server public keys, for telegram.Options.PublicKeys.
	Keys []telegram.PublicKey
	// contains filtered or unexported fields
}

Server is a running in-process teled server with helpers to connect clients.

func New

func New(tb testing.TB) *Server

New starts a teled server backed by a throwaway PostgreSQL container and returns it. The server, database and connections are torn down on test cleanup. The test is skipped on hosts without container support.

func (*Server) Client

func (s *Server) Client(storage session.Storage) *telegram.Client

Client builds a gotd client wired to this server. A nil storage uses a fresh in-memory session.

func (*Server) Pool

func (s *Server) Pool() *pgxpool.Pool

Pool returns the server's PostgreSQL pool, for tests that assert on stored state directly.

func (*Server) Run

func (s *Server) Run(ctx context.Context, storage session.Storage, fn func(api *tg.Client) error) error

Run connects a client (using storage, or a fresh in-memory session when nil), invokes fn with the raw API, and disconnects.

Jump to

Keyboard shortcuts

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