(t *testing.T)
| 2815 | } |
| 2816 | |
| 2817 | func TestContextShouldBindBodyWithPlain(t *testing.T) { |
| 2818 | for _, tt := range []struct { |
| 2819 | name string |
| 2820 | bindingBody binding.BindingBody |
| 2821 | body string |
| 2822 | }{ |
| 2823 | { |
| 2824 | name: " JSON & JSON-BODY ", |
| 2825 | bindingBody: binding.JSON, |
| 2826 | body: `{"foo":"FOO"}`, |
| 2827 | }, |
| 2828 | { |
| 2829 | name: " JSON & XML-BODY ", |
| 2830 | bindingBody: binding.XML, |
| 2831 | body: `<?xml version="1.0" encoding="UTF-8"?> |
| 2832 | <root> |
| 2833 | <foo>FOO</foo> |
| 2834 | </root>`, |
| 2835 | }, |
| 2836 | { |
| 2837 | name: " JSON & YAML-BODY ", |
| 2838 | bindingBody: binding.YAML, |
| 2839 | body: `foo: FOO`, |
| 2840 | }, |
| 2841 | { |
| 2842 | name: " JSON & TOM-BODY ", |
| 2843 | bindingBody: binding.TOML, |
| 2844 | body: `foo=FOO`, |
| 2845 | }, |
| 2846 | { |
| 2847 | name: " JSON & Plain-BODY ", |
| 2848 | bindingBody: binding.Plain, |
| 2849 | body: `foo=FOO`, |
| 2850 | }, |
| 2851 | } { |
| 2852 | t.Logf("testing: %s", tt.name) |
| 2853 | |
| 2854 | w := httptest.NewRecorder() |
| 2855 | c, _ := CreateTestContext(w) |
| 2856 | |
| 2857 | c.Request, _ = http.NewRequest(http.MethodPost, "/", bytes.NewBufferString(tt.body)) |
| 2858 | |
| 2859 | type typeJSON struct { |
| 2860 | Foo string `json:"foo" binding:"required"` |
| 2861 | } |
| 2862 | objJSON := typeJSON{} |
| 2863 | |
| 2864 | if tt.bindingBody == binding.Plain { |
| 2865 | body := "" |
| 2866 | require.NoError(t, c.ShouldBindBodyWithPlain(&body)) |
| 2867 | assert.Equal(t, "foo=FOO", body) |
| 2868 | } |
| 2869 | |
| 2870 | if tt.bindingBody == binding.JSON { |
| 2871 | require.NoError(t, c.ShouldBindBodyWithJSON(&objJSON)) |
| 2872 | assert.Equal(t, typeJSON{"FOO"}, objJSON) |
| 2873 | } |
| 2874 |
nothing calls this directly
no test coverage detected