MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / testFormat

Method testFormat

integration_test/matrix_test.go:83–131  ·  view source on GitHub ↗

testFormat fetches images iterates over images in the specified folder, runs imgproxy on each image, and compares the result with the reference image which is expected to be in the `integration` folder with the same name but with `.png` extension.

(source, target imagetype.Type)

Source from the content-addressed store, hash-verified

81// which is expected to be in the `integration` folder with the same name
82// but with `.png` extension.
83func (s *MatrixTestSuite) testFormat(source, target imagetype.Type) {
84 folder := source.String()
85
86 // TODO: rename the folders in test-images repo
87 if folder == "heic" {
88 folder = "heif"
89 }
90
91 if folder == "jpeg" {
92 folder = "jpg"
93 }
94
95 walkPath := path.Join(s.testImagesPath, folder)
96
97 // Iterate over the files in the source folder
98 err := filepath.Walk(walkPath, func(path string, info os.FileInfo, err error) error {
99 s.Require().NoError(err)
100
101 // Skip directories
102 if info.IsDir() {
103 return nil
104 }
105
106 // get the base name of the file (8-bpp.png)
107 baseName := filepath.Base(path)
108
109 // Construct the source URL for imgproxy (no processing)
110 sourceUrl := fmt.Sprintf("/insecure/plain/local:///%s/%s@%s", folder, baseName, target.String())
111
112 // Read source image from imgproxy
113 resp := s.GET(sourceUrl)
114 defer resp.Body.Close()
115
116 s.Require().Equal(
117 http.StatusOK,
118 resp.StatusCode,
119 "expected status code 200 OK, got %d, url: %s",
120 resp.StatusCode,
121 sourceUrl,
122 )
123
124 // Match image to precalculated hash
125 s.matcher.ImageMatches(s.T(), resp.Body, baseName, maxDistance)
126
127 return nil
128 })
129
130 s.Require().NoError(err)
131}
132func TestMatrix(t *testing.T) {
133 suite.Run(t, new(MatrixTestSuite))
134}

Callers 1

TestMatrixMethod · 0.95

Calls 5

ImageMatchesMethod · 0.80
TMethod · 0.80
CloseMethod · 0.65
StringMethod · 0.45
GETMethod · 0.45

Tested by

no test coverage detected