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
@@ -0,0 +1,146 @@
package peer
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
)
func createPromise(peer tg.InputPeerClass) Promise {
return func(ctx context.Context) (tg.InputPeerClass, error) {
return peer, nil
}
}
func TestConstraintsCombine(t *testing.T) {
decorate := func(promise Promise, decorators ...PromiseDecorator) Promise {
for _, decorator := range decorators {
promise = decorator(promise)
}
return promise
}
tests := []struct {
name string
decorators []PromiseDecorator
input tg.InputPeerClass
wantErr bool
}{
{
"UserOrChannel",
[]PromiseDecorator{OnlyUser, OnlyChannel},
&tg.InputPeerChannel{
ChannelID: 10,
AccessHash: 10,
},
false,
},
{
"UserOrChannel",
[]PromiseDecorator{OnlyUser, OnlyChannel},
&tg.InputPeerChat{
ChatID: 10,
},
true,
},
{
"ChannelOrUser",
[]PromiseDecorator{OnlyChannel, OnlyUser},
&tg.InputPeerUser{
UserID: 10,
AccessHash: 10,
},
false,
},
{
"ChannelOrUser",
[]PromiseDecorator{OnlyChannel, OnlyUser},
&tg.InputPeerChat{
ChatID: 10,
},
true,
},
}
for _, test := range tests {
tname := "Good"
if test.wantErr {
tname = "Bad"
}
t.Run(test.name, func(t *testing.T) {
t.Run(tname, func(t *testing.T) {
a := require.New(t)
promise := decorate(createPromise(test.input), test.decorators...)
_, err := promise(context.Background())
if test.wantErr {
a.Error(err)
} else {
a.NoError(err)
}
})
})
}
}
func TestConstraints(t *testing.T) {
tests := []struct {
name string
decorator func(Promise) Promise
input tg.InputPeerClass
wantErr bool
}{
{"Channel", OnlyChannel, &tg.InputPeerChannel{
ChannelID: 10,
AccessHash: 10,
}, false},
{"Channel", OnlyChannel, &tg.InputPeerUser{
UserID: 10,
AccessHash: 10,
}, true},
{"User", OnlyUser, &tg.InputPeerUser{
UserID: 10,
AccessHash: 10,
}, false},
{"User", OnlyUser, &tg.InputPeerSelf{}, false},
{"User", OnlyUser, &tg.InputPeerChannel{
ChannelID: 10,
AccessHash: 10,
}, true},
{"UserID", OnlyUserID, &tg.InputPeerUser{
UserID: 10,
AccessHash: 10,
}, false},
{"UserID", OnlyUserID, &tg.InputPeerChannel{
ChannelID: 10,
AccessHash: 10,
}, true},
{"UserID", OnlyUserID, &tg.InputPeerSelf{}, true},
{"Chat", OnlyChat, &tg.InputPeerChat{
ChatID: 10,
}, false},
{"Chat", OnlyChat, &tg.InputPeerChannel{
ChannelID: 10,
AccessHash: 10,
}, true},
}
for _, test := range tests {
tname := "Good"
if test.wantErr {
tname = "Bad"
}
t.Run(test.name, func(t *testing.T) {
t.Run(tname, func(t *testing.T) {
a := require.New(t)
promise := test.decorator(createPromise(test.input))
_, err := promise(context.Background())
if test.wantErr {
a.Error(err)
} else {
a.NoError(err)
}
})
})
}
}