(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func TestIsBrowserOrAPIRequest(t *testing.T) { |
| 16 | for k, tc := range []struct { |
| 17 | ua string |
| 18 | h string |
| 19 | e bool |
| 20 | }{ |
| 21 | {ua: "firefox-66", h: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", e: true}, |
| 22 | {ua: "safari-chrome", h: "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", e: true}, |
| 23 | {ua: "ie8", h: "image/jpeg,application/x-ms-application,image/gif,application/xaml+xml,image/pjpeg,application/x-ms-xbap,application/x-shockwave-flash,application/msword,*/*", e: true}, |
| 24 | {ua: "ie8-any", h: "*/*", e: true}, |
| 25 | {ua: "edge", h: "text/html,application/xhtml+xml,image/jxr,*/*", e: true}, |
| 26 | {ua: "opera", h: "text/html,application/xml;q=0.9,application/xhtml+xml,image/png,image/webp,image/jpeg,image/gif,image/x-xbitmap,*/*;q=0.1", e: true}, |
| 27 | {ua: "json-api", h: "application/json", e: false}, |
| 28 | {ua: "no-accept", h: "", e: true}, |
| 29 | } { |
| 30 | t.Run(fmt.Sprintf("case=%d/ua=%s", k, tc.ua), func(t *testing.T) { |
| 31 | r := &http.Request{Header: map[string][]string{"Accept": {tc.h}}} |
| 32 | t.Logf("isBrowser: %s", httputil.NegotiateContentType(r, offers, defaultOffer)) |
| 33 | |
| 34 | t.Logf("isJSON: %s", httputil.NegotiateContentType(r, |
| 35 | []string{"application/json"}, |
| 36 | "text/html", |
| 37 | )) |
| 38 | |
| 39 | assert.Equal(t, tc.e, IsBrowserRequest(r)) |
| 40 | assert.Equal(t, !tc.e, IsJSONRequest(r)) |
| 41 | }) |
| 42 | } |
| 43 | } |
nothing calls this directly
no test coverage detected