Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

view_test.go 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package dc
  2. import (
  3. "fmt"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/stretchr/testify/suite"
  7. )
  8. type ViewTestSuite struct {
  9. suite.Suite
  10. view dcView
  11. }
  12. func (suite *ViewTestSuite) SetupSuite() {
  13. suite.view = dcView{
  14. overrides: dcAddrSet{
  15. v4: map[int][]Addr{
  16. 111: {
  17. {Network: "tcp4", Address: "127.0.0.1:443"},
  18. },
  19. 203: {
  20. {Network: "tcp4", Address: "127.0.0.2:443"},
  21. },
  22. },
  23. v6: map[int][]Addr{
  24. 203: {
  25. {Network: "tcp6", Address: "xxx"},
  26. },
  27. },
  28. },
  29. }
  30. }
  31. func (suite *ViewTestSuite) TestGetV4() {
  32. testData := map[int][]Addr{
  33. 111: {
  34. {"tcp4", "127.0.0.1:443"},
  35. },
  36. 203: {
  37. {"tcp4", "127.0.0.2:443"},
  38. {"tcp4", "91.105.192.100:443"},
  39. },
  40. 2: {
  41. {"tcp4", "149.154.167.51:443"},
  42. {"tcp4", "95.161.76.100:443"},
  43. },
  44. }
  45. for dc, addresses := range testData {
  46. suite.T().Run(fmt.Sprintf("dc%d", dc), func(t *testing.T) {
  47. assert.ElementsMatch(t, addresses, suite.view.getV4(dc))
  48. })
  49. }
  50. }
  51. func (suite *ViewTestSuite) TestGetV6() {
  52. testData := map[int][]Addr{
  53. 111: {},
  54. 203: {
  55. {"tcp6", "xxx"},
  56. {"tcp6", "[2a0a:f280:0203:000a:5000:0000:0000:0100]:443"},
  57. },
  58. 1: {
  59. {"tcp6", "[2001:b28:f23d:f001::a]:443"},
  60. },
  61. }
  62. for dc, addresses := range testData {
  63. suite.T().Run(fmt.Sprintf("dc%d", dc), func(t *testing.T) {
  64. assert.ElementsMatch(t, addresses, suite.view.getV6(dc))
  65. })
  66. }
  67. }
  68. func TestView(t *testing.T) {
  69. t.Parallel()
  70. suite.Run(t, &ViewTestSuite{})
  71. }