Welcome to mirror list, hosted at ThFree Co, Russian Federation.

rewrite_test.go « upload « internal « workhorse - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e3f33a02489347a7c83c9990c542c5a8983a063f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package upload

import (
	"os"
	"runtime"
	"testing"

	"github.com/stretchr/testify/require"
)

func TestImageTypeRecongition(t *testing.T) {
	tests := []struct {
		filename string
		isJPEG   bool
		isTIFF   bool
	}{
		{
			filename: "exif/testdata/sample_exif.jpg",
			isJPEG:   true,
			isTIFF:   false,
		}, {
			filename: "exif/testdata/sample_exif.tiff",
			isJPEG:   false,
			isTIFF:   true,
		}, {
			filename: "exif/testdata/sample_exif_corrupted.jpg",
			isJPEG:   true,
			isTIFF:   false,
		}, {
			filename: "exif/testdata/sample_exif_invalid.jpg",
			isJPEG:   false,
			isTIFF:   false,
		}, {
			filename: "exif/testdata/takes_lot_of_memory_to_decode.tiff", // File from https://gitlab.com/gitlab-org/gitlab/-/issues/341363
			isJPEG:   false,
			isTIFF:   true,
		},
	}

	for _, test := range tests {
		t.Run(test.filename, func(t *testing.T) {
			input, err := os.Open(test.filename)
			require.NoError(t, err)

			var m runtime.MemStats
			runtime.ReadMemStats(&m)
			start := m.TotalAlloc

			require.Equal(t, test.isJPEG, isJPEG(input))
			require.Equal(t, test.isTIFF, isTIFF(input))

			runtime.ReadMemStats(&m)
			require.Less(t, m.TotalAlloc-start, uint64(50000), "must take reasonable amount of memory to recognise the type")
		})
	}
}