mirror of
https://github.com/lukaszraczylo/go-telegram.git
synced 2026-06-11 23:19:31 +00:00
Initial release of go-telegram
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
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user