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
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

init_test.go 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package network_test
  2. import (
  3. "context"
  4. "net"
  5. "net/http/httptest"
  6. "strings"
  7. "time"
  8. "github.com/mccutchen/go-httpbin/httpbin"
  9. "github.com/stretchr/testify/mock"
  10. "github.com/stretchr/testify/suite"
  11. )
  12. type ConnMock struct {
  13. mock.Mock
  14. }
  15. func (c *ConnMock) Read(b []byte) (int, error) {
  16. args := c.Called(b)
  17. return args.Int(0), args.Error(1)
  18. }
  19. func (c *ConnMock) Write(b []byte) (int, error) {
  20. args := c.Called(b)
  21. return args.Int(0), args.Error(1)
  22. }
  23. func (c *ConnMock) Close() error {
  24. return c.Called().Error(0)
  25. }
  26. func (c *ConnMock) LocalAddr() net.Addr {
  27. return c.Called().Get(0).(net.Addr)
  28. }
  29. func (c *ConnMock) RemoteAddr() net.Addr {
  30. return c.Called().Get(0).(net.Addr)
  31. }
  32. func (c *ConnMock) SetDeadline(t time.Time) error {
  33. return c.Called(t).Error(0)
  34. }
  35. func (c *ConnMock) SetReadDeadline(t time.Time) error {
  36. return c.Called(t).Error(0)
  37. }
  38. func (c *ConnMock) SetWriteDeadline(t time.Time) error {
  39. return c.Called(t).Error(0)
  40. }
  41. type DialerMock struct {
  42. mock.Mock
  43. }
  44. func (d *DialerMock) Dial(network, address string) (net.Conn, error) {
  45. args := d.Called(network, address)
  46. return args.Get(0).(net.Conn), args.Error(1)
  47. }
  48. func (d *DialerMock) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
  49. args := d.Called(ctx, network, address)
  50. return args.Get(0).(net.Conn), args.Error(1)
  51. }
  52. type HTTPServerTestSuite struct {
  53. suite.Suite
  54. httpServer *httptest.Server
  55. }
  56. func (suite *HTTPServerTestSuite) SetupSuite() {
  57. suite.httpServer = httptest.NewServer(httpbin.NewHTTPBin().Handler())
  58. }
  59. func (suite *HTTPServerTestSuite) TearDownSuite() {
  60. suite.httpServer.Close()
  61. }
  62. func (suite *HTTPServerTestSuite) HTTPServerAddress() string {
  63. return strings.TrimPrefix(suite.httpServer.URL, "http://")
  64. }