mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-10 20:22:31 +02:00
IMG-49: Get rid of global watermark image and fetcher (#1515)
* Get rid of global watermark image * imagedata.Factory, removed global Fetcher
This commit is contained in:
@@ -12,14 +12,17 @@ import (
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/imgproxy/imgproxy/v3/config"
|
||||
"github.com/imgproxy/imgproxy/v3/fetcher"
|
||||
"github.com/imgproxy/imgproxy/v3/ierrors"
|
||||
"github.com/imgproxy/imgproxy/v3/imagedata"
|
||||
"github.com/imgproxy/imgproxy/v3/options"
|
||||
"github.com/imgproxy/imgproxy/v3/transport"
|
||||
"github.com/imgproxy/imgproxy/v3/vips"
|
||||
)
|
||||
|
||||
type ProcessingTestSuite struct {
|
||||
suite.Suite
|
||||
idf *imagedata.Factory
|
||||
}
|
||||
|
||||
func (s *ProcessingTestSuite) SetupSuite() {
|
||||
@@ -30,10 +33,19 @@ func (s *ProcessingTestSuite) SetupSuite() {
|
||||
config.MaxAnimationFrames = 100
|
||||
config.MaxAnimationFrameResolution = 10 * 1024 * 1024
|
||||
|
||||
s.Require().NoError(imagedata.Init())
|
||||
s.Require().NoError(vips.Init())
|
||||
|
||||
logrus.SetOutput(io.Discard)
|
||||
|
||||
trc := transport.NewDefaultConfig()
|
||||
tr, err := transport.New(trc)
|
||||
s.Require().NoError(err)
|
||||
|
||||
fc := fetcher.NewDefaultConfig()
|
||||
f, err := fetcher.New(tr, fc)
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.idf = imagedata.NewFactory(f)
|
||||
}
|
||||
|
||||
func (s *ProcessingTestSuite) openFile(name string) imagedata.ImageData {
|
||||
@@ -41,7 +53,7 @@ func (s *ProcessingTestSuite) openFile(name string) imagedata.ImageData {
|
||||
s.Require().NoError(err)
|
||||
path := filepath.Join(wd, "..", "testdata", name)
|
||||
|
||||
imagedata, err := imagedata.NewFromPath(path)
|
||||
imagedata, err := s.idf.NewFromPath(path)
|
||||
s.Require().NoError(err)
|
||||
|
||||
return imagedata
|
||||
@@ -82,7 +94,7 @@ func (s *ProcessingTestSuite) TestResizeToFit() {
|
||||
po.Width = tc.width
|
||||
po.Height = tc.height
|
||||
|
||||
result, err := ProcessImage(context.Background(), imgdata, po)
|
||||
result, err := ProcessImage(context.Background(), imgdata, po, nil, s.idf)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(result)
|
||||
|
||||
@@ -121,7 +133,7 @@ func (s *ProcessingTestSuite) TestResizeToFitEnlarge() {
|
||||
po.Width = tc.width
|
||||
po.Height = tc.height
|
||||
|
||||
result, err := ProcessImage(context.Background(), imgdata, po)
|
||||
result, err := ProcessImage(context.Background(), imgdata, po, nil, s.idf)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(result)
|
||||
|
||||
@@ -165,7 +177,7 @@ func (s *ProcessingTestSuite) TestResizeToFitExtend() {
|
||||
po.Width = tc.width
|
||||
po.Height = tc.height
|
||||
|
||||
result, err := ProcessImage(context.Background(), imgdata, po)
|
||||
result, err := ProcessImage(context.Background(), imgdata, po, nil, s.idf)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(result)
|
||||
|
||||
@@ -209,7 +221,7 @@ func (s *ProcessingTestSuite) TestResizeToFitExtendAR() {
|
||||
po.Width = tc.width
|
||||
po.Height = tc.height
|
||||
|
||||
result, err := ProcessImage(context.Background(), imgdata, po)
|
||||
result, err := ProcessImage(context.Background(), imgdata, po, nil, s.idf)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(result)
|
||||
|
||||
@@ -247,7 +259,7 @@ func (s *ProcessingTestSuite) TestResizeToFill() {
|
||||
po.Width = tc.width
|
||||
po.Height = tc.height
|
||||
|
||||
result, err := ProcessImage(context.Background(), imgdata, po)
|
||||
result, err := ProcessImage(context.Background(), imgdata, po, nil, s.idf)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(result)
|
||||
|
||||
@@ -286,7 +298,7 @@ func (s *ProcessingTestSuite) TestResizeToFillEnlarge() {
|
||||
po.Width = tc.width
|
||||
po.Height = tc.height
|
||||
|
||||
result, err := ProcessImage(context.Background(), imgdata, po)
|
||||
result, err := ProcessImage(context.Background(), imgdata, po, nil, s.idf)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(result)
|
||||
|
||||
@@ -332,7 +344,7 @@ func (s *ProcessingTestSuite) TestResizeToFillExtend() {
|
||||
po.Width = tc.width
|
||||
po.Height = tc.height
|
||||
|
||||
result, err := ProcessImage(context.Background(), imgdata, po)
|
||||
result, err := ProcessImage(context.Background(), imgdata, po, nil, s.idf)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(result)
|
||||
|
||||
@@ -378,7 +390,7 @@ func (s *ProcessingTestSuite) TestResizeToFillExtendAR() {
|
||||
po.Width = tc.width
|
||||
po.Height = tc.height
|
||||
|
||||
result, err := ProcessImage(context.Background(), imgdata, po)
|
||||
result, err := ProcessImage(context.Background(), imgdata, po, nil, s.idf)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(result)
|
||||
|
||||
@@ -416,7 +428,7 @@ func (s *ProcessingTestSuite) TestResizeToFillDown() {
|
||||
po.Width = tc.width
|
||||
po.Height = tc.height
|
||||
|
||||
result, err := ProcessImage(context.Background(), imgdata, po)
|
||||
result, err := ProcessImage(context.Background(), imgdata, po, nil, s.idf)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(result)
|
||||
|
||||
@@ -455,7 +467,7 @@ func (s *ProcessingTestSuite) TestResizeToFillDownEnlarge() {
|
||||
po.Width = tc.width
|
||||
po.Height = tc.height
|
||||
|
||||
result, err := ProcessImage(context.Background(), imgdata, po)
|
||||
result, err := ProcessImage(context.Background(), imgdata, po, nil, s.idf)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(result)
|
||||
|
||||
@@ -501,7 +513,7 @@ func (s *ProcessingTestSuite) TestResizeToFillDownExtend() {
|
||||
po.Width = tc.width
|
||||
po.Height = tc.height
|
||||
|
||||
result, err := ProcessImage(context.Background(), imgdata, po)
|
||||
result, err := ProcessImage(context.Background(), imgdata, po, nil, s.idf)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(result)
|
||||
|
||||
@@ -545,7 +557,7 @@ func (s *ProcessingTestSuite) TestResizeToFillDownExtendAR() {
|
||||
po.Width = tc.width
|
||||
po.Height = tc.height
|
||||
|
||||
result, err := ProcessImage(context.Background(), imgdata, po)
|
||||
result, err := ProcessImage(context.Background(), imgdata, po, nil, s.idf)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(result)
|
||||
|
||||
@@ -974,7 +986,7 @@ func (s *ProcessingTestSuite) TestResultSizeLimit() {
|
||||
po.Rotate = tc.rotate
|
||||
po.Padding = tc.padding
|
||||
|
||||
result, err := ProcessImage(context.Background(), imgdata, po)
|
||||
result, err := ProcessImage(context.Background(), imgdata, po, nil, s.idf)
|
||||
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(result)
|
||||
@@ -989,7 +1001,7 @@ func (s *ProcessingTestSuite) TestImageResolutionTooLarge() {
|
||||
po.SecurityOptions.MaxSrcResolution = 1
|
||||
|
||||
imgdata := s.openFile("test2.jpg")
|
||||
_, err := ProcessImage(context.Background(), imgdata, po)
|
||||
_, err := ProcessImage(context.Background(), imgdata, po, nil, s.idf)
|
||||
|
||||
s.Require().Error(err)
|
||||
s.Require().Equal(422, ierrors.Wrap(err, 0).StatusCode())
|
||||
|
Reference in New Issue
Block a user