7a04f298d2
- 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
77 lines
1.6 KiB
Go
77 lines
1.6 KiB
Go
package dcs
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
|
|
)
|
|
|
|
func TestFindDCs(t *testing.T) {
|
|
dcOptions := []tg.DCOption{
|
|
{ID: 1, Ipv6: false},
|
|
{ID: 1, Ipv6: true},
|
|
{ID: 1, Ipv6: false, Static: true},
|
|
|
|
{ID: 2, Ipv6: true, Static: true},
|
|
{ID: 2, Ipv6: true},
|
|
{ID: 2, Ipv6: false},
|
|
}
|
|
for i := range dcOptions {
|
|
dcOptions[i].IPAddress = fmt.Sprintf("DC: %d, Index: %d", dcOptions[i].ID, i)
|
|
}
|
|
|
|
a := require.New(t)
|
|
dc := FindDCs(dcOptions, -2, false)
|
|
a.Empty(dc)
|
|
dc = FindDCs(dcOptions, -2, true)
|
|
a.Empty(dc)
|
|
|
|
// Prefer IPv6.
|
|
dc = FindDCs(dcOptions, 1, true)
|
|
a.True(dc[0].Ipv6)
|
|
|
|
// Prefer static.
|
|
dc = FindDCs(dcOptions, 1, false)
|
|
a.True(dc[0].Static)
|
|
|
|
// Prefer static and IPv6.
|
|
dc = FindDCs(dcOptions, 2, true)
|
|
a.True(dc[0].Static)
|
|
a.True(dc[0].Ipv6)
|
|
}
|
|
|
|
func TestFindPrimaryDCs(t *testing.T) {
|
|
dcOptions := []tg.DCOption{
|
|
{ID: 1, Ipv6: false},
|
|
{ID: 1, Ipv6: true},
|
|
{ID: 1, Ipv6: false, Static: true},
|
|
|
|
{ID: 2, Ipv6: true, Static: true, MediaOnly: true},
|
|
{ID: 2, Ipv6: true, CDN: true},
|
|
{ID: 2, Ipv6: false, CDN: true},
|
|
}
|
|
for i := range dcOptions {
|
|
dcOptions[i].IPAddress = fmt.Sprintf("DC: %d, Index: %d", dcOptions[i].ID, i)
|
|
}
|
|
a := require.New(t)
|
|
dc := FindPrimaryDCs(dcOptions, -2, false)
|
|
a.Empty(dc)
|
|
dc = FindPrimaryDCs(dcOptions, -2, true)
|
|
a.Empty(dc)
|
|
|
|
// Prefer IPv6.
|
|
dc = FindPrimaryDCs(dcOptions, 1, true)
|
|
a.True(dc[0].Ipv6)
|
|
|
|
// Prefer static.
|
|
dc = FindPrimaryDCs(dcOptions, 1, false)
|
|
a.True(dc[0].Static)
|
|
|
|
// Filter CDN/MediaOnly/TCPo.
|
|
dc = FindPrimaryDCs(dcOptions, 2, false)
|
|
a.Empty(dc)
|
|
}
|