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
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

noop_test.go 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package events_test
  2. import (
  3. "context"
  4. "net"
  5. "testing"
  6. "time"
  7. "github.com/9seconds/mtg/v2/events"
  8. "github.com/9seconds/mtg/v2/mtglib"
  9. "github.com/stretchr/testify/suite"
  10. )
  11. type NoopTestSuite struct {
  12. suite.Suite
  13. testData map[string]mtglib.Event
  14. ctx context.Context
  15. }
  16. func (suite *NoopTestSuite) SetupSuite() {
  17. suite.testData = map[string]mtglib.Event{
  18. "start": mtglib.EventStart{
  19. CreatedAt: time.Now(),
  20. ConnID: "connID",
  21. RemoteIP: net.ParseIP("127.0.0.1"),
  22. },
  23. "connected-to-dc": mtglib.EventConnectedToDC{
  24. CreatedAt: time.Now(),
  25. ConnID: "connID",
  26. RemoteIP: net.ParseIP("127.1.0.1"),
  27. DC: 2,
  28. },
  29. "domain-fronting": mtglib.EventDomainFronting{
  30. CreatedAt: time.Now(),
  31. ConnID: "connID",
  32. },
  33. "traffic": mtglib.EventTraffic{
  34. CreatedAt: time.Now(),
  35. ConnID: "connID",
  36. Traffic: 1000,
  37. IsRead: true,
  38. },
  39. "finish": mtglib.EventFinish{
  40. CreatedAt: time.Now(),
  41. ConnID: "connID",
  42. },
  43. "concurrency-limited": mtglib.EventConcurrencyLimited{},
  44. "ip-blacklisted": mtglib.EventIPBlocklisted{
  45. RemoteIP: net.ParseIP("10.0.0.10"),
  46. CreatedAt: time.Now(),
  47. },
  48. }
  49. suite.ctx = context.Background()
  50. }
  51. func (suite *NoopTestSuite) TestStream() {
  52. stream := events.NewNoopStream()
  53. for name, v := range suite.testData {
  54. value := v
  55. suite.T().Run(name, func(t *testing.T) {
  56. stream.Send(suite.ctx, value)
  57. })
  58. }
  59. stream.Shutdown()
  60. }
  61. func (suite *NoopTestSuite) TestObserver() {
  62. observer := events.NewNoopObserver()
  63. for name, v := range suite.testData {
  64. value := v
  65. suite.T().Run(name, func(t *testing.T) {
  66. switch typedEvt := value.(type) {
  67. case mtglib.EventStart:
  68. observer.EventStart(typedEvt)
  69. case mtglib.EventConnectedToDC:
  70. observer.EventConnectedToDC(typedEvt)
  71. case mtglib.EventDomainFronting:
  72. observer.EventDomainFronting(typedEvt)
  73. case mtglib.EventFinish:
  74. observer.EventFinish(typedEvt)
  75. case mtglib.EventConcurrencyLimited:
  76. observer.EventConcurrencyLimited(typedEvt)
  77. case mtglib.EventIPBlocklisted:
  78. observer.EventIPBlocklisted(typedEvt)
  79. }
  80. })
  81. }
  82. observer.Shutdown()
  83. }
  84. func TestNoop(t *testing.T) {
  85. t.Parallel()
  86. suite.Run(t, &NoopTestSuite{})
  87. }