mirror of
https://github.com/lukaszraczylo/go-telegram.git
synced 2026-06-06 22:49:32 +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
37 lines
872 B
Go
37 lines
872 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"flag"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
var update = flag.Bool("update", false, "update golden files")
|
|
|
|
func TestScrape_Golden_SmallFixture(t *testing.T) {
|
|
htmlBytes, err := os.ReadFile("../../testdata/html/small_fixture.html")
|
|
require.NoError(t, err)
|
|
|
|
api, err := scrape(htmlBytes)
|
|
require.NoError(t, err)
|
|
|
|
var buf bytes.Buffer
|
|
enc := json.NewEncoder(&buf)
|
|
enc.SetIndent("", " ")
|
|
enc.SetEscapeHTML(false)
|
|
require.NoError(t, enc.Encode(api))
|
|
|
|
goldenPath := "../../testdata/golden/api_small_fixture.json"
|
|
if *update {
|
|
require.NoError(t, os.WriteFile(goldenPath, buf.Bytes(), 0o644))
|
|
return
|
|
}
|
|
expected, err := os.ReadFile(goldenPath)
|
|
require.NoError(t, err, "missing golden; run `go test -update ./cmd/scrape/...` to create")
|
|
require.Equal(t, string(expected), buf.String())
|
|
}
|