( opChain *chain, method string, callback string, options ...ContentOpts, )
| 971 | ) |
| 972 | |
| 973 | func (r *Response) getJSONP( |
| 974 | opChain *chain, method string, callback string, options ...ContentOpts, |
| 975 | ) interface{} { |
| 976 | if !r.checkContentOptions(opChain, options, "application/javascript") { |
| 977 | return nil |
| 978 | } |
| 979 | |
| 980 | content, ok := r.getContent(opChain, method) |
| 981 | if !ok { |
| 982 | return nil |
| 983 | } |
| 984 | |
| 985 | m := jsonp.FindSubmatch(content) |
| 986 | |
| 987 | if len(m) != 3 || string(m[1]) != callback { |
| 988 | opChain.fail(AssertionFailure{ |
| 989 | Type: AssertValid, |
| 990 | Actual: &AssertionValue{ |
| 991 | string(content), |
| 992 | }, |
| 993 | Errors: []error{ |
| 994 | fmt.Errorf(`expected: JSONP body in form of "%s(<valid json>)"`, |
| 995 | callback), |
| 996 | }, |
| 997 | }) |
| 998 | return nil |
| 999 | } |
| 1000 | |
| 1001 | var value interface{} |
| 1002 | |
| 1003 | if err := json.Unmarshal(m[2], &value); err != nil { |
| 1004 | opChain.fail(AssertionFailure{ |
| 1005 | Type: AssertValid, |
| 1006 | Actual: &AssertionValue{ |
| 1007 | string(content), |
| 1008 | }, |
| 1009 | Errors: []error{ |
| 1010 | errors.New("failed to decode json"), |
| 1011 | err, |
| 1012 | }, |
| 1013 | }) |
| 1014 | return nil |
| 1015 | } |
| 1016 | |
| 1017 | return value |
| 1018 | } |
| 1019 | |
| 1020 | func (r *Response) checkContentOptions( |
| 1021 | opChain *chain, options []ContentOpts, expectedType string, expectedCharset ...string, |
no test coverage detected