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
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

view_test.go 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. collected: dcAddrSet{
  30. v4: map[int][]Addr{
  31. 1: {
  32. {Network: "tcp4", Address: "127.1.0.1:443"},
  33. },
  34. },
  35. },
  36. }
  37. }
  38. func (suite *ViewTestSuite) TestGetV4() {
  39. testData := map[int][]Addr{
  40. 111: {
  41. {"tcp4", "127.0.0.1:443"},
  42. },
  43. 203: {
  44. {"tcp4", "127.0.0.2:443"},
  45. {"tcp4", "91.105.192.100:443"},
  46. },
  47. 2: {
  48. {"tcp4", "149.154.167.51:443"},
  49. {"tcp4", "95.161.76.100:443"},
  50. },
  51. 1: {
  52. {"tcp4", "127.1.0.1:443"},
  53. {"tcp4", "149.154.175.50:443"},
  54. },
  55. }
  56. for dc, addresses := range testData {
  57. suite.T().Run(fmt.Sprintf("dc%d", dc), func(t *testing.T) {
  58. assert.ElementsMatch(t, addresses, suite.view.getV4(dc))
  59. })
  60. }
  61. }
  62. func (suite *ViewTestSuite) TestGetV6() {
  63. testData := map[int][]Addr{
  64. 111: {},
  65. 203: {
  66. {"tcp6", "xxx"},
  67. {"tcp6", "[2a0a:f280:0203:000a:5000:0000:0000:0100]:443"},
  68. },
  69. 1: {
  70. {"tcp6", "[2001:b28:f23d:f001::a]:443"},
  71. },
  72. }
  73. for dc, addresses := range testData {
  74. suite.T().Run(fmt.Sprintf("dc%d", dc), func(t *testing.T) {
  75. assert.ElementsMatch(t, addresses, suite.view.getV6(dc))
  76. })
  77. }
  78. }
  79. func TestView(t *testing.T) {
  80. t.Parallel()
  81. suite.Run(t, &ViewTestSuite{})
  82. }