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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package mtglib_test
  2. import (
  3. "net"
  4. "testing"
  5. "time"
  6. "github.com/9seconds/mtg/v2/mtglib"
  7. "github.com/stretchr/testify/suite"
  8. )
  9. type EventsTestSuite struct {
  10. suite.Suite
  11. }
  12. func (suite *EventsTestSuite) TestEventStart() {
  13. evt := mtglib.EventStart{
  14. CreatedAt: time.Now(),
  15. ConnID: "CONNID",
  16. RemoteIP: net.ParseIP("10.0.0.10"),
  17. }
  18. suite.Equal("CONNID", evt.StreamID())
  19. suite.WithinDuration(time.Now(), evt.Timestamp(), 10*time.Millisecond)
  20. }
  21. func (suite *EventsTestSuite) TestEventFinish() {
  22. evt := mtglib.EventFinish{
  23. CreatedAt: time.Now(),
  24. ConnID: "CONNID",
  25. }
  26. suite.Equal("CONNID", evt.StreamID())
  27. suite.WithinDuration(time.Now(), evt.Timestamp(), 10*time.Millisecond)
  28. }
  29. func (suite *EventsTestSuite) TestEventConnectedToDC() {
  30. evt := mtglib.EventConnectedToDC{
  31. CreatedAt: time.Now(),
  32. ConnID: "CONNID",
  33. RemoteIP: net.ParseIP("10.0.0.10"),
  34. DC: 3,
  35. }
  36. suite.Equal("CONNID", evt.StreamID())
  37. suite.WithinDuration(time.Now(), evt.Timestamp(), 10*time.Millisecond)
  38. }
  39. func (suite *EventsTestSuite) TestEventTraffic() {
  40. evt := mtglib.EventTraffic{
  41. CreatedAt: time.Now(),
  42. ConnID: "CONNID",
  43. Traffic: 3,
  44. IsRead: true,
  45. }
  46. suite.Equal("CONNID", evt.StreamID())
  47. suite.WithinDuration(time.Now(), evt.Timestamp(), 10*time.Millisecond)
  48. }
  49. func (suite *EventsTestSuite) TestEventDomainFronting() {
  50. evt := mtglib.EventDomainFronting{
  51. CreatedAt: time.Now(),
  52. ConnID: "CONNID",
  53. }
  54. suite.Equal("CONNID", evt.StreamID())
  55. suite.WithinDuration(time.Now(), evt.Timestamp(), 10*time.Millisecond)
  56. }
  57. func (suite *EventsTestSuite) TestEventConcurrencyLimited() {
  58. evt := mtglib.EventConcurrencyLimited{
  59. CreatedAt: time.Now(),
  60. }
  61. suite.Empty(evt.StreamID())
  62. suite.WithinDuration(time.Now(), evt.Timestamp(), 10*time.Millisecond)
  63. }
  64. func (suite *EventsTestSuite) TestEventIPBlocklisted() {
  65. evt := mtglib.EventIPBlocklisted{
  66. CreatedAt: time.Now(),
  67. RemoteIP: net.ParseIP("10.0.0.10"),
  68. }
  69. suite.Empty(evt.StreamID())
  70. suite.WithinDuration(time.Now(), evt.Timestamp(), 10*time.Millisecond)
  71. }
  72. func TestEvents(t *testing.T) {
  73. t.Parallel()
  74. suite.Run(t, &EventsTestSuite{})
  75. }