1 package httpencoding 2 3 import ( 4 "net/http" 5 "reflect" 6 "testing" 7 ) 8 9 type testEncodings []string 10 11 func (t *testEncodings) Handle(encoding Encoding) bool { 12 *t = append(*t, string(encoding)) 13 return false 14 } 15 16 func TestOrder(t *testing.T) { 17 for n, test := range []struct { 18 AcceptEncoding string 19 Encodings testEncodings 20 }{ 21 {"", testEncodings{""}}, 22 {"gzip", testEncodings{"gzip", ""}}, 23 {"gzip, deflate, br", testEncodings{"gzip", "deflate", "br", ""}}, 24 {"gzip, deflate;q=0.5, br;q=1.9", testEncodings{"br", "gzip", "deflate", ""}}, 25 {"identity, gzip, deflate;q=0.5, br;q=1.9", testEncodings{"br", "", "gzip", "deflate"}}, 26 {"gzip, br, identity;q=0", testEncodings{"gzip", "br"}}, 27 {"gzip, br, identity;q=0, *", testEncodings{"gzip", "br"}}, 28 {"gzip, *, br", testEncodings{"gzip", "", "br"}}, 29 } { 30 te := make(testEncodings, 0, len(test.Encodings)) 31 HandleEncoding(&http.Request{ 32 Header: http.Header{ 33 acceptEncoding: []string{test.AcceptEncoding}, 34 }, 35 }, &te) 36 if !reflect.DeepEqual(te, test.Encodings) { 37 t.Errorf("test %d: expecting %v, got %v", n+1, test.Encodings, te) 38 } 39 } 40 }