aboutsummaryrefslogtreecommitdiff
path: root/pkg/ext/compression_test.go
blob: 64243780d97c90cee130ae60d5652275dd7d9814 (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
// go:build unit
package ext

import "testing"

func TestGetCompression(t *testing.T) {
	testCases := []struct {
		name        string
		header      string
		compression string
	}{
		{
			name:        "Empty",
			header:      "",
			compression: "*",
		},
		{
			name:        "Weighted",
			header:      "gzip;q=1.0, *;q=0.5",
			compression: "gzip",
		},
		{
			name:        "Mixed",
			header:      "deflate, gzip;q=1.0, *;q=0.5",
			compression: "deflate",
		},
		{
			name:        "Not weighted",
			header:      "zstd, deflate, gzip",
			compression: "zstd",
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			got := GetCompression(tc.header)
			if got != tc.compression {
				t.Errorf("Wrong compression returned: got %s want %s", got, tc.compression)
			}
		})
	}
}