/
tdesktop_test.go
62 lines (57 loc) · 1.13 KB
/
tdesktop_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package session
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/gotd/td/internal/crypto"
"github.com/gotd/td/session/tdesktop"
"github.com/gotd/td/telegram/dcs"
)
func TestTDesktopSession(t *testing.T) {
key := crypto.Key{}
keyID := key.ID()
tests := []struct {
name string
account tdesktop.Account
want *Data
wantErr bool
}{
{"OK", tdesktop.Account{
Authorization: tdesktop.MTPAuthorization{
MainDC: 2,
Keys: map[int]crypto.Key{
2: key,
},
},
}, &Data{
DC: 2,
Config: Config{
ThisDC: 2,
},
Addr: findDCAddr(dcs.Prod().Options, 2),
AuthKey: key[:],
AuthKeyID: keyID[:],
}, false},
{"UnknownDC", tdesktop.Account{
Authorization: tdesktop.MTPAuthorization{
MainDC: 200,
Keys: map[int]crypto.Key{
200: key,
},
},
}, nil, true},
{"NoKey", tdesktop.Account{}, nil, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a := require.New(t)
got, err := TDesktopSession(tt.account)
if tt.wantErr {
a.Nil(got)
a.Error(err)
} else {
a.Equal(tt.want, got)
a.NoError(err)
}
})
}
}