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.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. publicConfigs: 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. {Network: "tcp4", Address: "127.0.0.1:443"},
  35. },
  36. 203: {
  37. {Network: "tcp4", Address: "127.0.0.2:443"},
  38. },
  39. 2: {
  40. {Network: "tcp4", Address: "149.154.167.51:443"},
  41. {Network: "tcp4", Address: "95.161.76.100:443"},
  42. },
  43. }
  44. for dc, addresses := range testData {
  45. suite.T().Run(fmt.Sprintf("dc%d", dc), func(t *testing.T) {
  46. assert.ElementsMatch(t, addresses, suite.view.getV4(dc))
  47. })
  48. }
  49. }
  50. func (suite *ViewTestSuite) TestGetV6() {
  51. testData := map[int][]Addr{
  52. 111: {},
  53. 203: {
  54. {Network: "tcp6", Address: "xxx"},
  55. },
  56. 1: {
  57. {Network: "tcp6", Address: "[2001:b28:f23d:f001::a]:443"},
  58. },
  59. }
  60. for dc, addresses := range testData {
  61. suite.T().Run(fmt.Sprintf("dc%d", dc), func(t *testing.T) {
  62. assert.ElementsMatch(t, addresses, suite.view.getV6(dc))
  63. })
  64. }
  65. }
  66. func TestView(t *testing.T) {
  67. t.Parallel()
  68. suite.Run(t, &ViewTestSuite{})
  69. }