(t *testing.T)
| 1648 | } |
| 1649 | |
| 1650 | func Test_processResponse_template(t *testing.T) { |
| 1651 | ios, _, stdout, stderr := iostreams.Test() |
| 1652 | |
| 1653 | resp := http.Response{ |
| 1654 | StatusCode: 200, |
| 1655 | Header: map[string][]string{ |
| 1656 | "Content-Type": {"application/json"}, |
| 1657 | }, |
| 1658 | Body: io.NopCloser(strings.NewReader(`[ |
| 1659 | { |
| 1660 | "title": "First title", |
| 1661 | "labels": [{"name":"bug"}, {"name":"help wanted"}] |
| 1662 | }, |
| 1663 | { |
| 1664 | "title": "Second but not last" |
| 1665 | }, |
| 1666 | { |
| 1667 | "title": "Alas, tis' the end", |
| 1668 | "labels": [{}, {"name":"feature"}] |
| 1669 | } |
| 1670 | ]`)), |
| 1671 | } |
| 1672 | |
| 1673 | opts := ApiOptions{ |
| 1674 | IO: ios, |
| 1675 | Template: `{{range .}}{{.title}} ({{.labels | pluck "name" | join ", " }}){{"\n"}}{{end}}`, |
| 1676 | } |
| 1677 | |
| 1678 | tmpl := template.New(ios.Out, ios.TerminalWidth(), ios.ColorEnabled()) |
| 1679 | err := tmpl.Parse(opts.Template) |
| 1680 | require.NoError(t, err) |
| 1681 | _, err = processResponse(&resp, &opts, ios.Out, io.Discard, tmpl, true, true) |
| 1682 | require.NoError(t, err) |
| 1683 | err = tmpl.Flush() |
| 1684 | require.NoError(t, err) |
| 1685 | |
| 1686 | assert.Equal(t, heredoc.Doc(` |
| 1687 | First title (bug, help wanted) |
| 1688 | Second but not last () |
| 1689 | Alas, tis' the end (, feature) |
| 1690 | `), stdout.String()) |
| 1691 | assert.Equal(t, "", stderr.String()) |
| 1692 | } |
| 1693 | |
| 1694 | func Test_parseErrorResponse(t *testing.T) { |
| 1695 | type args struct { |
nothing calls this directly
no test coverage detected