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)
| 81 | // which is expected to be in the `integration` folder with the same name |
| 82 | // but with `.png` extension. |
| 83 | func (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 | } |
| 132 | func TestMatrix(t *testing.T) { |
| 133 | suite.Run(t, new(MatrixTestSuite)) |
| 134 | } |
no test coverage detected