(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestContentEncodingMiddleware(t *testing.T) { |
| 13 | t.Parallel() |
| 14 | |
| 15 | // support for: |
| 16 | // Content-Encoding: gzip |
| 17 | // Content-Encoding: deflate |
| 18 | // Content-Encoding: gzip, deflate |
| 19 | // Content-Encoding: deflate, gzip |
| 20 | middleware := AllowContentEncoding("deflate", "gzip") |
| 21 | |
| 22 | tests := []struct { |
| 23 | name string |
| 24 | encodings []string |
| 25 | expectedStatus int |
| 26 | }{ |
| 27 | { |
| 28 | name: "Support no encoding", |
| 29 | encodings: []string{}, |
| 30 | expectedStatus: 200, |
| 31 | }, |
| 32 | { |
| 33 | name: "Support gzip encoding", |
| 34 | encodings: []string{"gzip"}, |
| 35 | expectedStatus: 200, |
| 36 | }, |
| 37 | { |
| 38 | name: "No support for br encoding", |
| 39 | encodings: []string{"br"}, |
| 40 | expectedStatus: 415, |
| 41 | }, |
| 42 | { |
| 43 | name: "Support for gzip and deflate encoding", |
| 44 | encodings: []string{"gzip", "deflate"}, |
| 45 | expectedStatus: 200, |
| 46 | }, |
| 47 | { |
| 48 | name: "Support for deflate and gzip encoding", |
| 49 | encodings: []string{"deflate", "gzip"}, |
| 50 | expectedStatus: 200, |
| 51 | }, |
| 52 | { |
| 53 | name: "No support for deflate and br encoding", |
| 54 | encodings: []string{"deflate", "br"}, |
| 55 | expectedStatus: 415, |
| 56 | }, |
| 57 | } |
| 58 | |
| 59 | for _, tt := range tests { |
| 60 | var tt = tt |
| 61 | t.Run(tt.name, func(t *testing.T) { |
| 62 | t.Parallel() |
| 63 | |
| 64 | body := []byte("This is my content. There are many like this but this one is mine") |
| 65 | r := httptest.NewRequest("POST", "/", bytes.NewReader(body)) |
| 66 | for _, encoding := range tt.encodings { |
| 67 | r.Header.Set("Content-Encoding", encoding) |
| 68 | } |
| 69 |
nothing calls this directly
no test coverage detected