(t *testing.T)
| 1760 | } |
| 1761 | |
| 1762 | func Test_processResponse_template(t *testing.T) { |
| 1763 | ios, _, stdout, stderr := iostreams.Test() |
| 1764 | |
| 1765 | resp := http.Response{ |
| 1766 | StatusCode: 200, |
| 1767 | Header: map[string][]string{ |
| 1768 | "Content-Type": {"application/json"}, |
| 1769 | }, |
| 1770 | Body: io.NopCloser(strings.NewReader(`[ |
| 1771 | { |
| 1772 | "title": "First title", |
| 1773 | "labels": [{"name":"bug"}, {"name":"help wanted"}] |
| 1774 | }, |
| 1775 | { |
| 1776 | "title": "Second but not last" |
| 1777 | }, |
| 1778 | { |
| 1779 | "title": "Alas, tis' the end", |
| 1780 | "labels": [{}, {"name":"feature"}] |
| 1781 | } |
| 1782 | ]`)), |
| 1783 | } |
| 1784 | |
| 1785 | opts := ApiOptions{ |
| 1786 | IO: ios, |
| 1787 | Template: `{{range .}}{{.title}} ({{.labels | pluck "name" | join ", " }}){{"\n"}}{{end}}`, |
| 1788 | } |
| 1789 | |
| 1790 | tmpl := template.New(ios.Out, ios.TerminalWidth(), ios.ColorEnabled()) |
| 1791 | err := tmpl.Parse(opts.Template) |
| 1792 | require.NoError(t, err) |
| 1793 | _, err = processResponse(&resp, &opts, ios.Out, io.Discard, tmpl, true, true) |
| 1794 | require.NoError(t, err) |
| 1795 | err = tmpl.Flush() |
| 1796 | require.NoError(t, err) |
| 1797 | |
| 1798 | assert.Equal(t, heredoc.Doc(` |
| 1799 | First title (bug, help wanted) |
| 1800 | Second but not last () |
| 1801 | Alas, tis' the end (, feature) |
| 1802 | `), stdout.String()) |
| 1803 | assert.Equal(t, "", stderr.String()) |
| 1804 | } |
| 1805 | |
| 1806 | func Test_parseErrorResponse(t *testing.T) { |
| 1807 | type args struct { |
nothing calls this directly
no test coverage detected