move gotd fork into repo. (#111)

- update to latest telegram layer
- remove some references to fields in tg.Entities that don't exist in
the schema
- originally added here:
https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e
  - referenced here
-
https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3
-
https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
This commit is contained in:
Adam Van Ymeren
2025-06-27 20:03:37 -07:00
committed by GitHub
parent 0952df0244
commit 7a04f298d2
19264 changed files with 1539697 additions and 84 deletions
+23
View File
@@ -0,0 +1,23 @@
package testutil
import "testing"
const defaultAllocRuns = 10
// MaxAlloc checks that f does not allocate more than n.
func MaxAlloc(t *testing.T, n int, f func()) {
t.Helper()
if Race {
t.Skip("Skipped (race detector conflicts with allocation tests)")
}
avg := testing.AllocsPerRun(defaultAllocRuns, f)
if avg > float64(n) {
t.Errorf("Allocated %f bytes per run, expected less than %d", avg, n)
}
}
// ZeroAlloc checks that f does not allocate.
func ZeroAlloc(t *testing.T, f func()) {
t.Helper()
MaxAlloc(t, 0, f)
}
+15
View File
@@ -0,0 +1,15 @@
package testutil
import (
"time"
)
// Date return date for testing.
func Date() time.Time {
// Using VK birthday as test date.
return time.Date(2006, 10, 10,
13, 42, 15,
34123,
time.UTC,
)
}
+2
View File
@@ -0,0 +1,2 @@
// Package testutil wraps helpers for testing.
package testutil
+12
View File
@@ -0,0 +1,12 @@
package testutil
import (
"testing"
)
// SetEnv sets environment variable and sets delete callback
// to unset variable after test.
func SetEnv(t *testing.T, k, v string) {
// Set envs.
t.Setenv(k, v)
}
+12
View File
@@ -0,0 +1,12 @@
package testutil
import (
"github.com/go-faster/errors"
)
var errTestError = errors.New("test error")
// TestError returns error for testing error pass.
func TestError() error {
return errTestError
}
+38
View File
@@ -0,0 +1,38 @@
package testutil
import (
"os"
"runtime"
"strconv"
"strings"
"testing"
)
// SkipExternal skips current test if GOTD_TEST_EXTERNAL is not 1.
//
// Caller should be high-level test function with TestExternalE2E prefix,
// like TestExternalE2EConnect.
//
// Run all tests with following command in module root:
//
// GOTD_TEST_EXTERNAL=1 go test -v -run ^TestExternalE2E ./...
func SkipExternal(tb testing.TB) {
const env = "GOTD_TEST_EXTERNAL"
tb.Helper()
{
// Checking caller prefix.
const expectedPrefix = "TestExternalE2E"
pc, _, _, _ := runtime.Caller(1)
details := runtime.FuncForPC(pc)
name := details.Name()[strings.LastIndex(details.Name(), ".")+1:]
if !strings.HasPrefix(name, expectedPrefix) {
tb.Fatalf("Test function %s should have prefix %s.", name, expectedPrefix)
}
}
if ok, _ := strconv.ParseBool(os.Getenv(env)); !ok {
tb.Skipf("Skipped. Set %s=1 to enable external e2e test.", env)
}
}
+34
View File
@@ -0,0 +1,34 @@
package testutil
import (
"crypto/rsa"
"crypto/x509"
"encoding/base64"
)
// RSAPrivateKey returns pre-generated test RSA private key.
func RSAPrivateKey() *rsa.PrivateKey {
rawKey, err := base64.StdEncoding.DecodeString("MIIEowIBAAKCAQEAvPXkA3h/InI+o9Q1B01ysoRZGDlazlSwOMX5Q8KgLsOSKyUDYCI" +
"07AWV60da4eAUgbI6BNE6B/vw2jH8gInEKb+0DyOKTPGv2t0mPq5a+I+C8xbXIVLwTHBm0mWaiiDQbcaQLBSzxhZ8BTa8VyMK8RO/XIGPoNSnJhf" +
"LcKg5pmrIenzKDnlPDE2vEPWe8E84cknnmZQVRbbyae/Vqnu+XbadKXuhOro2r1Yz4n49jLHZfUVuyoSbLbYBoTBkdiadO5wCAU9edKl9Bt4LtBu" +
"SC24MXK4WGWCuX5P7ujENLAMl8Evn5qabD5mMOlFWJUtlBp2iZQhOzJdHtsshMq25pwIDAQABAoIBAEV+zbA1FdTuXXlVZ3dbFY7wO/A7z9jIrtM" +
"ChK1WHCF2zgBOKZKmof4YA843PQaLqh8VFF+HL6eWEju9XJdNk7ajCa7zrD6mOL3uzc0JxO1bopaS1OYtobELOdWxhoe8j8t/1rBPoNp+lHg6bER" +
"D4BdP4vY7tD47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Dos+vbpmDHvuYHmQ56ljX+5mD3T+ZjuYk7TM")
if err != nil {
panic(err)
}
k, err := x509.ParsePKCS1PrivateKey(rawKey)
if err != nil {
panic(err)
}
return k
}
+26
View File
@@ -0,0 +1,26 @@
package testutil
import (
"fmt"
"testing"
)
// Payloads returns a payload sizes list.
// Helpful for benchmarks.
func Payloads() []int {
return []int{
16,
128,
1024,
8192,
64 * 1024,
512 * 1024,
}
}
// RunPayloads runs given benchmark runner for every payload.
func RunPayloads(b *testing.B, runner func(size int) func(b *testing.B)) {
for _, size := range Payloads() {
b.Run(fmt.Sprintf("%db", size), runner(size))
}
}
+7
View File
@@ -0,0 +1,7 @@
//go:build !race
// +build !race
package testutil
// Race reports if the race detector is enabled.
const Race = false
+7
View File
@@ -0,0 +1,7 @@
//go:build race
// +build race
package testutil
// Race reports if the race detector is enabled.
const Race = true
+31
View File
@@ -0,0 +1,31 @@
package testutil
import (
"encoding/binary"
"math/rand"
)
// ZeroRand is zero random source.
type ZeroRand struct{}
// Read implements io.Reader.
func (ZeroRand) Read(p []byte) (n int, err error) { return len(p), nil }
func randSeed(data []byte) int64 {
if len(data) == 0 {
return 0
}
seedBuf := make([]byte, 64/8)
copy(seedBuf, data)
return int64(binary.BigEndian.Uint64(seedBuf))
}
// Rand returns a new rand.Rand with source deterministically initialized
// from seed byte slice.
//
// Zero length seed (or nil) is valid input.
func Rand(seed []byte) *rand.Rand {
return rand.New(rand.NewSource(randSeed(seed))) // #nosec
}
+16
View File
@@ -0,0 +1,16 @@
package testutil
import "io"
// ErrWriter returns an io.Writer that returns 0, err from all Write calls.
func ErrWriter(err error) io.Writer {
return &errWriter{err: err}
}
type errWriter struct {
err error
}
func (r *errWriter) Write(p []byte) (int, error) {
return 0, r.err
}