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.

noop_test.go 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. "finish": mtglib.EventFinish{
  24. CreatedAt: time.Now(),
  25. ConnID: "connID",
  26. },
  27. "concurrency-limited": mtglib.EventConcurrencyLimited{},
  28. "ip-blacklisted": mtglib.EventIPBlocklisted{
  29. RemoteIP: net.ParseIP("10.0.0.10"),
  30. CreatedAt: time.Now(),
  31. },
  32. }
  33. suite.ctx = context.Background()
  34. }
  35. func (suite *NoopTestSuite) TestStream() {
  36. stream := events.NewNoopStream()
  37. for name, v := range suite.testData {
  38. value := v
  39. suite.T().Run(name, func(t *testing.T) {
  40. stream.Send(suite.ctx, value)
  41. })
  42. }
  43. stream.Shutdown()
  44. }
  45. func (suite *NoopTestSuite) TestObserver() {
  46. observer := events.NewNoopObserver()
  47. for name, v := range suite.testData {
  48. value := v
  49. suite.T().Run(name, func(t *testing.T) {
  50. switch typedEvt := value.(type) {
  51. case mtglib.EventStart:
  52. observer.EventStart(typedEvt)
  53. case mtglib.EventFinish:
  54. observer.EventFinish(typedEvt)
  55. case mtglib.EventConcurrencyLimited:
  56. observer.EventConcurrencyLimited(typedEvt)
  57. case mtglib.EventIPBlocklisted:
  58. observer.EventIPBlocklisted(typedEvt)
  59. }
  60. })
  61. }
  62. observer.Shutdown()
  63. }
  64. func TestNoop(t *testing.T) {
  65. t.Parallel()
  66. suite.Run(t, &NoopTestSuite{})
  67. }