(t *testing.T)
| 1728 | } |
| 1729 | |
| 1730 | func Test_processResponse_template(t *testing.T) { |
| 1731 | ios, _, stdout, stderr := iostreams.Test() |
| 1732 | |
| 1733 | resp := http.Response{ |
| 1734 | StatusCode: 200, |
| 1735 | Header: map[string][]string{ |
| 1736 | "Content-Type": {"application/json"}, |
| 1737 | }, |
| 1738 | Body: io.NopCloser(strings.NewReader(`[ |
| 1739 | { |
| 1740 | "title": "First title", |
| 1741 | "labels": [{"name":"bug"}, {"name":"help wanted"}] |
| 1742 | }, |
| 1743 | { |
| 1744 | "title": "Second but not last" |
| 1745 | }, |
| 1746 | { |
| 1747 | "title": "Alas, tis' the end", |
| 1748 | "labels": [{}, {"name":"feature"}] |
| 1749 | } |
| 1750 | ]`)), |
| 1751 | } |
| 1752 | |
| 1753 | opts := ApiOptions{ |
| 1754 | IO: ios, |
| 1755 | Template: `{{range .}}{{.title}} ({{.labels | pluck "name" | join ", " }}){{"\n"}}{{end}}`, |
| 1756 | } |
| 1757 | |
| 1758 | tmpl := template.New(ios.Out, ios.TerminalWidth(), ios.ColorEnabled()) |
| 1759 | err := tmpl.Parse(opts.Template) |
| 1760 | require.NoError(t, err) |
| 1761 | _, err = processResponse(&resp, &opts, ios.Out, io.Discard, tmpl, true, true) |
| 1762 | require.NoError(t, err) |
| 1763 | err = tmpl.Flush() |
| 1764 | require.NoError(t, err) |
| 1765 | |
| 1766 | assert.Equal(t, heredoc.Doc(` |
| 1767 | First title (bug, help wanted) |
| 1768 | Second but not last () |
| 1769 | Alas, tis' the end (, feature) |
| 1770 | `), stdout.String()) |
| 1771 | assert.Equal(t, "", stderr.String()) |
| 1772 | } |
| 1773 | |
| 1774 | func Test_parseErrorResponse(t *testing.T) { |
| 1775 | type args struct { |
nothing calls this directly
no test coverage detected