mirror of
https://github.com/lukaszraczylo/go-telegram.git
synced 2026-06-05 22:43:59 +00:00
ac7cae8fa7
A fully-generated, strongly-typed Go client for the Telegram Bot API. * 176 methods + 301 types generated from Bot API v10.0 * 1408 auto-generated tests (8 scenarios per method) * Typed unions throughout — no 'any' in the public surface * Pluggable HTTP transport and JSON codec (default goccy/go-json) * Built-in retry middleware honouring Telegram's retry_after * Generic dispatcher with filters and conversation handlers * Self-verifying codegen pipeline (regen → audit → emit → run tests) * 14 example bots covering common patterns
43 lines
948 B
Go
43 lines
948 B
Go
package client
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestNew_Defaults(t *testing.T) {
|
|
b := New("123:abc")
|
|
require.Equal(t, "123:abc", b.token)
|
|
require.Equal(t, defaultBaseURL, b.base)
|
|
require.NotNil(t, b.http)
|
|
require.NotNil(t, b.codec)
|
|
require.NotNil(t, b.logger)
|
|
}
|
|
|
|
func TestNew_OptionsApplied(t *testing.T) {
|
|
custom := &http.Client{}
|
|
type fakeCodec struct{ DefaultCodec }
|
|
c := fakeCodec{}
|
|
|
|
b := New("t",
|
|
WithHTTPClient(custom),
|
|
WithCodec(c),
|
|
WithBaseURL("https://example.test"),
|
|
WithLogger(NoopLogger{}),
|
|
)
|
|
require.Same(t, custom, b.http)
|
|
require.Equal(t, c, b.codec)
|
|
require.Equal(t, "https://example.test", b.base)
|
|
}
|
|
|
|
func TestResultRoundTrip(t *testing.T) {
|
|
in := Result[int64]{OK: true, Result: 42}
|
|
data, err := DefaultCodec{}.Marshal(in)
|
|
require.NoError(t, err)
|
|
var out Result[int64]
|
|
require.NoError(t, DefaultCodec{}.Unmarshal(data, &out))
|
|
require.Equal(t, in, out)
|
|
}
|