(t *testing.T)
| 1829 | } |
| 1830 | |
| 1831 | func Test_processResponse_template(t *testing.T) { |
| 1832 | ios, _, stdout, stderr := iostreams.Test() |
| 1833 | |
| 1834 | resp := http.Response{ |
| 1835 | StatusCode: 200, |
| 1836 | Header: map[string][]string{ |
| 1837 | "Content-Type": {"application/json"}, |
| 1838 | }, |
| 1839 | Body: io.NopCloser(strings.NewReader(`[ |
| 1840 | { |
| 1841 | "title": "First title", |
| 1842 | "labels": [{"name":"bug"}, {"name":"help wanted"}] |
| 1843 | }, |
| 1844 | { |
| 1845 | "title": "Second but not last" |
| 1846 | }, |
| 1847 | { |
| 1848 | "title": "Alas, tis' the end", |
| 1849 | "labels": [{}, {"name":"feature"}] |
| 1850 | } |
| 1851 | ]`)), |
| 1852 | } |
| 1853 | |
| 1854 | opts := ApiOptions{ |
| 1855 | IO: ios, |
| 1856 | Template: `{{range .}}{{.title}} ({{.labels | pluck "name" | join ", " }}){{"\n"}}{{end}}`, |
| 1857 | } |
| 1858 | |
| 1859 | tmpl := template.New(ios.Out, ios.TerminalWidth(), ios.ColorEnabled()) |
| 1860 | err := tmpl.Parse(opts.Template) |
| 1861 | require.NoError(t, err) |
| 1862 | _, err = processResponse(&resp, &opts, ios.Out, io.Discard, tmpl, true, true) |
| 1863 | require.NoError(t, err) |
| 1864 | err = tmpl.Flush() |
| 1865 | require.NoError(t, err) |
| 1866 | |
| 1867 | assert.Equal(t, heredoc.Doc(` |
| 1868 | First title (bug, help wanted) |
| 1869 | Second but not last () |
| 1870 | Alas, tis' the end (, feature) |
| 1871 | `), stdout.String()) |
| 1872 | assert.Equal(t, "", stderr.String()) |
| 1873 | } |
| 1874 | |
| 1875 | func Test_parseErrorResponse(t *testing.T) { |
| 1876 | type args struct { |
nothing calls this directly
no test coverage detected