1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2024-11-24 08:12:38 +02:00

Use require instead of assert in tests

This commit is contained in:
DarthSim 2022-07-18 19:48:50 +06:00
parent 067481dc6b
commit d610afb48b
6 changed files with 184 additions and 186 deletions

View File

@ -10,7 +10,7 @@ import (
"github.com/imgproxy/imgproxy/v3/imagedata"
"github.com/imgproxy/imgproxy/v3/options"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
@ -52,31 +52,31 @@ func (s *EtagTestSuite) TestGenerateActualReq() {
s.h.SetActualProcessingOptions(po)
s.h.SetActualImageData(&imgWithETag)
assert.Equal(s.T(), etagReq, s.h.GenerateActualETag())
require.Equal(s.T(), etagReq, s.h.GenerateActualETag())
}
func (s *EtagTestSuite) TestGenerateActualData() {
s.h.SetActualProcessingOptions(po)
s.h.SetActualImageData(&imgWithoutETag)
assert.Equal(s.T(), etagData, s.h.GenerateActualETag())
require.Equal(s.T(), etagData, s.h.GenerateActualETag())
}
func (s *EtagTestSuite) TestGenerateExpectedReq() {
s.h.ParseExpectedETag(etagReq)
assert.Equal(s.T(), etagReq, s.h.GenerateExpectedETag())
require.Equal(s.T(), etagReq, s.h.GenerateExpectedETag())
}
func (s *EtagTestSuite) TestGenerateExpectedData() {
s.h.ParseExpectedETag(etagData)
assert.Equal(s.T(), etagData, s.h.GenerateExpectedETag())
require.Equal(s.T(), etagData, s.h.GenerateExpectedETag())
}
func (s *EtagTestSuite) TestProcessingOptionsCheckSuccess() {
s.h.ParseExpectedETag(etagReq)
assert.True(s.T(), s.h.SetActualProcessingOptions(po))
assert.True(s.T(), s.h.ProcessingOptionsMatch())
require.True(s.T(), s.h.SetActualProcessingOptions(po))
require.True(s.T(), s.h.ProcessingOptionsMatch())
}
func (s *EtagTestSuite) TestProcessingOptionsCheckFailure() {
@ -85,25 +85,25 @@ func (s *EtagTestSuite) TestProcessingOptionsCheckFailure() {
s.h.ParseExpectedETag(wrongEtag)
assert.False(s.T(), s.h.SetActualProcessingOptions(po))
assert.False(s.T(), s.h.ProcessingOptionsMatch())
require.False(s.T(), s.h.SetActualProcessingOptions(po))
require.False(s.T(), s.h.ProcessingOptionsMatch())
}
func (s *EtagTestSuite) TestImageETagExpectedPresent() {
s.h.ParseExpectedETag(etagReq)
assert.Equal(s.T(), imgWithETag.Headers["ETag"], s.h.ImageEtagExpected())
require.Equal(s.T(), imgWithETag.Headers["ETag"], s.h.ImageEtagExpected())
}
func (s *EtagTestSuite) TestImageETagExpectedBlank() {
s.h.ParseExpectedETag(etagData)
assert.Empty(s.T(), s.h.ImageEtagExpected())
require.Empty(s.T(), s.h.ImageEtagExpected())
}
func (s *EtagTestSuite) TestImageDataCheckDataToDataSuccess() {
s.h.ParseExpectedETag(etagData)
assert.True(s.T(), s.h.SetActualImageData(&imgWithoutETag))
require.True(s.T(), s.h.SetActualImageData(&imgWithoutETag))
}
func (s *EtagTestSuite) TestImageDataCheckDataToDataFailure() {
@ -111,12 +111,12 @@ func (s *EtagTestSuite) TestImageDataCheckDataToDataFailure() {
wrongEtag := etagData[:i] + `/Dwrongimghash"`
s.h.ParseExpectedETag(wrongEtag)
assert.False(s.T(), s.h.SetActualImageData(&imgWithoutETag))
require.False(s.T(), s.h.SetActualImageData(&imgWithoutETag))
}
func (s *EtagTestSuite) TestImageDataCheckDataToReqSuccess() {
s.h.ParseExpectedETag(etagData)
assert.True(s.T(), s.h.SetActualImageData(&imgWithETag))
require.True(s.T(), s.h.SetActualImageData(&imgWithETag))
}
func (s *EtagTestSuite) TestImageDataCheckDataToReqFailure() {
@ -124,19 +124,19 @@ func (s *EtagTestSuite) TestImageDataCheckDataToReqFailure() {
wrongEtag := etagData[:i] + `/Dwrongimghash"`
s.h.ParseExpectedETag(wrongEtag)
assert.False(s.T(), s.h.SetActualImageData(&imgWithETag))
require.False(s.T(), s.h.SetActualImageData(&imgWithETag))
}
func (s *EtagTestSuite) TestImageDataCheckReqToDataFailure() {
s.h.ParseExpectedETag(etagReq)
assert.False(s.T(), s.h.SetActualImageData(&imgWithoutETag))
require.False(s.T(), s.h.SetActualImageData(&imgWithoutETag))
}
func (s *EtagTestSuite) TestETagBusterFailure() {
config.ETagBuster = "busted"
s.h.ParseExpectedETag(etagReq)
assert.False(s.T(), s.h.SetActualImageData(&imgWithoutETag))
require.False(s.T(), s.h.SetActualImageData(&imgWithoutETag))
}
func TestEtag(t *testing.T) {

View File

@ -6,7 +6,6 @@ import (
"testing"
"github.com/imgproxy/imgproxy/v3/imagetype"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
@ -42,8 +41,8 @@ func (s *JpegTestSuite) TestDecodeJpegMeta() {
defer f.Close()
metadata, err := DecodeJpegMeta(f)
assert.Nil(s.T(), err)
assert.Equal(s.T(), expectedMeta, metadata)
require.Nil(s.T(), err)
require.Equal(s.T(), expectedMeta, metadata)
}()
}
}

View File

@ -5,7 +5,6 @@ import (
"testing"
"github.com/imgproxy/imgproxy/v3/config"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
@ -23,7 +22,7 @@ func (s *PresetsTestSuite) TestParsePreset() {
require.Nil(s.T(), err)
assert.Equal(s.T(), urlOptions{
require.Equal(s.T(), urlOptions{
urlOption{Name: "resize", Args: []string{"fit", "100", "200"}},
urlOption{Name: "sharpen", Args: []string{"2"}},
}, presets["test"])
@ -33,46 +32,46 @@ func (s *PresetsTestSuite) TestParsePresetInvalidString() {
presetStr := "resize:fit:100:200/sharpen:2"
err := parsePreset(presetStr)
assert.Equal(s.T(), fmt.Errorf("Invalid preset string: %s", presetStr), err)
assert.Empty(s.T(), presets)
require.Equal(s.T(), fmt.Errorf("Invalid preset string: %s", presetStr), err)
require.Empty(s.T(), presets)
}
func (s *PresetsTestSuite) TestParsePresetEmptyName() {
presetStr := "=resize:fit:100:200/sharpen:2"
err := parsePreset(presetStr)
assert.Equal(s.T(), fmt.Errorf("Empty preset name: %s", presetStr), err)
assert.Empty(s.T(), presets)
require.Equal(s.T(), fmt.Errorf("Empty preset name: %s", presetStr), err)
require.Empty(s.T(), presets)
}
func (s *PresetsTestSuite) TestParsePresetEmptyValue() {
presetStr := "test="
err := parsePreset(presetStr)
assert.Equal(s.T(), fmt.Errorf("Empty preset value: %s", presetStr), err)
assert.Empty(s.T(), presets)
require.Equal(s.T(), fmt.Errorf("Empty preset value: %s", presetStr), err)
require.Empty(s.T(), presets)
}
func (s *PresetsTestSuite) TestParsePresetInvalidValue() {
presetStr := "test=resize:fit:100:200/sharpen:2/blur"
err := parsePreset(presetStr)
assert.Equal(s.T(), fmt.Errorf("Invalid preset value: %s", presetStr), err)
assert.Empty(s.T(), presets)
require.Equal(s.T(), fmt.Errorf("Invalid preset value: %s", presetStr), err)
require.Empty(s.T(), presets)
}
func (s *PresetsTestSuite) TestParsePresetEmptyString() {
err := parsePreset(" ")
assert.Nil(s.T(), err)
assert.Empty(s.T(), presets)
require.Nil(s.T(), err)
require.Empty(s.T(), presets)
}
func (s *PresetsTestSuite) TestParsePresetComment() {
err := parsePreset("# test=resize:fit:100:200/sharpen:2")
assert.Nil(s.T(), err)
assert.Empty(s.T(), presets)
require.Nil(s.T(), err)
require.Empty(s.T(), presets)
}
func (s *PresetsTestSuite) TestValidatePresets() {
@ -85,7 +84,7 @@ func (s *PresetsTestSuite) TestValidatePresets() {
err := ValidatePresets()
assert.Nil(s.T(), err)
require.Nil(s.T(), err)
}
func (s *PresetsTestSuite) TestValidatePresetsInvalid() {
@ -98,7 +97,7 @@ func (s *PresetsTestSuite) TestValidatePresetsInvalid() {
err := ValidatePresets()
assert.Error(s.T(), err)
require.Error(s.T(), err)
}
func TestPresets(t *testing.T) {

View File

@ -7,7 +7,6 @@ import (
"net/url"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
@ -29,8 +28,8 @@ func (s *ProcessingOptionsTestSuite) TestParseBase64URL() {
po, imageURL, err := ParsePath(path, make(http.Header))
require.Nil(s.T(), err)
assert.Equal(s.T(), originURL, imageURL)
assert.Equal(s.T(), imagetype.PNG, po.Format)
require.Equal(s.T(), originURL, imageURL)
require.Equal(s.T(), imagetype.PNG, po.Format)
}
func (s *ProcessingOptionsTestSuite) TestParseBase64URLWithoutExtension() {
@ -39,8 +38,8 @@ func (s *ProcessingOptionsTestSuite) TestParseBase64URLWithoutExtension() {
po, imageURL, err := ParsePath(path, make(http.Header))
require.Nil(s.T(), err)
assert.Equal(s.T(), originURL, imageURL)
assert.Equal(s.T(), imagetype.Unknown, po.Format)
require.Equal(s.T(), originURL, imageURL)
require.Equal(s.T(), imagetype.Unknown, po.Format)
}
func (s *ProcessingOptionsTestSuite) TestParseBase64URLWithBase() {
@ -51,8 +50,8 @@ func (s *ProcessingOptionsTestSuite) TestParseBase64URLWithBase() {
po, imageURL, err := ParsePath(path, make(http.Header))
require.Nil(s.T(), err)
assert.Equal(s.T(), fmt.Sprintf("%s%s", config.BaseURL, originURL), imageURL)
assert.Equal(s.T(), imagetype.PNG, po.Format)
require.Equal(s.T(), fmt.Sprintf("%s%s", config.BaseURL, originURL), imageURL)
require.Equal(s.T(), imagetype.PNG, po.Format)
}
func (s *ProcessingOptionsTestSuite) TestParsePlainURL() {
@ -61,8 +60,8 @@ func (s *ProcessingOptionsTestSuite) TestParsePlainURL() {
po, imageURL, err := ParsePath(path, make(http.Header))
require.Nil(s.T(), err)
assert.Equal(s.T(), originURL, imageURL)
assert.Equal(s.T(), imagetype.PNG, po.Format)
require.Equal(s.T(), originURL, imageURL)
require.Equal(s.T(), imagetype.PNG, po.Format)
}
func (s *ProcessingOptionsTestSuite) TestParsePlainURLWithoutExtension() {
@ -72,8 +71,8 @@ func (s *ProcessingOptionsTestSuite) TestParsePlainURLWithoutExtension() {
po, imageURL, err := ParsePath(path, make(http.Header))
require.Nil(s.T(), err)
assert.Equal(s.T(), originURL, imageURL)
assert.Equal(s.T(), imagetype.Unknown, po.Format)
require.Equal(s.T(), originURL, imageURL)
require.Equal(s.T(), imagetype.Unknown, po.Format)
}
func (s *ProcessingOptionsTestSuite) TestParsePlainURLEscaped() {
originURL := "http://images.dev/lorem/ipsum.jpg?param=value"
@ -81,8 +80,8 @@ func (s *ProcessingOptionsTestSuite) TestParsePlainURLEscaped() {
po, imageURL, err := ParsePath(path, make(http.Header))
require.Nil(s.T(), err)
assert.Equal(s.T(), originURL, imageURL)
assert.Equal(s.T(), imagetype.PNG, po.Format)
require.Equal(s.T(), originURL, imageURL)
require.Equal(s.T(), imagetype.PNG, po.Format)
}
func (s *ProcessingOptionsTestSuite) TestParsePlainURLWithBase() {
@ -93,8 +92,8 @@ func (s *ProcessingOptionsTestSuite) TestParsePlainURLWithBase() {
po, imageURL, err := ParsePath(path, make(http.Header))
require.Nil(s.T(), err)
assert.Equal(s.T(), fmt.Sprintf("%s%s", config.BaseURL, originURL), imageURL)
assert.Equal(s.T(), imagetype.PNG, po.Format)
require.Equal(s.T(), fmt.Sprintf("%s%s", config.BaseURL, originURL), imageURL)
require.Equal(s.T(), imagetype.PNG, po.Format)
}
func (s *ProcessingOptionsTestSuite) TestParsePlainURLEscapedWithBase() {
@ -105,8 +104,8 @@ func (s *ProcessingOptionsTestSuite) TestParsePlainURLEscapedWithBase() {
po, imageURL, err := ParsePath(path, make(http.Header))
require.Nil(s.T(), err)
assert.Equal(s.T(), fmt.Sprintf("%s%s", config.BaseURL, originURL), imageURL)
assert.Equal(s.T(), imagetype.PNG, po.Format)
require.Equal(s.T(), fmt.Sprintf("%s%s", config.BaseURL, originURL), imageURL)
require.Equal(s.T(), imagetype.PNG, po.Format)
}
// func (s *ProcessingOptionsTestSuite) TestParseURLAllowedSource() {
@ -133,7 +132,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathFormat() {
require.Nil(s.T(), err)
assert.Equal(s.T(), imagetype.WEBP, po.Format)
require.Equal(s.T(), imagetype.WEBP, po.Format)
}
func (s *ProcessingOptionsTestSuite) TestParsePathResize() {
@ -142,10 +141,10 @@ func (s *ProcessingOptionsTestSuite) TestParsePathResize() {
require.Nil(s.T(), err)
assert.Equal(s.T(), ResizeFill, po.ResizingType)
assert.Equal(s.T(), 100, po.Width)
assert.Equal(s.T(), 200, po.Height)
assert.True(s.T(), po.Enlarge)
require.Equal(s.T(), ResizeFill, po.ResizingType)
require.Equal(s.T(), 100, po.Width)
require.Equal(s.T(), 200, po.Height)
require.True(s.T(), po.Enlarge)
}
func (s *ProcessingOptionsTestSuite) TestParsePathResizingType() {
@ -154,7 +153,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathResizingType() {
require.Nil(s.T(), err)
assert.Equal(s.T(), ResizeFill, po.ResizingType)
require.Equal(s.T(), ResizeFill, po.ResizingType)
}
func (s *ProcessingOptionsTestSuite) TestParsePathSize() {
@ -163,9 +162,9 @@ func (s *ProcessingOptionsTestSuite) TestParsePathSize() {
require.Nil(s.T(), err)
assert.Equal(s.T(), 100, po.Width)
assert.Equal(s.T(), 200, po.Height)
assert.True(s.T(), po.Enlarge)
require.Equal(s.T(), 100, po.Width)
require.Equal(s.T(), 200, po.Height)
require.True(s.T(), po.Enlarge)
}
func (s *ProcessingOptionsTestSuite) TestParsePathWidth() {
@ -174,7 +173,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathWidth() {
require.Nil(s.T(), err)
assert.Equal(s.T(), 100, po.Width)
require.Equal(s.T(), 100, po.Width)
}
func (s *ProcessingOptionsTestSuite) TestParsePathHeight() {
@ -183,7 +182,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathHeight() {
require.Nil(s.T(), err)
assert.Equal(s.T(), 100, po.Height)
require.Equal(s.T(), 100, po.Height)
}
func (s *ProcessingOptionsTestSuite) TestParsePathEnlarge() {
@ -192,7 +191,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathEnlarge() {
require.Nil(s.T(), err)
assert.True(s.T(), po.Enlarge)
require.True(s.T(), po.Enlarge)
}
func (s *ProcessingOptionsTestSuite) TestParsePathExtend() {
@ -201,10 +200,10 @@ func (s *ProcessingOptionsTestSuite) TestParsePathExtend() {
require.Nil(s.T(), err)
assert.Equal(s.T(), true, po.Extend.Enabled)
assert.Equal(s.T(), GravitySouth, po.Extend.Gravity.Type)
assert.Equal(s.T(), 10.0, po.Extend.Gravity.X)
assert.Equal(s.T(), 20.0, po.Extend.Gravity.Y)
require.Equal(s.T(), true, po.Extend.Enabled)
require.Equal(s.T(), GravitySouth, po.Extend.Gravity.Type)
require.Equal(s.T(), 10.0, po.Extend.Gravity.X)
require.Equal(s.T(), 20.0, po.Extend.Gravity.Y)
}
func (s *ProcessingOptionsTestSuite) TestParsePathGravity() {
@ -213,7 +212,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathGravity() {
require.Nil(s.T(), err)
assert.Equal(s.T(), GravitySouthEast, po.Gravity.Type)
require.Equal(s.T(), GravitySouthEast, po.Gravity.Type)
}
func (s *ProcessingOptionsTestSuite) TestParsePathGravityFocuspoint() {
@ -222,9 +221,9 @@ func (s *ProcessingOptionsTestSuite) TestParsePathGravityFocuspoint() {
require.Nil(s.T(), err)
assert.Equal(s.T(), GravityFocusPoint, po.Gravity.Type)
assert.Equal(s.T(), 0.5, po.Gravity.X)
assert.Equal(s.T(), 0.75, po.Gravity.Y)
require.Equal(s.T(), GravityFocusPoint, po.Gravity.Type)
require.Equal(s.T(), 0.5, po.Gravity.X)
require.Equal(s.T(), 0.75, po.Gravity.Y)
}
func (s *ProcessingOptionsTestSuite) TestParsePathQuality() {
@ -233,7 +232,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathQuality() {
require.Nil(s.T(), err)
assert.Equal(s.T(), 55, po.Quality)
require.Equal(s.T(), 55, po.Quality)
}
func (s *ProcessingOptionsTestSuite) TestParsePathBackground() {
@ -242,10 +241,10 @@ func (s *ProcessingOptionsTestSuite) TestParsePathBackground() {
require.Nil(s.T(), err)
assert.True(s.T(), po.Flatten)
assert.Equal(s.T(), uint8(128), po.Background.R)
assert.Equal(s.T(), uint8(129), po.Background.G)
assert.Equal(s.T(), uint8(130), po.Background.B)
require.True(s.T(), po.Flatten)
require.Equal(s.T(), uint8(128), po.Background.R)
require.Equal(s.T(), uint8(129), po.Background.G)
require.Equal(s.T(), uint8(130), po.Background.B)
}
func (s *ProcessingOptionsTestSuite) TestParsePathBackgroundHex() {
@ -254,10 +253,10 @@ func (s *ProcessingOptionsTestSuite) TestParsePathBackgroundHex() {
require.Nil(s.T(), err)
assert.True(s.T(), po.Flatten)
assert.Equal(s.T(), uint8(0xff), po.Background.R)
assert.Equal(s.T(), uint8(0xdd), po.Background.G)
assert.Equal(s.T(), uint8(0xee), po.Background.B)
require.True(s.T(), po.Flatten)
require.Equal(s.T(), uint8(0xff), po.Background.R)
require.Equal(s.T(), uint8(0xdd), po.Background.G)
require.Equal(s.T(), uint8(0xee), po.Background.B)
}
func (s *ProcessingOptionsTestSuite) TestParsePathBackgroundDisable() {
@ -266,7 +265,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathBackgroundDisable() {
require.Nil(s.T(), err)
assert.False(s.T(), po.Flatten)
require.False(s.T(), po.Flatten)
}
func (s *ProcessingOptionsTestSuite) TestParsePathBlur() {
@ -275,7 +274,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathBlur() {
require.Nil(s.T(), err)
assert.Equal(s.T(), float32(0.2), po.Blur)
require.Equal(s.T(), float32(0.2), po.Blur)
}
func (s *ProcessingOptionsTestSuite) TestParsePathSharpen() {
@ -284,7 +283,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathSharpen() {
require.Nil(s.T(), err)
assert.Equal(s.T(), float32(0.2), po.Sharpen)
require.Equal(s.T(), float32(0.2), po.Sharpen)
}
func (s *ProcessingOptionsTestSuite) TestParsePathDpr() {
path := "/dpr:2/plain/http://images.dev/lorem/ipsum.jpg"
@ -292,7 +291,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathDpr() {
require.Nil(s.T(), err)
assert.Equal(s.T(), 2.0, po.Dpr)
require.Equal(s.T(), 2.0, po.Dpr)
}
func (s *ProcessingOptionsTestSuite) TestParsePathWatermark() {
path := "/watermark:0.5:soea:10:20:0.6/plain/http://images.dev/lorem/ipsum.jpg"
@ -300,11 +299,11 @@ func (s *ProcessingOptionsTestSuite) TestParsePathWatermark() {
require.Nil(s.T(), err)
assert.True(s.T(), po.Watermark.Enabled)
assert.Equal(s.T(), GravitySouthEast, po.Watermark.Gravity.Type)
assert.Equal(s.T(), 10.0, po.Watermark.Gravity.X)
assert.Equal(s.T(), 20.0, po.Watermark.Gravity.Y)
assert.Equal(s.T(), 0.6, po.Watermark.Scale)
require.True(s.T(), po.Watermark.Enabled)
require.Equal(s.T(), GravitySouthEast, po.Watermark.Gravity.Type)
require.Equal(s.T(), 10.0, po.Watermark.Gravity.X)
require.Equal(s.T(), 20.0, po.Watermark.Gravity.Y)
require.Equal(s.T(), 0.6, po.Watermark.Scale)
}
func (s *ProcessingOptionsTestSuite) TestParsePathPreset() {
@ -322,9 +321,9 @@ func (s *ProcessingOptionsTestSuite) TestParsePathPreset() {
require.Nil(s.T(), err)
assert.Equal(s.T(), ResizeFill, po.ResizingType)
assert.Equal(s.T(), float32(0.2), po.Blur)
assert.Equal(s.T(), 50, po.Quality)
require.Equal(s.T(), ResizeFill, po.ResizingType)
require.Equal(s.T(), float32(0.2), po.Blur)
require.Equal(s.T(), 50, po.Quality)
}
func (s *ProcessingOptionsTestSuite) TestParsePathPresetDefault() {
@ -339,9 +338,9 @@ func (s *ProcessingOptionsTestSuite) TestParsePathPresetDefault() {
require.Nil(s.T(), err)
assert.Equal(s.T(), ResizeFill, po.ResizingType)
assert.Equal(s.T(), float32(0.2), po.Blur)
assert.Equal(s.T(), 70, po.Quality)
require.Equal(s.T(), ResizeFill, po.ResizingType)
require.Equal(s.T(), float32(0.2), po.Blur)
require.Equal(s.T(), 70, po.Quality)
}
func (s *ProcessingOptionsTestSuite) TestParsePathPresetLoopDetection() {
@ -368,7 +367,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathCachebuster() {
require.Nil(s.T(), err)
assert.Equal(s.T(), "123", po.CacheBuster)
require.Equal(s.T(), "123", po.CacheBuster)
}
func (s *ProcessingOptionsTestSuite) TestParsePathStripMetadata() {
@ -377,7 +376,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathStripMetadata() {
require.Nil(s.T(), err)
assert.True(s.T(), po.StripMetadata)
require.True(s.T(), po.StripMetadata)
}
func (s *ProcessingOptionsTestSuite) TestParsePathWebpDetection() {
@ -389,8 +388,8 @@ func (s *ProcessingOptionsTestSuite) TestParsePathWebpDetection() {
require.Nil(s.T(), err)
assert.Equal(s.T(), true, po.PreferWebP)
assert.Equal(s.T(), false, po.EnforceWebP)
require.Equal(s.T(), true, po.PreferWebP)
require.Equal(s.T(), false, po.EnforceWebP)
}
func (s *ProcessingOptionsTestSuite) TestParsePathWebpEnforce() {
@ -402,8 +401,8 @@ func (s *ProcessingOptionsTestSuite) TestParsePathWebpEnforce() {
require.Nil(s.T(), err)
assert.Equal(s.T(), true, po.PreferWebP)
assert.Equal(s.T(), true, po.EnforceWebP)
require.Equal(s.T(), true, po.PreferWebP)
require.Equal(s.T(), true, po.EnforceWebP)
}
func (s *ProcessingOptionsTestSuite) TestParsePathWidthHeader() {
@ -415,7 +414,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathWidthHeader() {
require.Nil(s.T(), err)
assert.Equal(s.T(), 100, po.Width)
require.Equal(s.T(), 100, po.Width)
}
func (s *ProcessingOptionsTestSuite) TestParsePathWidthHeaderDisabled() {
@ -425,7 +424,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathWidthHeaderDisabled() {
require.Nil(s.T(), err)
assert.Equal(s.T(), 0, po.Width)
require.Equal(s.T(), 0, po.Width)
}
func (s *ProcessingOptionsTestSuite) TestParsePathWidthHeaderRedefine() {
@ -437,7 +436,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathWidthHeaderRedefine() {
require.Nil(s.T(), err)
assert.Equal(s.T(), 150, po.Width)
require.Equal(s.T(), 150, po.Width)
}
func (s *ProcessingOptionsTestSuite) TestParsePathViewportWidthHeader() {
@ -449,7 +448,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathViewportWidthHeader() {
require.Nil(s.T(), err)
assert.Equal(s.T(), 100, po.Width)
require.Equal(s.T(), 100, po.Width)
}
func (s *ProcessingOptionsTestSuite) TestParsePathViewportWidthHeaderDisabled() {
@ -459,7 +458,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathViewportWidthHeaderDisabled()
require.Nil(s.T(), err)
assert.Equal(s.T(), 0, po.Width)
require.Equal(s.T(), 0, po.Width)
}
func (s *ProcessingOptionsTestSuite) TestParsePathViewportWidthHeaderRedefine() {
@ -471,7 +470,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathViewportWidthHeaderRedefine()
require.Nil(s.T(), err)
assert.Equal(s.T(), 150, po.Width)
require.Equal(s.T(), 150, po.Width)
}
func (s *ProcessingOptionsTestSuite) TestParsePathDprHeader() {
@ -483,7 +482,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathDprHeader() {
require.Nil(s.T(), err)
assert.Equal(s.T(), 2.0, po.Dpr)
require.Equal(s.T(), 2.0, po.Dpr)
}
func (s *ProcessingOptionsTestSuite) TestParsePathDprHeaderDisabled() {
@ -493,7 +492,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathDprHeaderDisabled() {
require.Nil(s.T(), err)
assert.Equal(s.T(), 1.0, po.Dpr)
require.Equal(s.T(), 1.0, po.Dpr)
}
// func (s *ProcessingOptionsTestSuite) TestParsePathSigned() {
@ -514,7 +513,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathDprHeaderDisabled() {
// _, _, err := ParsePath(path, make(http.Header))
// require.Error(s.T(), err)
// assert.Equal(s.T(), signature.ErrInvalidSignature.Error(), err.Error())
// require.Equal(s.T(), signature.ErrInvalidSignature.Error(), err.Error())
// }
func (s *ProcessingOptionsTestSuite) TestParsePathOnlyPresets() {
@ -532,8 +531,8 @@ func (s *ProcessingOptionsTestSuite) TestParsePathOnlyPresets() {
require.Nil(s.T(), err)
assert.Equal(s.T(), float32(0.2), po.Blur)
assert.Equal(s.T(), 50, po.Quality)
require.Equal(s.T(), float32(0.2), po.Blur)
require.Equal(s.T(), 50, po.Quality)
}
func (s *ProcessingOptionsTestSuite) TestParseSkipProcessing() {
@ -543,7 +542,7 @@ func (s *ProcessingOptionsTestSuite) TestParseSkipProcessing() {
require.Nil(s.T(), err)
assert.Equal(s.T(), []imagetype.Type{imagetype.JPEG, imagetype.PNG}, po.SkipProcessingFormats)
require.Equal(s.T(), []imagetype.Type{imagetype.JPEG, imagetype.PNG}, po.SkipProcessingFormats)
}
func (s *ProcessingOptionsTestSuite) TestParseSkipProcessingInvalid() {
@ -552,7 +551,7 @@ func (s *ProcessingOptionsTestSuite) TestParseSkipProcessingInvalid() {
_, _, err := ParsePath(path, make(http.Header))
require.Error(s.T(), err)
assert.Equal(s.T(), "Invalid image format in skip processing: bad_format", err.Error())
require.Equal(s.T(), "Invalid image format in skip processing: bad_format", err.Error())
}
func (s *ProcessingOptionsTestSuite) TestParseExpires() {
@ -567,7 +566,7 @@ func (s *ProcessingOptionsTestSuite) TestParseExpiresExpired() {
_, _, err := ParsePath(path, make(http.Header))
require.Error(s.T(), err)
assert.Equal(s.T(), errExpiredURL.Error(), err.Error())
require.Equal(s.T(), errExpiredURL.Error(), err.Error())
}
func (s *ProcessingOptionsTestSuite) TestParseBase64URLOnlyPresets() {
@ -586,9 +585,9 @@ func (s *ProcessingOptionsTestSuite) TestParseBase64URLOnlyPresets() {
require.Nil(s.T(), err)
assert.Equal(s.T(), float32(0.2), po.Blur)
assert.Equal(s.T(), 50, po.Quality)
assert.Equal(s.T(), originURL, imageURL)
require.Equal(s.T(), float32(0.2), po.Blur)
require.Equal(s.T(), 50, po.Quality)
require.Equal(s.T(), originURL, imageURL)
}
func TestProcessingOptions(t *testing.T) {

View File

@ -23,7 +23,7 @@ import (
"github.com/imgproxy/imgproxy/v3/svg"
"github.com/imgproxy/imgproxy/v3/vips"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
@ -37,11 +37,12 @@ func (s *ProcessingHandlerTestSuite) SetupSuite() {
config.Reset()
wd, err := os.Getwd()
assert.Nil(s.T(), err)
require.Nil(s.T(), err)
config.LocalFileSystemRoot = filepath.Join(wd, "/testdata")
initialize()
err = initialize()
require.Nil(s.T(), err)
logrus.SetOutput(ioutil.Discard)
@ -74,17 +75,17 @@ func (s *ProcessingHandlerTestSuite) send(path string, header ...http.Header) *h
func (s *ProcessingHandlerTestSuite) readTestFile(name string) []byte {
wd, err := os.Getwd()
assert.Nil(s.T(), err)
require.Nil(s.T(), err)
data, err := ioutil.ReadFile(filepath.Join(wd, "testdata", name))
assert.Nil(s.T(), err)
require.Nil(s.T(), err)
return data
}
func (s *ProcessingHandlerTestSuite) readBody(res *http.Response) []byte {
data, err := ioutil.ReadAll(res.Body)
assert.Nil(s.T(), err)
require.Nil(s.T(), err)
return data
}
@ -116,15 +117,15 @@ func (s *ProcessingHandlerTestSuite) TestRequest() {
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png")
res := rw.Result()
assert.Equal(s.T(), 200, res.StatusCode)
assert.Equal(s.T(), "image/png", res.Header.Get("Content-Type"))
require.Equal(s.T(), 200, res.StatusCode)
require.Equal(s.T(), "image/png", res.Header.Get("Content-Type"))
meta, err := imagemeta.DecodeMeta(res.Body)
assert.Nil(s.T(), err)
assert.Equal(s.T(), imagetype.PNG, meta.Format())
assert.Equal(s.T(), 4, meta.Width())
assert.Equal(s.T(), 4, meta.Height())
require.Nil(s.T(), err)
require.Equal(s.T(), imagetype.PNG, meta.Format())
require.Equal(s.T(), 4, meta.Width())
require.Equal(s.T(), 4, meta.Height())
}
func (s *ProcessingHandlerTestSuite) TestSignatureValidationFailure() {
@ -134,7 +135,7 @@ func (s *ProcessingHandlerTestSuite) TestSignatureValidationFailure() {
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png")
res := rw.Result()
assert.Equal(s.T(), 403, res.StatusCode)
require.Equal(s.T(), 403, res.StatusCode)
}
func (s *ProcessingHandlerTestSuite) TestSignatureValidationSuccess() {
@ -144,7 +145,7 @@ func (s *ProcessingHandlerTestSuite) TestSignatureValidationSuccess() {
rw := s.send("/My9d3xq_PYpVHsPrCyww0Kh1w5KZeZhIlWhsa4az1TI/rs:fill:4:4/plain/local:///test1.png")
res := rw.Result()
assert.Equal(s.T(), 200, res.StatusCode)
require.Equal(s.T(), 200, res.StatusCode)
}
func (s *ProcessingHandlerTestSuite) TestSourceValidation() {
@ -201,9 +202,9 @@ func (s *ProcessingHandlerTestSuite) TestSourceValidation() {
res := rw.Result()
if tc.expectedError {
assert.Equal(s.T(), 404, res.StatusCode)
require.Equal(s.T(), 404, res.StatusCode)
} else {
assert.Equal(s.T(), 200, res.StatusCode)
require.Equal(s.T(), 200, res.StatusCode)
}
})
}
@ -216,7 +217,7 @@ func (s *ProcessingHandlerTestSuite) TestSourceFormatNotSupported() {
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png")
res := rw.Result()
assert.Equal(s.T(), 422, res.StatusCode)
require.Equal(s.T(), 422, res.StatusCode)
}
func (s *ProcessingHandlerTestSuite) TestResultingFormatNotSupported() {
@ -226,7 +227,7 @@ func (s *ProcessingHandlerTestSuite) TestResultingFormatNotSupported() {
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png@png")
res := rw.Result()
assert.Equal(s.T(), 422, res.StatusCode)
require.Equal(s.T(), 422, res.StatusCode)
}
func (s *ProcessingHandlerTestSuite) TestSkipProcessingConfig() {
@ -235,24 +236,24 @@ func (s *ProcessingHandlerTestSuite) TestSkipProcessingConfig() {
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png")
res := rw.Result()
assert.Equal(s.T(), 200, res.StatusCode)
require.Equal(s.T(), 200, res.StatusCode)
actual := s.readBody(res)
expected := s.readTestFile("test1.png")
assert.True(s.T(), bytes.Equal(expected, actual))
require.True(s.T(), bytes.Equal(expected, actual))
}
func (s *ProcessingHandlerTestSuite) TestSkipProcessingPO() {
rw := s.send("/unsafe/rs:fill:4:4/skp:png/plain/local:///test1.png")
res := rw.Result()
assert.Equal(s.T(), 200, res.StatusCode)
require.Equal(s.T(), 200, res.StatusCode)
actual := s.readBody(res)
expected := s.readTestFile("test1.png")
assert.True(s.T(), bytes.Equal(expected, actual))
require.True(s.T(), bytes.Equal(expected, actual))
}
func (s *ProcessingHandlerTestSuite) TestSkipProcessingSameFormat() {
@ -261,12 +262,12 @@ func (s *ProcessingHandlerTestSuite) TestSkipProcessingSameFormat() {
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png@png")
res := rw.Result()
assert.Equal(s.T(), 200, res.StatusCode)
require.Equal(s.T(), 200, res.StatusCode)
actual := s.readBody(res)
expected := s.readTestFile("test1.png")
assert.True(s.T(), bytes.Equal(expected, actual))
require.True(s.T(), bytes.Equal(expected, actual))
}
func (s *ProcessingHandlerTestSuite) TestSkipProcessingDifferentFormat() {
@ -275,45 +276,45 @@ func (s *ProcessingHandlerTestSuite) TestSkipProcessingDifferentFormat() {
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png@jpg")
res := rw.Result()
assert.Equal(s.T(), 200, res.StatusCode)
require.Equal(s.T(), 200, res.StatusCode)
actual := s.readBody(res)
expected := s.readTestFile("test1.png")
assert.False(s.T(), bytes.Equal(expected, actual))
require.False(s.T(), bytes.Equal(expected, actual))
}
func (s *ProcessingHandlerTestSuite) TestSkipProcessingSVG() {
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.svg")
res := rw.Result()
assert.Equal(s.T(), 200, res.StatusCode)
require.Equal(s.T(), 200, res.StatusCode)
actual := s.readBody(res)
expected, err := svg.Satitize(s.readTestFile("test1.svg"))
assert.Nil(s.T(), err)
require.Nil(s.T(), err)
assert.True(s.T(), bytes.Equal(expected, actual))
require.True(s.T(), bytes.Equal(expected, actual))
}
func (s *ProcessingHandlerTestSuite) TestNotSkipProcessingSVGToJPG() {
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.svg@jpg")
res := rw.Result()
assert.Equal(s.T(), 200, res.StatusCode)
require.Equal(s.T(), 200, res.StatusCode)
actual := s.readBody(res)
expected := s.readTestFile("test1.svg")
assert.False(s.T(), bytes.Equal(expected, actual))
require.False(s.T(), bytes.Equal(expected, actual))
}
func (s *ProcessingHandlerTestSuite) TestErrorSavingToSVG() {
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png@svg")
res := rw.Result()
assert.Equal(s.T(), 422, res.StatusCode)
require.Equal(s.T(), 422, res.StatusCode)
}
func (s *ProcessingHandlerTestSuite) TestCacheControlPassthrough() {
@ -330,8 +331,8 @@ func (s *ProcessingHandlerTestSuite) TestCacheControlPassthrough() {
rw := s.send("/unsafe/rs:fill:4:4/plain/" + ts.URL)
res := rw.Result()
assert.Equal(s.T(), "fake-cache-control", res.Header.Get("Cache-Control"))
assert.Equal(s.T(), "fake-expires", res.Header.Get("Expires"))
require.Equal(s.T(), "fake-cache-control", res.Header.Get("Cache-Control"))
require.Equal(s.T(), "fake-expires", res.Header.Get("Expires"))
}
func (s *ProcessingHandlerTestSuite) TestCacheControlPassthroughDisabled() {
@ -348,8 +349,8 @@ func (s *ProcessingHandlerTestSuite) TestCacheControlPassthroughDisabled() {
rw := s.send("/unsafe/rs:fill:4:4/plain/" + ts.URL)
res := rw.Result()
assert.NotEqual(s.T(), "fake-cache-control", res.Header.Get("Cache-Control"))
assert.NotEqual(s.T(), "fake-expires", res.Header.Get("Expires"))
require.NotEqual(s.T(), "fake-cache-control", res.Header.Get("Cache-Control"))
require.NotEqual(s.T(), "fake-expires", res.Header.Get("Expires"))
}
func (s *ProcessingHandlerTestSuite) TestETagDisabled() {
@ -358,8 +359,8 @@ func (s *ProcessingHandlerTestSuite) TestETagDisabled() {
rw := s.send("/unsafe/rs:fill:4:4/plain/local:///test1.png")
res := rw.Result()
assert.Equal(s.T(), 200, res.StatusCode)
assert.Empty(s.T(), res.Header.Get("ETag"))
require.Equal(s.T(), 200, res.StatusCode)
require.Empty(s.T(), res.Header.Get("ETag"))
}
func (s *ProcessingHandlerTestSuite) TestETagReqNoIfNotModified() {
@ -368,7 +369,7 @@ func (s *ProcessingHandlerTestSuite) TestETagReqNoIfNotModified() {
poStr, imgdata, etag := s.sampleETagData("loremipsumdolor")
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
assert.Empty(s.T(), r.Header.Get("If-None-Match"))
require.Empty(s.T(), r.Header.Get("If-None-Match"))
rw.Header().Set("ETag", imgdata.Headers["ETag"])
rw.WriteHeader(200)
@ -379,8 +380,8 @@ func (s *ProcessingHandlerTestSuite) TestETagReqNoIfNotModified() {
rw := s.send(fmt.Sprintf("/unsafe/%s/plain/%s", poStr, ts.URL))
res := rw.Result()
assert.Equal(s.T(), 200, res.StatusCode)
assert.Equal(s.T(), etag, res.Header.Get("ETag"))
require.Equal(s.T(), 200, res.StatusCode)
require.Equal(s.T(), etag, res.Header.Get("ETag"))
}
func (s *ProcessingHandlerTestSuite) TestETagDataNoIfNotModified() {
@ -389,7 +390,7 @@ func (s *ProcessingHandlerTestSuite) TestETagDataNoIfNotModified() {
poStr, imgdata, etag := s.sampleETagData("")
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
assert.Empty(s.T(), r.Header.Get("If-None-Match"))
require.Empty(s.T(), r.Header.Get("If-None-Match"))
rw.WriteHeader(200)
rw.Write(imgdata.Data)
@ -399,8 +400,8 @@ func (s *ProcessingHandlerTestSuite) TestETagDataNoIfNotModified() {
rw := s.send(fmt.Sprintf("/unsafe/%s/plain/%s", poStr, ts.URL))
res := rw.Result()
assert.Equal(s.T(), 200, res.StatusCode)
assert.Equal(s.T(), etag, res.Header.Get("ETag"))
require.Equal(s.T(), 200, res.StatusCode)
require.Equal(s.T(), etag, res.Header.Get("ETag"))
}
func (s *ProcessingHandlerTestSuite) TestETagReqMatch() {
@ -409,7 +410,7 @@ func (s *ProcessingHandlerTestSuite) TestETagReqMatch() {
poStr, imgdata, etag := s.sampleETagData(`"loremipsumdolor"`)
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
assert.Equal(s.T(), imgdata.Headers["ETag"], r.Header.Get("If-None-Match"))
require.Equal(s.T(), imgdata.Headers["ETag"], r.Header.Get("If-None-Match"))
rw.WriteHeader(304)
}))
@ -421,8 +422,8 @@ func (s *ProcessingHandlerTestSuite) TestETagReqMatch() {
rw := s.send(fmt.Sprintf("/unsafe/%s/plain/%s", poStr, ts.URL), header)
res := rw.Result()
assert.Equal(s.T(), 304, res.StatusCode)
assert.Equal(s.T(), etag, res.Header.Get("ETag"))
require.Equal(s.T(), 304, res.StatusCode)
require.Equal(s.T(), etag, res.Header.Get("ETag"))
}
func (s *ProcessingHandlerTestSuite) TestETagDataMatch() {
@ -431,7 +432,7 @@ func (s *ProcessingHandlerTestSuite) TestETagDataMatch() {
poStr, imgdata, etag := s.sampleETagData("")
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
assert.Empty(s.T(), r.Header.Get("If-None-Match"))
require.Empty(s.T(), r.Header.Get("If-None-Match"))
rw.WriteHeader(200)
rw.Write(imgdata.Data)
@ -444,8 +445,8 @@ func (s *ProcessingHandlerTestSuite) TestETagDataMatch() {
rw := s.send(fmt.Sprintf("/unsafe/%s/plain/%s", poStr, ts.URL), header)
res := rw.Result()
assert.Equal(s.T(), 304, res.StatusCode)
assert.Equal(s.T(), etag, res.Header.Get("ETag"))
require.Equal(s.T(), 304, res.StatusCode)
require.Equal(s.T(), etag, res.Header.Get("ETag"))
}
func (s *ProcessingHandlerTestSuite) TestETagReqNotMatch() {
@ -455,7 +456,7 @@ func (s *ProcessingHandlerTestSuite) TestETagReqNotMatch() {
_, _, expectedETag := s.sampleETagData(`"loremipsum"`)
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
assert.Equal(s.T(), `"loremipsum"`, r.Header.Get("If-None-Match"))
require.Equal(s.T(), `"loremipsum"`, r.Header.Get("If-None-Match"))
rw.Header().Set("ETag", imgdata.Headers["ETag"])
rw.WriteHeader(200)
@ -469,8 +470,8 @@ func (s *ProcessingHandlerTestSuite) TestETagReqNotMatch() {
rw := s.send(fmt.Sprintf("/unsafe/%s/plain/%s", poStr, ts.URL), header)
res := rw.Result()
assert.Equal(s.T(), 200, res.StatusCode)
assert.Equal(s.T(), actualETag, res.Header.Get("ETag"))
require.Equal(s.T(), 200, res.StatusCode)
require.Equal(s.T(), actualETag, res.Header.Get("ETag"))
}
func (s *ProcessingHandlerTestSuite) TestETagDataNotMatch() {
@ -481,7 +482,7 @@ func (s *ProcessingHandlerTestSuite) TestETagDataNotMatch() {
expectedETag := actualETag[:strings.IndexByte(actualETag, '/')] + "/Dasdbefj"
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
assert.Empty(s.T(), r.Header.Get("If-None-Match"))
require.Empty(s.T(), r.Header.Get("If-None-Match"))
rw.WriteHeader(200)
rw.Write(imgdata.Data)
@ -494,8 +495,8 @@ func (s *ProcessingHandlerTestSuite) TestETagDataNotMatch() {
rw := s.send(fmt.Sprintf("/unsafe/%s/plain/%s", poStr, ts.URL), header)
res := rw.Result()
assert.Equal(s.T(), 200, res.StatusCode)
assert.Equal(s.T(), actualETag, res.Header.Get("ETag"))
require.Equal(s.T(), 200, res.StatusCode)
require.Equal(s.T(), actualETag, res.Header.Get("ETag"))
}
func (s *ProcessingHandlerTestSuite) TestETagProcessingOptionsNotMatch() {
@ -506,7 +507,7 @@ func (s *ProcessingHandlerTestSuite) TestETagProcessingOptionsNotMatch() {
expectedETag := "abcdefj" + actualETag[strings.IndexByte(actualETag, '/'):]
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
assert.Empty(s.T(), r.Header.Get("If-None-Match"))
require.Empty(s.T(), r.Header.Get("If-None-Match"))
rw.Header().Set("ETag", imgdata.Headers["ETag"])
rw.WriteHeader(200)
@ -520,8 +521,8 @@ func (s *ProcessingHandlerTestSuite) TestETagProcessingOptionsNotMatch() {
rw := s.send(fmt.Sprintf("/unsafe/%s/plain/%s", poStr, ts.URL), header)
res := rw.Result()
assert.Equal(s.T(), 200, res.StatusCode)
assert.Equal(s.T(), actualETag, res.Header.Get("ETag"))
require.Equal(s.T(), 200, res.StatusCode)
require.Equal(s.T(), actualETag, res.Header.Get("ETag"))
}
func TestProcessingHandler(t *testing.T) {

View File

@ -3,7 +3,7 @@ package security
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/imgproxy/imgproxy/v3/config"
@ -22,19 +22,19 @@ func (s *SignatureTestSuite) SetupTest() {
func (s *SignatureTestSuite) TestVerifySignature() {
err := VerifySignature("dtLwhdnPPiu_epMl1LrzheLpvHas-4mwvY6L3Z8WwlY", "asd")
assert.Nil(s.T(), err)
require.Nil(s.T(), err)
}
func (s *SignatureTestSuite) TestVerifySignatureTruncated() {
config.SignatureSize = 8
err := VerifySignature("dtLwhdnPPis", "asd")
assert.Nil(s.T(), err)
require.Nil(s.T(), err)
}
func (s *SignatureTestSuite) TestVerifySignatureInvalid() {
err := VerifySignature("dtLwhdnPPis", "asd")
assert.Error(s.T(), err)
require.Error(s.T(), err)
}
func (s *SignatureTestSuite) TestVerifySignatureMultiplePairs() {
@ -42,13 +42,13 @@ func (s *SignatureTestSuite) TestVerifySignatureMultiplePairs() {
config.Salts = append(config.Salts, []byte("test-salt2"))
err := VerifySignature("dtLwhdnPPiu_epMl1LrzheLpvHas-4mwvY6L3Z8WwlY", "asd")
assert.Nil(s.T(), err)
require.Nil(s.T(), err)
err = VerifySignature("jbDffNPt1-XBgDccsaE-XJB9lx8JIJqdeYIZKgOqZpg", "asd")
assert.Nil(s.T(), err)
require.Nil(s.T(), err)
err = VerifySignature("dtLwhdnPPis", "asd")
assert.Error(s.T(), err)
require.Error(s.T(), err)
}
func TestSignature(t *testing.T) {