cerrado @ 10925e006bf43edc79331fbe601e09a28c43df2b

 1// go:build unit
 2package ext
 3
 4import "testing"
 5
 6func TestGetCompression(t *testing.T) {
 7	testCases := []struct {
 8		name        string
 9		header      string
10		compression string
11	}{
12		{
13			name:        "Empty",
14			header:      "",
15			compression: "*",
16		},
17		{
18			name:        "Weighted",
19			header:      "gzip;q=1.0, *;q=0.5",
20			compression: "gzip",
21		},
22		{
23			name:        "Mixed",
24			header:      "deflate, gzip;q=1.0, *;q=0.5",
25			compression: "deflate",
26		},
27		{
28			name:        "Not weighted",
29			header:      "zstd, deflate, gzip",
30			compression: "zstd",
31		},
32	}
33
34	for _, tc := range testCases {
35		t.Run(tc.name, func(t *testing.T) {
36			got := GetCompression(tc.header)
37			if got != tc.compression {
38				t.Errorf("Wrong compression returned: got %s want %s", got, tc.compression)
39			}
40		})
41	}
42}