tgbottest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package tgbottest provides a local fake Telegram Bot API server for tests.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("fake Telegram API server is closed")

ErrClosed is returned when a response is queued after the server is closed.

Functions

This section is empty.

Types

type Envelope

type Envelope struct {
	OK          bool   `json:"ok"`
	Result      any    `json:"result,omitempty"`
	ErrorCode   int    `json:"error_code,omitempty"`
	Description string `json:"description,omitempty"`
	Parameters  any    `json:"parameters,omitempty"`
}

Envelope represents a Telegram Bot API response envelope.

type File

type File struct {
	FileName    string
	ContentType string
	Size        int64
}

File describes one file part captured from a multipart request.

type Option

type Option func(*Server)

Option configures a fake Telegram API server.

func WithRequestBodyLimit

func WithRequestBodyLimit(limit int64) Option

WithRequestBodyLimit sets the maximum captured request body size.

type Request

type Request struct {
	Method      string
	HTTPMethod  string
	ContentType string
	JSON        map[string]any
	Fields      map[string]string
	Files       map[string]File
	DecodeError string
}

Request is a captured Telegram Bot API request.

type Server

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

Server is a closeable, concurrency-safe fake Telegram Bot API server.

func NewServer

func NewServer(opts ...Option) *Server

NewServer starts a fake Telegram Bot API server.

func (*Server) Client

func (server *Server) Client() *http.Client

Client returns an HTTP client configured for this server.

func (*Server) Close

func (server *Server) Close()

Close stops the server. It is safe to call Close more than once.

func (*Server) Enqueue

func (server *Server) Enqueue(statusCode int, envelope Envelope) error

Enqueue appends a response to the FIFO response queue.

func (*Server) Requests

func (server *Server) Requests() []Request

Requests returns an isolated snapshot of all captured requests.

func (*Server) URL

func (server *Server) URL() string

URL returns the base URL accepted by tgbot.WithAPIURL.

Jump to

Keyboard shortcuts

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