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
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

noop_test.go 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. }
  29. suite.ctx = context.Background()
  30. }
  31. func (suite *NoopTestSuite) TestStream() {
  32. stream := events.NewNoopStream()
  33. for name, v := range suite.testData {
  34. value := v
  35. suite.T().Run(name, func(t *testing.T) {
  36. stream.Send(suite.ctx, value)
  37. })
  38. }
  39. stream.Shutdown()
  40. }
  41. func (suite *NoopTestSuite) TestObserver() {
  42. observer := events.NewNoopObserver()
  43. for name, v := range suite.testData {
  44. value := v
  45. suite.T().Run(name, func(t *testing.T) {
  46. switch typedEvt := value.(type) {
  47. case mtglib.EventStart:
  48. observer.EventStart(typedEvt)
  49. case mtglib.EventFinish:
  50. observer.EventFinish(typedEvt)
  51. case mtglib.EventConcurrencyLimited:
  52. observer.EventConcurrencyLimited(typedEvt)
  53. }
  54. })
  55. }
  56. observer.Shutdown()
  57. }
  58. func TestNoop(t *testing.T) {
  59. t.Parallel()
  60. suite.Run(t, &NoopTestSuite{})
  61. }