suite.go 722 B

123456789101112131415161718192021222324252627282930313233343536
  1. package integration
  2. import (
  3. "context"
  4. "net"
  5. "github.com/imgproxy/imgproxy/v3"
  6. "github.com/stretchr/testify/suite"
  7. )
  8. type Suite struct {
  9. suite.Suite
  10. }
  11. // StartImgproxy starts imgproxy instance for the tests
  12. // Returns instance, instance address and stop function
  13. func (s *Suite) StartImgproxy(c *imgproxy.Config) (net.Addr, context.CancelFunc) {
  14. ctx, cancel := context.WithCancel(s.T().Context())
  15. c.Server.Bind = ":0"
  16. c.Server.LogMemStats = true
  17. i, err := imgproxy.New(ctx, c)
  18. s.Require().NoError(err)
  19. addrCh := make(chan net.Addr)
  20. go func() {
  21. err = i.StartServer(s.T().Context(), addrCh)
  22. if err != nil {
  23. s.T().Errorf("Imgproxy stopped with error: %v", err)
  24. }
  25. }()
  26. return <-addrCh, cancel
  27. }