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